OpenASIP 2.2
Loading...
Searching...
No Matches
ProgramWriter.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 ProgramWriter.hh
26 *
27 * Declaration of ProgramWriter class.
28 *
29 * @author Mikael Lepistö 2005 (tmlepist-no.spam-cs.tut.fi)
30 * @note rating: yellow
31 */
32
33#ifndef TTA_PROGRAM_WRITER_HH
34#define TTA_PROGRAM_WRITER_HH
35
36#include <map>
37
38#include "BaseType.hh"
39#include "MoveElement.hh"
40#include "Binary.hh"
41#include "Address.hh"
42
43namespace TPEF {
44 class Binary;
45 class CodeSection;
46 class RelocSection;
47 class SymbolSection;
48 class ResourceSection;
49 class ResourceElement;
50 class Section;
51 class ASpaceElement;
52 class SectionElement;
53}
54
55namespace TTAMachine {
56 class Machine;
57 class Bus;
58 class RegisterFile;
59 class ImmediateUnit;
60 class FunctionUnit;
61 class Port;
62 class HWOperation;
63 class MachinePart;
64 class AddressSpace;
65}
66
67namespace TTAProgram {
68
69class Program;
70class Terminal;
71
72/**
73 * Returns requested Machine parts as a TPEF resources.
74 *
75 * Also adds new resources to resource section if resource is not
76 * already there.
77 *
78 * NOTE: If resource section is modified externally, cache should be cleared.
79 *
80 */
82public:
85 TPEF::ResourceSection& resources);
86
87 void clearCache();
88
92 const TTAMachine::HWOperation& oper,
93 int operandIndex);
97 const TTAMachine::ImmediateUnit& immUnit);
98
99private:
100 void initCache();
101
102 /// The model of the target processor architecture.
104 /// The TPEF input section that contains all machine resource entries.
106
107 // Key type for caching ResourceElements for machine components.
108 // For example (HWOperation, index) pair
109 typedef std::pair<const TTAMachine::MachinePart*, int> CacheKey;
110 /// Mapping from parts of the target processor model to TPEF machine
111 /// resource entries.
112 typedef std::map<CacheKey, TPEF::ResourceElement*> ResourceCache;
113
114 /// Aggregate of all mappings between machine resource entries and
115 /// target processor parts (machine parts).
117
118 /// Last TPEF bus id that was generated.
119 HalfWord lastBusId_;
120 /// Last TPEF unit port id that was generated.
122 /// Last TPEF function unit id that was generated.
124 /// Last TPEF register file id that was generated.
126 /// Last TPEF immediate unit id that was generated.
128};
129
130/**
131 * Writes new TPEF out of POM and original TPEF.
132 *
133 * Writer creates creates whole new code section, code relocation section,
134 * resource section and symbol section for code symbols. Data sections,
135 * uninitialized data sections and data to data relocations are also copied
136 * from original TPEF.
137 *
138 * Client of POM has to write data to code relocations and all sections
139 * that client wants to preserve from original TPEF.
140 */
142public:
143 ProgramWriter(const Program& prog);
144
145 TPEF::Binary* createBinary() const;
146
147 static TPEF::Binary* createBinary(const Program& prog);
148
149private:
150 /**
151 * TPEF resource id:s for getting corresponding resource elements.
152 */
153 struct ResourceID {
154 TPEF::MoveElement::FieldType type; ///< RF, UNIT or IMM.
155 HalfWord unit; ///< Unit id.
156 HalfWord index; ///< Operand or register file index.
157 };
158
159 /**
160 * Info about relocation of immediate or data chunk.
161 */
162 struct RelocInfo {
164 TPEF::Section* aSrcSect, TPEF::SectionElement* aSrcElem,
165 const Address& aDstAddress, int bitWidth) :
166 srcSect(aSrcSect), srcElem(aSrcElem),
167 destination(aDstAddress), bits(bitWidth) {
168 }
169
170 /// Location section.
172 /// Location element.
174 /// Destination address.
176 /// Relocation width.
177 int bits;
178 };
179
181 TPEF::CodeSection* code,
182 TPEFResourceUpdater& updater) const;
183
184 void createDataSections(TPEF::Binary* bin, bool littleEndian) const;
185
186 void createRelocSections(TPEF::Binary* bin) const;
187
188 TPEF::Section& findSection(TPEF::Binary& bin, Address address) const;
189
191 const Terminal& term,
192 TPEFResourceUpdater& updater) const;
193
195 TPEF::ResourceSection& resources) const;
196
198 const TTAMachine::AddressSpace& addressSpace,
199 TPEF::Binary& bin) const;
200
201
202 /// Program that is written to TPEF.
204 /// Created TPEF binary.
205 // const TPEF::Binary& tpef_;
206
207 /// Map that contains created address spaces
208 mutable std::map<const TTAMachine::AddressSpace*,
210
211 mutable std::vector<RelocInfo> relocInfos_;
212
213 /// Default widt that is used as address width of relocations of immediate
214 /// elements. This should be fixed by checking width from bus or template.
215 static const HalfWord IMMEDIATE_ADDRESS_WIDTH;
216
217 /// Maximum width for short immediates
218 static const int MAX_SIMM_WIDTH;
219};
220
221}
222
223#endif
std::vector< RelocInfo > relocInfos_
void createDataSections(TPEF::Binary *bin, bool littleEndian) const
void createRelocSections(TPEF::Binary *bin) const
void createCodeSection(TPEF::CodeSection *code, TPEFResourceUpdater &updater) const
ResourceID terminalResource(const Terminal &term, TPEFResourceUpdater &updater) const
static const HalfWord IMMEDIATE_ADDRESS_WIDTH
Default widt that is used as address width of relocations of immediate elements. This should be fixed...
const Program & prog_
Program that is written to TPEF.
TPEF::Binary * createBinary() const
TPEF::Binary::FileType resolveFileType(TPEF::ResourceSection &resources) const
TPEF::Section & findSection(TPEF::Binary &bin, Address address) const
std::map< const TTAMachine::AddressSpace *, TPEF::ASpaceElement * > aSpaceMap_
Created TPEF binary.
TPEF::ASpaceElement & createASpaceElement(const TTAMachine::AddressSpace &addressSpace, TPEF::Binary &bin) const
static const int MAX_SIMM_WIDTH
Maximum width for short immediates.
HalfWord lastUnitPortId_
Last TPEF unit port id that was generated.
std::map< CacheKey, TPEF::ResourceElement * > ResourceCache
Mapping from parts of the target processor model to TPEF machine resource entries.
TPEF::ResourceElement & registerFile(const TTAMachine::RegisterFile &rf)
TPEF::ResourceElement & bus(const TTAMachine::Bus &bus)
HalfWord lastBusId_
Last TPEF bus id that was generated.
HalfWord lastFunctionUnitId_
Last TPEF function unit id that was generated.
TPEF::ResourceElement & functionUnit(const TTAMachine::FunctionUnit &fu)
TPEF::ResourceElement & immediateUnit(const TTAMachine::ImmediateUnit &immUnit)
HalfWord lastRegisterFileId_
Last TPEF register file id that was generated.
TPEF::ResourceElement & operand(const TTAMachine::HWOperation &oper, int operandIndex)
TPEF::ResourceSection & resources_
The TPEF input section that contains all machine resource entries.
std::pair< const TTAMachine::MachinePart *, int > CacheKey
HalfWord lastImmediateUnitId_
Last TPEF immediate unit id that was generated.
TTAMachine::Machine & mach_
The model of the target processor architecture.
TPEF::ResourceElement & functionUnitPort(const TTAMachine::Port &port)
ResourceCache cache_
Aggregate of all mappings between machine resource entries and target processor parts (machine parts)...
RelocInfo(TPEF::Section *aSrcSect, TPEF::SectionElement *aSrcElem, const Address &aDstAddress, int bitWidth)
TPEF::SectionElement * srcElem
Location element.
TPEF::Section * srcSect
Location section.
Address destination
Destination address.
TPEF::MoveElement::FieldType type
RF, UNIT or IMM.
HalfWord index
Operand or register file index.