OpenASIP  2.0
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 
43 namespace TTAMachine {
44  class Machine;
45 }
46 
47 class UniversalMachine;
48 
49 namespace TTAProgram {
50 
51 class Instruction;
52 class Procedure;
53 class DataMemory;
54 class Move;
55 class InstructionReferenceManager;
56 class TerminalImmediate;
57 class Terminal;
58 class GlobalScope;
59 
60 /**
61  * Represents a TTA program.
62  */
63 class Program {
64 public:
65  /// Vector for instructions.
66  typedef std::vector<Instruction*> InstructionVector;
67 
68  Program(const TTAMachine::AddressSpace& space);
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 
81  void setUniversalMachine(UniversalMachine* umach) { umach_ = umach; }
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 
93  Procedure& firstProcedure() const;
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 
102  Instruction& firstInstruction() const;
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 
111  Instruction& nextInstruction(const Instruction&) const;
112  Instruction& lastInstruction() const;
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 
152 private:
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.
163  Program(const Program&);
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
TTAProgram
Definition: Estimator.hh:65
TTAProgram::Program
Definition: Program.hh:63
TTAProgram::Program::addProcedure
void addProcedure(Procedure *proc)
Definition: Program.cc:524
TTAProgram::Program::firstInstruction
Instruction & firstInstruction() const
Definition: Program.cc:353
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
TTAProgram::Program::operator[]
Procedure & operator[](size_t index)
Definition: Program.cc:642
TTAProgram::Program::addInstruction
void addInstruction(Instruction *ins)
Definition: Program.cc:554
BaseType.hh
TTAProgram::Address
Definition: Address.hh:51
TTAProgram::Program::procedureCount
int procedureCount() const
Definition: Program.cc:610
TTAProgram::Program::firstProcedure
Procedure & firstProcedure() const
Definition: Program.cc:213
TTAProgram::Program::entryAddress
Address entryAddress() const
Definition: Program.cc:330
TTAMachine::AddressSpace
Definition: AddressSpace.hh:51
Exception.hh
TTAProgram::Program::startAddress
Address startAddress() const
Definition: Program.cc:286
TTAProgram::Program::isInstructionPerAddress
bool isInstructionPerAddress() const
Definition: Program.hh:151
TTAProgram::Program::nextInstruction
Instruction & nextInstruction(const Instruction &) const
Definition: Program.cc:403
TTAProgram::Instruction
Definition: Instruction.hh:57
TTAProgram::Program::DataMemList
std::vector< DataMemory * > DataMemList
List for data memories.
Definition: Program.hh:158
TTAProgram::Program::finalized_
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
TTAProgram::Program::instructionPerAddress_
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
TTAProgram::Program::moveAt
const Move & moveAt(int number) const
Definition: Program.cc:480
TTAProgram::Program::dataMems_
DataMemList dataMems_
The data memories in the program.
Definition: Program.hh:180
TTAProgram::Program::umach_
UniversalMachine * umach_
The UniversalMachine instance used to refer to in case of the unscheduled/unassigned parts of the pro...
Definition: Program.hh:196
TTAProgram::Program::InstructionVector
std::vector< Instruction * > InstructionVector
Vector for instructions.
Definition: Program.hh:66
TTAProgram::Program::refManager_
InstructionReferenceManager * refManager_
Keeps book of all instruction to instruction (jumps and calls) references in the program.
Definition: Program.hh:192
TTAProgram::Program::procedureAtIndex
const Procedure & procedureAtIndex(int index) const
Definition: Program.cc:508
TCEString.hh
TTAProgram::Program::hasProcedure
bool hasProcedure(const std::string &name) const
Definition: Program.cc:673
TTAProgram::Program::globalScopeConst
const GlobalScope & globalScopeConst() const
Definition: Program.cc:192
TTAProgram::Program::ProcList
std::vector< Procedure * > ProcList
List for procedures.
Definition: Program.hh:154
TTAProgram::Program::instructionAt
Instruction & instructionAt(InstructionAddress address) const
Definition: Program.cc:374
TTAProgram::Program::copyDataLabelsFrom
void copyDataLabelsFrom(const Program &srcProg)
TTAProgram::Program::MoveList
std::vector< Move * > MoveList
List for moves.
Definition: Program.hh:160
TTAProgram::Program::addDataMemory
void addDataMemory(DataMemory *dataMem)
Definition: Program.cc:954
TTAProgram::Program::nextProcedure
Procedure & nextProcedure(const Procedure &proc) const
Definition: Program.cc:250
TTAProgram::Program::setEntryAddress
void setEntryAddress(Address address)
Definition: Program.cc:342
TTAProgram::Program::moveProcedure
void moveProcedure(Procedure &proc, int howMuch)
Definition: Program.cc:588
UniversalMachine
Definition: UniversalMachine.hh:56
TTAProgram::Program::isFinalized
bool isFinalized() const
Definition: Program.hh:149
TTAProgram::Program::link
void link(const TTAProgram::Program &other)
Definition: Program.cc:1309
TTAProgram::Program::dataMemory
DataMemory & dataMemory(int index) const
Definition: Program.cc:967
TTAProgram::Program::cleanup
void cleanup()
Definition: Program.cc:161
TTAProgram::GlobalScope
Definition: GlobalScope.hh:47
TTAProgram::Move
Definition: Move.hh:55
TTAProgram::Program::copyDataMemoriesFrom
void copyDataMemoriesFrom(const Program &srcProg)
Definition: Program.cc:845
TTAProgram::Program::Program
Program(const TTAMachine::AddressSpace &space)
Definition: Program.cc:91
TTAProgram::Program::universalMachine
UniversalMachine & universalMachine() const
Definition: Program.cc:104
TTAProgram::Program::operator=
Program & operator=(const Program &old)
Definition: Program.cc:701
TTAProgram::Program::dataMemoryCount
int dataMemoryCount() const
Definition: Program.cc:942
TTAProgram::Program::toString
TCEString toString() const
Definition: Program.cc:1327
TTAProgram::Program::moves_
MoveList moves_
List of all the moves of the program.
Definition: Program.hh:183
TTAProgram::Program::copy
Program * copy() const
Definition: Program.cc:714
TTAProgram::TerminalImmediate
Definition: TerminalImmediate.hh:44
TTAProgram::Program::instructionCount
int instructionCount() const
Definition: Program.cc:1209
TTAProgram::Program::setStartAddress
void setStartAddress(Address start)
Definition: Program.cc:304
TTAProgram::InstructionReferenceManager
Definition: InstructionReferenceManager.hh:82
TTAProgram::Program::instructionReferenceManager
InstructionReferenceManager & instructionReferenceManager() const
Definition: Program.cc:688
TTAProgram::Program::procedures_
ProcList procedures_
The procedures in the program.
Definition: Program.hh:177
Address.hh
TTAProgram::Program::replaceUniversalAddressSpaces
void replaceUniversalAddressSpaces(const TTAMachine::AddressSpace &space)
Definition: Program.cc:1012
TTAProgram::Program::moveCount
int moveCount() const
Definition: Program.cc:494
TCEString
Definition: TCEString.hh:53
TTAProgram::Program::writeToTPEF
static void writeToTPEF(const TTAProgram::Program &program, const std::string &tpefFileName)
Definition: Program.cc:1169
TTAProgram::Program::entry_
Address entry_
The entry address of the program.
Definition: Program.hh:188
TTAProgram::Program::targetProcessor
TTAMachine::Machine & targetProcessor() const
Definition: Program.cc:202
TTAProgram::Program::loadFromTPEF
static Program * loadFromTPEF(const std::string &tpefFileName, const TTAMachine::Machine &theMachine)
Definition: Program.cc:1112
TTAProgram::Program::convertSymbolRef
TerminalImmediate * convertSymbolRef(Terminal &tsr)
Definition: Program.cc:1226
TTAProgram::Terminal
Definition: Terminal.hh:60
TTAProgram::Program::~Program
virtual ~Program()
Definition: Program.cc:144
TTAProgram::Program::globalScope_
GlobalScope * globalScope_
Global scope of the program.
Definition: Program.hh:174
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
TTAProgram::Program::lastInstruction
Instruction & lastInstruction() const
Definition: Program.cc:463
TTAProgram::Program::lastProcedure
Procedure & lastProcedure() const
Definition: Program.cc:230
TTAProgram::Program::globalScope
GlobalScope & globalScope()
Definition: Program.cc:180
TTAProgram::DataMemory
Definition: DataMemory.hh:56
TTAMachine
Definition: Assembler.hh:48
TTAProgram::Program::fixInstructionReferences
void fixInstructionReferences()
Definition: Program.cc:775
TTAProgram::Program::removeProcedure
void removeProcedure(Procedure &proc)
Definition: Program.cc:901
TTAProgram::Program::ProcIter
ProcList::const_iterator ProcIter
Iterator for the procedure list.
Definition: Program.hh:156
TTAProgram::Program::copyFrom
void copyFrom(const Program &source)
Definition: Program.cc:732
TTAProgram::Program::start_
Address start_
The start address of the program.
Definition: Program.hh:186
TTAProgram::Program::instructionVector
InstructionVector instructionVector() const
Definition: Program.cc:1196
TTAProgram::Program::procedure
Procedure & procedure(int index) const
Definition: Program.cc:622
TTAProgram::Procedure
Definition: Procedure.hh:55
TTAProgram::Program::setUniversalMachine
void setUniversalMachine(UniversalMachine *umach)
Definition: Program.hh:81
TTAProgram::Program::loadFromUnscheduledTPEF
static Program * loadFromUnscheduledTPEF(const std::string &tpefFileName, const TTAMachine::Machine &theMachine)
Definition: Program.cc:1083
TTAProgram::Program::copyCodeLabelsFrom
void copyCodeLabelsFrom(const Program &srcProg)
TTAProgram::Program::convertSymbolRefsToInsRefs
void convertSymbolRefsToInsRefs(bool ignoreUnfoundSymbols=false)
Definition: Program.cc:1264
TTAMachine::Machine
Definition: Machine.hh:73
TTAProgram::Program::finalize
void finalize()
Definition: Program.cc:1343