OpenASIP 2.2
Loading...
Searching...
No Matches
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
44namespace TTAProgram {
45
46class Procedure;
47class Move;
48class Immediate;
49class 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 */
58public:
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
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;
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
123private:
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.
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
UInt32 InstructionAddress
Definition BaseType.hh:175
static NullInstructionTemplate & instance()
CodeSnippet * parent_
Parent procedure.
const TTAMachine::InstructionTemplate * insTemplate_
Instruction template that is used for this instruction.
Instruction * copy() const
void setSize(short size)
bool hasConditionalRegisterAccesses_
Set to true in case this instruction has moves that access registers and are conditional.
MoveList moves_
Moves contained in this instruction.
void removeImmediate(Immediate &imm)
std::string toString() const
void addImmediate(std::shared_ptr< Immediate > imm)
short size_
Size of instruction in MAU's.
std::shared_ptr< Move > movePtr(int i) const
Move & move(int i) const
Address address() const
InstructionAddress positionInProcedure_
Cache the instruction's index in the its procedure for faster address().
std::shared_ptr< Immediate > immediatePtr(int i) const
ImmList immediates_
Immediates contained in this instruction.
bool hasControlFlowMove() const
bool hasConditionalRegisterAccesses() const
std::vector< std::shared_ptr< Move > > MoveList
List for moves.
Immediate & immediate(int i) const
void setFinalAddress(InstructionAddress addr)
Instruction(const Instruction &)
Copying not allowed.
void addMove(std::shared_ptr< Move > move)
bool hasFinalAddress() const
InstructionAddress finalAddress_
In case the final instruction address is known (due to program not modified anymore),...
void removeMove(Move &move)
void setInstructionTemplate(const TTAMachine::InstructionTemplate &insTemp)
Instruction & operator=(const Instruction &)
Assignment not allowed.
CodeSnippet & parent() const
const TTAMachine::InstructionTemplate & instructionTemplate() const
void setParent(CodeSnippet &proc)
bool hasRegisterAccesses_
Set to true in case this instruction has moves that access registers.
bool hasRegisterAccesses() const
std::vector< std::shared_ptr< Immediate > > ImmList
List for immediates.