OpenASIP  2.0
Instruction.hh
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 Instruction.hh
26  *
27  * Declaration of Instruction class.
28  *
29  * @author Ari Metsähalme 2005 (ari.metsahalme-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef TTA_INSTRUCTION_HH
34 #define TTA_INSTRUCTION_HH
35 
36 #include <vector>
37 #include <memory>
38 
39 #include "Address.hh"
40 #include "Exception.hh"
43 
44 namespace TTAProgram {
45 
46 class Procedure;
47 class Move;
48 class Immediate;
49 class CodeSnippet;
50 
51 /**
52  * Represents a TTA instruction.
53  *
54  * @note: The annotations added with the AnnotatedInstructionElement
55  * are not saved to a TPEF file when the program is written!
56  */
58 public:
59 
60 #ifdef TCE_PYTHON_BINDINGS
61 
62  // Py++ generated code has problems with the default values
63 
65 
66  explicit Instruction(
68 
69 #else
72 
73 
74  explicit Instruction(
77 #endif
78  ~Instruction();
79 
80  CodeSnippet& parent() const;
81  void setParent(CodeSnippet& proc);
82  bool isInProcedure() const;
83 
84  void addMove(std::shared_ptr<Move> move);
85  int moveCount() const;
86  Move& move(int i) const;
87  std::shared_ptr<Move> movePtr(int i) const;
88  void removeMove(Move& move);
89 
90  bool isNOP() const { return moveCount() == 0 && immediateCount() == 0; }
91 
92  void addImmediate(std::shared_ptr<Immediate> imm);
93  int immediateCount() const;
94  Immediate& immediate(int i) const;
95  std::shared_ptr<Immediate> immediatePtr(int i) const;
96  void removeImmediate(Immediate& imm);
97 
98  Address address() const;
99 
100  bool hasFinalAddress() const
101  { return finalAddress_ != (InstructionAddress)-1; }
102 
103  short size() const;
104  void setSize(short size) { size_ = size; }
105 
106  bool hasRegisterAccesses() const;
107  bool hasConditionalRegisterAccesses() const;
108  bool hasJump() const;
109  bool hasCall() const;
110  bool hasReturn() const;
111  bool hasControlFlowMove() const;
112 
113  Instruction* copy() const;
114 
116  const TTAMachine::InstructionTemplate& insTemp);
118 
119  std::string toString() const;
120 
122 
123 private:
124  /// List for moves.
125  typedef std::vector<std::shared_ptr<Move> > MoveList;
126  /// List for immediates.
127  typedef std::vector<std::shared_ptr<Immediate> > ImmList;
128 
129  /// Copying not allowed.
130  Instruction(const Instruction&);
131  /// Assignment not allowed.
133 
134  /// Moves contained in this instruction.
136  /// Immediates contained in this instruction.
138  /// Parent procedure.
140 
141  /// Instruction template that is used for this instruction.
143 
144  /// Cache the instruction's index in the its procedure for faster address().
146  /// In case the final instruction address is known (due to program not
147  /// modified anymore), the final instruction address is stored here.
148  /// -1 in case not known.
150 
151  /// Size of instruction in MAU's.
152  mutable short size_;
153  /// Set to true in case this instruction has moves that access registers.
155  /// Set to true in case this instruction has moves that access registers
156  /// and are conditional.
158 };
159 
160 }
161 
162 #endif
TTAProgram::AnnotatedInstructionElement
Definition: AnnotatedInstructionElement.hh:53
TTAProgram
Definition: Estimator.hh:65
TTAProgram::Instruction::removeMove
void removeMove(Move &move)
Definition: Instruction.cc:536
TTAProgram::Instruction::addMove
void addMove(std::shared_ptr< Move > move)
Definition: Instruction.cc:147
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
TTAProgram::Instruction::finalAddress_
InstructionAddress finalAddress_
In case the final instruction address is known (due to program not modified anymore),...
Definition: Instruction.hh:149
TTAProgram::Instruction::isNOP
bool isNOP() const
Definition: Instruction.hh:90
TTAProgram::Instruction::move
Move & move(int i) const
Definition: Instruction.cc:193
TTAProgram::Address
Definition: Address.hh:51
Exception.hh
TTAProgram::Instruction::MoveList
std::vector< std::shared_ptr< Move > > MoveList
List for moves.
Definition: Instruction.hh:125
TTAProgram::Instruction::hasConditionalRegisterAccesses
bool hasConditionalRegisterAccesses() const
Definition: Instruction.cc:412
TTAProgram::Instruction
Definition: Instruction.hh:57
TTAProgram::Instruction::removeImmediate
void removeImmediate(Immediate &imm)
Definition: Instruction.cc:560
TTAProgram::Instruction::toString
std::string toString() const
Definition: Instruction.cc:576
TTAProgram::Instruction::immediates_
ImmList immediates_
Immediates contained in this instruction.
Definition: Instruction.hh:137
TTAProgram::Instruction::hasCall
bool hasCall() const
Definition: Instruction.cc:438
TTAMachine::InstructionTemplate
Definition: InstructionTemplate.hh:49
TTAProgram::Instruction::hasRegisterAccesses_
bool hasRegisterAccesses_
Set to true in case this instruction has moves that access registers.
Definition: Instruction.hh:154
TTAProgram::Instruction::insTemplate_
const TTAMachine::InstructionTemplate * insTemplate_
Instruction template that is used for this instruction.
Definition: Instruction.hh:142
TTAProgram::Immediate
Definition: Immediate.hh:54
TTAProgram::Instruction::ImmList
std::vector< std::shared_ptr< Immediate > > ImmList
List for immediates.
Definition: Instruction.hh:127
TTAProgram::Instruction::copy
Instruction * copy() const
Definition: Instruction.cc:379
TTAProgram::Instruction::~Instruction
~Instruction()
Definition: Instruction.cc:93
TTAProgram::Instruction::parent
CodeSnippet & parent() const
Definition: Instruction.cc:109
TTAProgram::Instruction::size_
short size_
Size of instruction in MAU's.
Definition: Instruction.hh:152
NullInstructionTemplate.hh
TTAProgram::Instruction::setSize
void setSize(short size)
Definition: Instruction.hh:104
TTAProgram::Move
Definition: Move.hh:55
TTAProgram::Instruction::immediatePtr
std::shared_ptr< Immediate > immediatePtr(int i) const
Definition: Instruction.cc:309
TTAProgram::Instruction::immediate
Immediate & immediate(int i) const
Definition: Instruction.cc:285
TTAProgram::Instruction::hasRegisterAccesses
bool hasRegisterAccesses() const
Definition: Instruction.cc:399
TTAProgram::CodeSnippet
Definition: CodeSnippet.hh:59
TTAProgram::Instruction::hasJump
bool hasJump() const
Definition: Instruction.cc:422
TTAProgram::Instruction::instructionTemplate
const TTAMachine::InstructionTemplate & instructionTemplate() const
Definition: Instruction.cc:523
TTAProgram::Instruction::hasReturn
bool hasReturn() const
Definition: Instruction.cc:452
TTAProgram::Instruction::setParent
void setParent(CodeSnippet &proc)
Definition: Instruction.cc:124
TTAProgram::Instruction::isInProcedure
bool isInProcedure() const
Definition: Instruction.cc:135
TTAProgram::Instruction::positionInProcedure_
InstructionAddress positionInProcedure_
Cache the instruction's index in the its procedure for faster address().
Definition: Instruction.hh:145
TTAMachine::NullInstructionTemplate::instance
static NullInstructionTemplate & instance()
Definition: NullInstructionTemplate.cc:62
TTAProgram::Instruction::moves_
MoveList moves_
Moves contained in this instruction.
Definition: Instruction.hh:135
AnnotatedInstructionElement.hh
Address.hh
TTAProgram::Instruction::hasConditionalRegisterAccesses_
bool hasConditionalRegisterAccesses_
Set to true in case this instruction has moves that access registers and are conditional.
Definition: Instruction.hh:157
TTAProgram::Instruction::size
short size() const
Definition: Instruction.cc:365
TTAProgram::Instruction::immediateCount
int immediateCount() const
Definition: Instruction.cc:267
TTAProgram::Instruction::setInstructionTemplate
void setInstructionTemplate(const TTAMachine::InstructionTemplate &insTemp)
Definition: Instruction.cc:488
TTAProgram::Instruction::hasControlFlowMove
bool hasControlFlowMove() const
Definition: Instruction.cc:471
TTAProgram::Instruction::movePtr
std::shared_ptr< Move > movePtr(int i) const
Definition: Instruction.cc:216
TTAProgram::Instruction::setFinalAddress
void setFinalAddress(InstructionAddress addr)
Definition: Instruction.hh:121
TTAProgram::Instruction::parent_
CodeSnippet * parent_
Parent procedure.
Definition: Instruction.hh:139
TTAProgram::Instruction::hasFinalAddress
bool hasFinalAddress() const
Definition: Instruction.hh:100
TTAProgram::Instruction::moveCount
int moveCount() const
Definition: Instruction.cc:176
TTAProgram::Instruction::address
Address address() const
Definition: Instruction.cc:327
TTAProgram::Instruction::addImmediate
void addImmediate(std::shared_ptr< Immediate > imm)
Definition: Instruction.cc:234
TTAProgram::Instruction::operator=
Instruction & operator=(const Instruction &)
Assignment not allowed.
TTAProgram::Instruction::Instruction
Instruction(const TTAMachine::InstructionTemplate &instructionTemplate=TTAMachine::NullInstructionTemplate::instance())
Definition: Instruction.cc:63