OpenASIP  2.0
Terminal.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 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 Terminal.cc
26  *
27  * Implementation of Terminal class.
28  *
29  * @author Ari Metsähalme 2005 (ari.metsahalme-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include "Exception.hh"
34 #include "Terminal.hh"
35 #include "InstructionReference.hh"
36 
37 using namespace TTAMachine;
38 
39 namespace TTAProgram {
40 
41 /////////////////////////////////////////////////////////////////////////////
42 // Terminal
43 /////////////////////////////////////////////////////////////////////////////
44 
45 /**
46  * The constructor.
47  */
48 Terminal::Terminal() {
49 }
50 
51 /**
52  * The destructor.
53  */
54 Terminal::~Terminal() {
55 }
56 
57 /**
58  * Tells whether the terminal is an inline immediate value.
59  *
60  * @return True if the terminal is an inline immediate value.
61  */
62 bool
63 Terminal::isImmediate() const {
64  return false;
65 }
66 
67 /**
68  * Tells whether the terminal is an inline immediate value that refers
69  * to an address.
70  *
71  * @return True if the terminal is an inline immediate value that refers
72  * to an address.
73  */
74 bool
75 Terminal::isAddress() const {
76  return false;
77 }
78 
79 /**
80  * Tells whether the terminal is an inline immediate value that refers
81  * to an instruction address.
82  *
83  * @return True if the terminal is an inline immediate value that refers
84  * to an instruction address.
85  */
86 bool
87 Terminal::isInstructionAddress() const {
88  return false;
89 }
90 
91 /**
92  * Tells whether the terminal is a long immediate register.
93  *
94  * @return True if the terminal is a long immediate register.
95  */
96 bool
97 Terminal::isImmediateRegister() const {
98  return false;
99 }
100 
101 /**
102  * Tells whether the terminal is a general-purpose register.
103  *
104  * @return True if the terminal is a general-purpose register.
105  */
106 bool
107 Terminal::isGPR() const {
108  return false;
109 }
110 
111 /**
112  * Tells whether the terminal is a function unit port (possibly,
113  * including an operation code).
114  *
115  * @return True if the terminal is a function unit port.
116  */
117 bool
118 Terminal::isFUPort() const {
119  return false;
120 }
121 
122 /**
123  * Tells whether the terminal is a the return address port
124  * in gcu.
125  *
126  * @return True if the terminal is a the RA port.
127  */
128 bool
129 Terminal::isRA() const {
130  return false;
131 }
132 
133 /**
134  * Tells whether the terminal is reference to a basic block.
135  *
136  * @return True if the terminal is a ref to a basic block
137  */
138 bool
139 Terminal::isBasicBlockReference() const {
140  return false;
141 }
142 
143 bool
144 Terminal::isProgramOperationReference() const {
145  return false;
146 }
147 
148 /**
149  * Tells whether the terminal is reference to a code symbol
150  *
151  * @return True if the terminal is a ref to a code symbol
152  */
153 bool
154 Terminal::isCodeSymbolReference() const {
155  return false;
156 }
157 
158 /**
159  * Tells whether the terminal is a reg in UniversalMachine
160  *
161  * @return True if the terminal is a register in universalmachine,
162  * ie. not in any real machine. This practically means the
163  * register is unallocated and meant to be bypassed.
164  */
165 bool
166 Terminal::isUniversalMachineRegister() const {
167  return false;
168 }
169 
170 /**
171  * Returns the value of the inline immediate.
172  *
173  * @return The value of the inline immediate.
174  * @exception WrongSubclass if the terminal is not an instance of
175  * TerminalImmediate.
176  */
177 SimValue
178 Terminal::value() const {
179  throw WrongSubclass(__FILE__, __LINE__);
180 }
181 
182 /**
183  * Returns a reference to the instruction to which the immediate points.
184  *
185  * @return A reference to the instruction to which the immediate points.
186  */
188 Terminal::instructionReference() const {
189  throw WrongSubclass(__FILE__, __LINE__);
190 }
191 
192 /**
193  * Returns a reference to the instruction to which the immediate points.
194  *
195  * @return A reference to the instruction to which the immediate points.
196  */
198 Terminal::instructionReference() {
199  throw WrongSubclass(__FILE__, __LINE__);
200 }
201 
202 /**
203  * Returns the address held by this terminal.
204  *
205  * @return A memory address.
206  * @exception WrongSubclass if the terminal is not an instance of
207  * TerminalAddress.
208  */
209 Address
210 Terminal::address() const {
211  throw WrongSubclass(__FILE__, __LINE__);
212 }
213 
214 /**
215  * Returns the register file of the general-purpose register.
216  *
217  * Applicable only if the unit of the terminal is an instance of
218  * RegisterFile.
219  *
220  * @return The register file of the general-purpose register.
221  * @exception WrongSubclass if the unit of the terminal is not an instance
222  * of RegisterFile.
223  */
224 const RegisterFile&
225 Terminal::registerFile() const {
226  throw WrongSubclass(__FILE__, __LINE__);
227 }
228 
229 /**
230  * Returns the immediate unit of the long immediate register.
231  *
232  * Applicable only if the unit of the terminal is an instance of
233  * ImmediateUnit.
234  *
235  * @return The immediate unit of the long immediate register.
236  * @exception WrongSubclass if the unit of the terminal is not an instance
237  * of ImmediateUnit.
238  */
239 const ImmediateUnit&
240 Terminal::immediateUnit() const {
241  throw WrongSubclass(__FILE__, __LINE__);
242 }
243 
244 /**
245  * Returns the function unit of the port.
246  *
247  * @exception WrongSubclass if the terminal is not an instance of
248  * TerminalFUPort.
249  */
250 const FunctionUnit&
251 Terminal::functionUnit() const {
252  throw WrongSubclass(__FILE__, __LINE__);
253 }
254 
255 /**
256  * Returns a reference to the basic block to which the immediate points.
257  *
258  * @return A reference to the basic block to which the immediate points.
259  */
260 const BasicBlock&
261 Terminal::basicBlock() const {
262  throw WrongSubclass(__FILE__, __LINE__);
263 }
264 
265 /**
266  * Return the index of the register (either a long immediate or a
267  * general-purpose register).
268  *
269  * @return The index of the register.
270  * @exception WrongSubclass if the terminal is not an instance of
271  * TerminalRegister.
272  */
273 int
274 Terminal::index() const {
275  throw WrongSubclass(__FILE__, __LINE__);
276 }
277 
278 /**
279  * Tells whether terminal transports an opcode to a function unit port.
280  *
281  * @return True if the terminal transports an opcode to a function unit port.
282  * @exception WrongSubclass always.
283 */
284 bool
285 Terminal::isOpcodeSetting() const {
286  throw WrongSubclass(
287  __FILE__, __LINE__, __func__,
288  "Terminal must be TerminalFUPort for this method.");
289 }
290 
291 /**
292  * Tells whether terminal is a triggering FU port.
293  *
294  * @return True if the terminal is a triggering port.
295  * @exception WrongSubclass always.
296 */
297 bool
298 Terminal::isTriggering() const {
299  throw WrongSubclass(
300  __FILE__, __LINE__, __func__,
301  "Terminal must be TerminalFUPort for this method.");
302 }
303 
304 /**
305  * Return the operation code transported into the function unit port by this
306  * terminal.
307  *
308  * Throws an error condition if the terminal does not read from or write to
309  * a function unit port (that is, if the terminal if of a wrong type).
310  * Throws an error condition also if the terminal does not access an
311  * opcode-setting function unit port.
312  *
313  * @exception WrongSubclass If the terminal is of the wrong type.
314  * @exception InvalidData If the terminal is of the right type, but it does
315  * not carry an operation-code.
316  * @return The operation carried by this terminal.
317  */
318 Operation&
319 Terminal::operation() const {
320  throw WrongSubclass(
321  __FILE__, __LINE__, __func__,
322  "Terminal must be TerminalFUPort for this method.");
323 }
324 
325 /**
326  * Return the operation to which this terminal was originally bound.
327  *
328  * NOTE! : Method must not be used for checkin if terminal contains
329  * opcode. See. operation().
330  *
331  * Method is mainly used for preserving information to which operation
332  * port reference is bound, during TPEF -> POM -> TPEF write cycles.
333  *
334  * @return The operation code to which terminal was originally bound.
335  * Null operation if terminal does not contain operation code.
336  *
337  * @todo This should be probably merged with operation() as "hints" are
338  * not really useful, we should make sure the operation of the move is known.
339  */
340 Operation&
341 Terminal::hintOperation() const {
342  throw WrongSubclass(
343  __FILE__, __LINE__, __func__,
344  "Terminal must be TerminalFUPort for this method.");
345 }
346 
347 /**
348  * Return the index that identifies the operation input or output that
349  * is represented by this terminal.
350  *
351  * Throws an error condition if the terminal does not read from or write to
352  * a function unit port (that is, if the terminal if of a wrong type).
353  * Throws an error condition also if the terminal does not access an
354  * opcode-setting function unit port, nor it bears auxiliary "hint
355  * operation" information.
356  *
357  * @return The index that identifies the operation input or output that
358  * is represented by this terminal.
359  * @exception WrongSubclass If the terminal is of the wrong type.
360  * @exception InvalidData If the terminal is of the right type, but does
361  * not have any operation-related information.
362  */
363 int
364 Terminal::operationIndex() const {
365  throw WrongSubclass(
366  __FILE__, __LINE__, __func__,
367  "Terminal must be TerminalFUPort for this method.");
368 }
369 
370 /**
371  * Return the port accessed by this terminal.
372  *
373  * @return The port of the unit of the terminal.
374  * @exception WrongSubclass if the terminal is not an instance of
375  * TerminalFUPort or TerminalRegister.
376  */
377 const Port&
378 Terminal::port() const {
379  throw WrongSubclass(__FILE__, __LINE__);
380 }
381 
382 /**
383  * Change the register of the register file to the given index.
384  *
385  * @param index The new register index.
386  * @exception OutOfRange if index is not smaller than the size of the
387  * register file or immediate unit it belongs to.
388  * @exception WrongSubclass if the terminal is not an instance of
389  * TerminalRegister.
390  */
391 void
392 Terminal::setIndex(int) {
393  throw WrongSubclass(__FILE__, __LINE__);
394 }
395 
396 /**
397  * Set a new referred instruction.
398  *
399  * @param ref The new instruction reference.
400  * @exception WrongSubclass if the terminal is not an instance of
401  * TerminalInstructionAddress
402  */
403 void
404 Terminal::setInstructionReference(InstructionReference) {
405  throw WrongSubclass(__FILE__, __LINE__);
406 }
407 
408 /**
409  * Comparison operator for Terminals.
410  *
411  * Delegates the comparison to dynamically bound equals() method.
412  *
413  * @param other Comparison target.
414  * @return True in case the objects are equal.
415  */
416 bool
417 Terminal::operator==(const Terminal& other) const {
418  return equals(other);
419 }
420 
421 }
TTAProgram
Definition: Estimator.hh:65
Exception.hh
Terminal.hh
SimValue
Definition: SimValue.hh:96
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
WrongSubclass
Definition: Exception.hh:336
TTAMachine::Port
Definition: Port.hh:54
__func__
#define __func__
Definition: Application.hh:67
Operation
Definition: Operation.hh:59
TTAProgram::BasicBlock
Definition: BasicBlock.hh:85
InstructionReference.hh
TTAProgram::Terminal
Definition: Terminal.hh:60
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
TTAMachine
Definition: Assembler.hh:48
TTAProgram::InstructionReference
Definition: InstructionReference.hh:49
TTAMachine::ImmediateUnit
Definition: ImmediateUnit.hh:50