OpenASIP 2.2
Loading...
Searching...
No Matches
Program.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 Program.hh
26 *
27 * Declaration of Program class.
28 *
29 * @author Ari Metsähalme 2005 (ari.metsahalme-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#ifndef TTA_PROGRAM_HH
34#define TTA_PROGRAM_HH
35
36#include <vector>
37
38#include "Address.hh"
39#include "BaseType.hh"
40#include "Exception.hh"
41#include "TCEString.hh"
42
43namespace TTAMachine {
44 class Machine;
45}
46
48
49namespace TTAProgram {
50
51class Instruction;
52class Procedure;
53class DataMemory;
54class Move;
55class InstructionReferenceManager;
56class TerminalImmediate;
57class Terminal;
58class GlobalScope;
59
60/**
61 * Represents a TTA program.
62 */
63class Program {
64public:
65 /// Vector for instructions.
66 typedef std::vector<Instruction*> InstructionVector;
67
69 Program(const TTAMachine::AddressSpace& space, Address start);
70 Program(
71 const TTAMachine::AddressSpace& space,
72 Address start,
73 Address entry);
74 virtual ~Program();
75
77 const GlobalScope& globalScopeConst() const;
78
82
83 Address startAddress() const;
84 void setStartAddress(Address start);
85 Address entryAddress() const;
86 void setEntryAddress(Address address);
87
88 void addProcedure(Procedure* proc);
89 void addInstruction(Instruction* ins);
90
91 void moveProcedure(Procedure& proc, int howMuch);
92
94 Procedure& lastProcedure() const;
95 Procedure& nextProcedure(const Procedure& proc) const;
96 int procedureCount() const;
97 Procedure& procedure(int index) const;
98 Procedure& operator[](size_t index);
99 Procedure& procedure(const std::string& name) const;
100 bool hasProcedure(const std::string& name) const;
101
104 int instructionCount() const;
105
106 const Move& moveAt(int number) const;
107 int moveCount() const;
108
109 const Procedure& procedureAtIndex(int index) const;
110
113
115
116 Program& operator=(const Program& old);
117 Program* copy() const;
118
119 void removeProcedure(Procedure& proc);
120
121 int dataMemoryCount() const;
122 DataMemory& dataMemory(int index) const;
123 DataMemory& dataMemory(const std::string& aSpaceName) const;
124 void addDataMemory(DataMemory* dataMem);
125
127
129
130 void link(const TTAProgram::Program& other);
131
133 const std::string& tpefFileName, const TTAMachine::Machine& theMachine);
134
135 static Program* loadFromTPEF(
136 const std::string& tpefFileName, const TTAMachine::Machine& theMachine);
137
138 static Program* loadFromUnscheduledTPEF(const std::string& tpefFileName);
139
140 static void writeToTPEF(
141 const TTAProgram::Program& program, const std::string& tpefFileName);
142
143 void convertSymbolRefsToInsRefs(bool ignoreUnfoundSymbols=false);
145
146 TCEString toString() const;
147
148 void finalize();
149 bool isFinalized() const { return finalized_; }
150
152private:
153 /// List for procedures.
154 typedef std::vector<Procedure*> ProcList;
155 /// Iterator for the procedure list.
156 typedef ProcList::const_iterator ProcIter;
157 /// List for data memories.
158 typedef std::vector<DataMemory*> DataMemList;
159 /// List for moves
160 typedef std::vector<Move*> MoveList;
161
162 /// Copying not allowed.
164
165 void copyDataMemoriesFrom(const Program& srcProg);
166 void copyCodeLabelsFrom(const Program& srcProg);
167 void copyDataLabelsFrom(const Program& srcProg);
168 void copyFrom(const Program& source);
169 void cleanup();
170
172
173 /// Global scope of the program.
175
176 /// The procedures in the program.
178
179 /// The data memories in the program.
181
182 /// List of all the moves of the program.
184
185 /// The start address of the program.
187 /// The entry address of the program.
189
190 /// Keeps book of all instruction to instruction (jumps and calls)
191 /// references in the program.
193
194 /// The UniversalMachine instance used to refer to in case of the
195 /// unscheduled/unassigned parts of the program.
197
198 /// True in case the program is not (and must not be) updated anymore
199 /// and it has its final instruction addresses computed.
201
202 /// True in case the program is instruction indexed, that is, each
203 /// instruction is assumed to be in a single instruction memory location.
205};
206
207}
208
209#endif
UInt32 InstructionAddress
Definition BaseType.hh:175
find Finds info of the inner loops in the program
std::vector< Instruction * > InstructionVector
Vector for instructions.
Definition Program.hh:66
static Program * loadFromTPEF(const std::string &tpefFileName, const TTAMachine::Machine &theMachine)
Definition Program.cc:1112
GlobalScope & globalScope()
Definition Program.cc:180
Procedure & procedure(int index) const
Definition Program.cc:622
static void writeToTPEF(const TTAProgram::Program &program, const std::string &tpefFileName)
Definition Program.cc:1169
Instruction & nextInstruction(const Instruction &) const
Definition Program.cc:403
Instruction & firstInstruction() const
Definition Program.cc:353
ProcList::const_iterator ProcIter
Iterator for the procedure list.
Definition Program.hh:156
TerminalImmediate * convertSymbolRef(Terminal &tsr)
Definition Program.cc:1226
bool hasProcedure(const std::string &name) const
Definition Program.cc:673
ProcList procedures_
The procedures in the program.
Definition Program.hh:177
bool finalized_
True in case the program is not (and must not be) updated anymore and it has its final instruction ad...
Definition Program.hh:200
GlobalScope * globalScope_
Global scope of the program.
Definition Program.hh:174
Program(const Program &)
Copying not allowed.
void moveProcedure(Procedure &proc, int howMuch)
Definition Program.cc:588
void copyCodeLabelsFrom(const Program &srcProg)
Program * copy() const
Definition Program.cc:714
TCEString toString() const
Definition Program.cc:1327
InstructionReferenceManager * refManager_
Keeps book of all instruction to instruction (jumps and calls) references in the program.
Definition Program.hh:192
virtual ~Program()
Definition Program.cc:144
void fixInstructionReferences()
Definition Program.cc:775
const Move & moveAt(int number) const
Definition Program.cc:480
Address entryAddress() const
Definition Program.cc:330
Instruction & lastInstruction() const
Definition Program.cc:463
const Procedure & procedureAtIndex(int index) const
Definition Program.cc:508
void replaceUniversalAddressSpaces(const TTAMachine::AddressSpace &space)
Definition Program.cc:1012
Procedure & operator[](size_t index)
Definition Program.cc:642
std::vector< Move * > MoveList
List for moves.
Definition Program.hh:160
Address startAddress() const
Definition Program.cc:286
MoveList moves_
List of all the moves of the program.
Definition Program.hh:183
void copyDataMemoriesFrom(const Program &srcProg)
Definition Program.cc:845
Program & operator=(const Program &old)
Definition Program.cc:701
void copyDataLabelsFrom(const Program &srcProg)
const GlobalScope & globalScopeConst() const
Definition Program.cc:192
TTAMachine::Machine & targetProcessor() const
Definition Program.cc:202
void setEntryAddress(Address address)
Definition Program.cc:342
int moveCount() const
Definition Program.cc:494
bool isInstructionPerAddress() const
Definition Program.hh:151
DataMemory & dataMemory(int index) const
Definition Program.cc:967
void removeProcedure(Procedure &proc)
Definition Program.cc:901
Procedure & nextProcedure(const Procedure &proc) const
Definition Program.cc:250
void addDataMemory(DataMemory *dataMem)
Definition Program.cc:954
void addProcedure(Procedure *proc)
Definition Program.cc:524
Instruction & instructionAt(InstructionAddress address) const
Definition Program.cc:374
bool instructionPerAddress_
True in case the program is instruction indexed, that is, each instruction is assumed to be in a sing...
Definition Program.hh:204
int procedureCount() const
Definition Program.cc:610
void addInstruction(Instruction *ins)
Definition Program.cc:554
InstructionReferenceManager & instructionReferenceManager() const
Definition Program.cc:688
UniversalMachine & universalMachine() const
Definition Program.cc:104
bool isFinalized() const
Definition Program.hh:149
void setStartAddress(Address start)
Definition Program.cc:304
Address entry_
The entry address of the program.
Definition Program.hh:188
std::vector< DataMemory * > DataMemList
List for data memories.
Definition Program.hh:158
int instructionCount() const
Definition Program.cc:1209
static Program * loadFromUnscheduledTPEF(const std::string &tpefFileName, const TTAMachine::Machine &theMachine)
Definition Program.cc:1083
void link(const TTAProgram::Program &other)
Definition Program.cc:1309
std::vector< Procedure * > ProcList
List for procedures.
Definition Program.hh:154
DataMemList dataMems_
The data memories in the program.
Definition Program.hh:180
void convertSymbolRefsToInsRefs(bool ignoreUnfoundSymbols=false)
Definition Program.cc:1264
InstructionVector instructionVector() const
Definition Program.cc:1196
UniversalMachine * umach_
The UniversalMachine instance used to refer to in case of the unscheduled/unassigned parts of the pro...
Definition Program.hh:196
void setUniversalMachine(UniversalMachine *umach)
Definition Program.hh:81
Procedure & lastProcedure() const
Definition Program.cc:230
void copyFrom(const Program &source)
Definition Program.cc:732
Procedure & firstProcedure() const
Definition Program.cc:213
int dataMemoryCount() const
Definition Program.cc:942
Address start_
The start address of the program.
Definition Program.hh:186