OpenASIP 2.2
Loading...
Searching...
No Matches
TerminalRegister.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2011 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file TerminalRegister.cc
26 *
27 * Implementation of TerminalRegister class.
28 *
29 * @author Ari Metsähalme 2005 (ari.metsahalme-no.spam-tut.fi)
30 * @author Pekka Jääskeläinen 2011
31 * @note rating: red
32 */
33
34#include "TerminalRegister.hh"
35#include "ImmediateUnit.hh"
38
39using namespace TTAMachine;
40
41namespace TTAProgram {
42
43/**
44 * The constructor.
45 *
46 * @param unit The register file.
47 * @param port The port of the register file.
48 * @param index Register identifier.
49 */
51 : unit_(*port.parentUnit()), port_(port), index_(index), isImmUnit_(false) {
52 if (dynamic_cast<const ImmediateUnit*>(&unit_) != NULL) {
53 isImmUnit_ = true;
54 } else if (dynamic_cast<const RegisterFile*>(&unit_) == NULL) {
55 throw InvalidData(
56 __FILE__, __LINE__, "TerminalRegister::TerminalRegister()",
57 "Unit of the terminal has invalid type");
58 }
59}
60
61/**
62 * The destructor.
63 */
66
67/**
68 * Returns the register file of the general-purpose register.
69 *
70 * Applicable only if the unit of the terminal is an instance of
71 * RegisterFile.
72 *
73 * @return The register file of the general-purpose register.
74 * @exception WrongSubclass if the unit of the terminal is not an instance
75 * of RegisterFile.
76 */
77const RegisterFile&
79 if (isImmUnit_ == false) {
80 return static_cast<const RegisterFile&>(unit_);
81 } else {
82 throw WrongSubclass(
83 __FILE__, __LINE__, "TerminalRegister::registerFile()",
84 "Unit of the terminal is not of type RegisterFile");
85 }
86}
87
88/**
89 * Returns the immediate unit of the long immediate register.
90 *
91 * Applicable only if the unit of the terminal is an instance of
92 * ImmediateUnit.
93 *
94 * @return The immediate unit of the long immediate register.
95 * @exception WrongSubclass if the unit of the terminal is not an instance
96 * of ImmediateUnit.
97 */
98const ImmediateUnit&
100 if (isImmUnit_ == true) {
101 return static_cast<const ImmediateUnit&>(unit_);
102 } else {
103 throw WrongSubclass(
104 __FILE__, __LINE__, "TerminalRegister::immediateUnit()",
105 "Unit of the terminal is not of type ImmediateUnit");
106 }
107}
108
109/**
110 * Return the port.
111 *
112 * @return The port of the unit of the terminal.
113 * @exception WrongSubclass never.
114 */
115const Port&
117 return port_;
118}
119
120/**
121 * Change the register of the register file to the given index.
122 *
123 * @param index The new register index.
124 * @exception OutOfRange if index is not smaller than the size of the
125 * register file or immediate unit it belongs to.
126 */
127void
129 const BaseRegisterFile& reg =
130 dynamic_cast<const BaseRegisterFile&>(unit_);
131
132 if (index < reg.numberOfRegisters()) {
133 index_ = index;
134 } else {
135 throw OutOfRange(
136 __FILE__, __LINE__, "TerminalRegister::setIndex()",
137 "Index out of range.");
138 }
139}
140
141/**
142 * Creates an exact copy of the terminal and returns it.
143 *
144 * @return A copy of the terminal.
145 */
148 return new TerminalRegister(port_, index_);
149}
150
151/**
152 * Checks if terminals are equal.
153 *
154 * @param other Terminal to compare.
155 * @return true if terminals are equal.
156 */
157bool
159 try {
160 if (isImmediateRegister()) {
161 return (other.isImmediateRegister() &&
162 index() == other.index() &&
163 immediateUnit().name() == other.immediateUnit().name());
164 }
165 if (isGPR()) {
166 return (other.isGPR() &&
167 index() == other.index() &&
168 registerFile().name() == other.registerFile().name());
169 }
170 return false;
171 } catch (const WrongSubclass&) {
172 // the method should throw this when called for wrong type,
173 // thus the objects cannot be equal
174 return false;
175 }
176}
177
180 if (isImmUnit_ == false) {
181 DisassemblyRegister disasm(registerFile().name(), index());
182 return disasm.toString();
183 } else {
184 TCEString res = unit_.name();
185 res << "." << index_;
186 return res;
187 }
188}
189
190/**
191 * Tells whether the terminal is a reg in UniversalMachine
192 *
193 * @return True if the terminal is a register in universalmachine,
194 * ie. not in any real machine. This practically means the
195 * register is unallocated and meant to be bypassed.
196 */
197bool
199 return (dynamic_cast<const UnboundedRegisterFile*>(&unit_) != NULL);
200}
201
202}
find Finds info of the inner loops in the false
std::string toString() const
virtual int numberOfRegisters() const
virtual TCEString name() const
const TTAMachine::Unit & unit_
Unit of the terminal.
virtual void setIndex(int index)
const TTAMachine::Port & port_
Port of the unit.
short index_
Index of the register of the register file or immediate unit.
virtual bool isImmediateRegister() const
virtual int index() const
virtual const TTAMachine::ImmediateUnit & immediateUnit() const
virtual const TTAMachine::Port & port() const
virtual bool isUniversalMachineRegister() const
TerminalRegister(const TTAMachine::Port &port, int index)
virtual TCEString toString() const
bool isImmUnit_
Unit type flag: true if immediate unit, false if register file.
virtual bool isGPR() const
virtual bool equals(const Terminal &other) const
virtual ~TerminalRegister()
Copying is allowed.
virtual Terminal * copy() const
virtual const TTAMachine::RegisterFile & registerFile() const
virtual int index() const
Definition Terminal.cc:274
virtual bool isGPR() const
Definition Terminal.cc:107
virtual bool isImmediateRegister() const
Definition Terminal.cc:97
virtual const TTAMachine::ImmediateUnit & immediateUnit() const
Definition Terminal.cc:240
virtual const TTAMachine::RegisterFile & registerFile() const
Definition Terminal.cc:225