OpenASIP 2.2
Loading...
Searching...
No Matches
MachineResourceManager.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 MachineResourceManager.hh
26 *
27 * Declaration of MachineResourceManager class.
28 *
29 * @author Mikael Lepistö 2005 (tmlepist-no.spam-cs.tut.fi)
30 * @note rating: yellow
31 */
32
33#ifndef TCEASM_RESOURCE_MANAGER_HH
34#define TCEASM_RESOURCE_MANAGER_HH
35
36#include <map>
37#include <string>
38
39#include "ParserStructs.hh"
40#include "MoveElement.hh"
41#include "Exception.hh"
42
43namespace TPEF {
44 class Binary;
45 class ResourceElement;
46 class ASpaceElement;
47 class ASpaceSection;
48 class StringSection;
49 class NullSection;
50 class ResourceSection;
51 class Section;
52 class Chunk;
53}
54
55namespace TTAMachine {
56 class Machine;
57 class FunctionUnit;
58 class RegisterFile;
59 class BaseRegisterFile;
60 class Port;
61}
62
64
65/**
66 * Provides all TPEF and machine resources needed by CodeSectionCreator
67 * and DataSectionCreator.
68 *
69 * Search resources from Machine and returns corresponding TPEF resources.
70 * Class also provides easy way to get common TPEF resource like strings,
71 * null section and required null elements. After all needed resources are
72 * returned the Binary that was given for MachineResourceManager will contain
73 * valid TPEF with NullSection, ASpaceSection, StringSection
74 * and ResourceSection.
75 */
77public:
78 /**
79 * Type of resource id request.
80 */
82 RQST_READ, ///< Register of port for reading.
83 RQST_WRITE, ///< Register or port for writing.
84 RQST_GUARD, ///< Register or port guard.
85 RQST_INVGUARD ///< Inverted register or port guard.
86 };
87
88 /**
89 * Result type when getting resource.
90 */
91 struct ResourceID {
93 type(TPEF::MoveElement::MF_NULL),
94 unit(0), index(0), width(0) {
95 }
96
97 /// Resource type.
99 /// TPEF Resource unit id.
101 /// TPEF Resource operand id or register file index.
103 /// Width of accessed port or other resource.
105 };
106
108 TPEF::Binary &tpef, const TTAMachine::Machine &adf,
110
112
114
116
117 TPEF::ASpaceElement *findDataAddressSpace(std::string name);
118
119 UValue findBusWidth(UValue slotNumber);
120
122
124
125 TPEF::Chunk* stringToChunk(const std::string aStr);
126
128 UValue currentLine, const RegisterTerm &term, UValue slotNumber,
129 RequestType type);
130
131private:
132 /**
133 * Cache element to see if same kind of resource reading has been
134 * resolved earlier during the compilation
135 */
136 struct ResourceKey {
137 /// Key string for resource.
138 std::string keyString;
139 /// Bus that was used.
141 /// Was resource read or written or was it guard.
143
144 bool operator<(const ResourceKey &comp) const {
145
146 if (keyString < comp.keyString) {
147 return true;
148 }
149
150 if (keyString > comp.keyString) {
151 return false;
152 }
153
154 if (slotNumber < comp.slotNumber) {
155 return true;
156 }
157
158 if (slotNumber > comp.slotNumber) {
159 return false;
160 }
161
162 if (type < comp.type) {
163 return true;
164 }
165
166 return false;
167 }
168 };
169
170 void initResourceSection();
171
173
175
177
179 std::string opOrPortString, const TTAMachine::Port *port);
180
181 std::string requestTypeString(RequestType type) const;
182
183 ResourceID functionUnitPortResource(const RegisterTerm &term);
184
185 ResourceID indexResource(
186 UValue currentLine, const RegisterTerm &term, UValue slotNumber,
187 RequestType type, std::string &resourceKeyString);
188
189 ResourceID rFPortOrFUIndexReference(
191 UValue currentLine, const RegisterTerm &term, UValue slotNumber,
192 RequestType type, std::string &resourceKeyString);
193
196 UValue slotNumber, RequestType type, std::string &resourceKeyString);
197
198 /// Binary where all used resources are added.
200
201 /// Machine where manager tries to find used resources.
203
204 /// The address space section of TPEF.
206
207 /// The string section of TPEF.
209
210 /// The undefined address space element of TPEF.
212
213 /// The instruction address space element of TPEF.
215 /// Bookkeeping for already requested address spaces.
216 std::map<std::string, TPEF::ASpaceElement*> addressSpaces_;
217
218 /// The null section of TPEF.
220
221 /// The resource section of TPEF.
223 /// Bookkeeping for already requested resources.
224 std::map<ResourceKey, ResourceID> resourceMap_;
225
226 /// For generating function unit resource ids.
228 /// Bookkeeping of already added function units.
229 std::map<TTAMachine::FunctionUnit*, UValue> functionUnitIDs_;
230
231 /// For generating register file resource ids.
233 /// Bookkeeping of already added register files.
234 std::map<TTAMachine::BaseRegisterFile*, UValue> registerFileIDs_;
235
236 /// For generating shared ids for ports, operations or special registers.
238 /// Bookkeeping of already added ports, operations and special registers.
239 std::map<std::string, UValue> opOrPortIDs_;
240
241 /// Assembler root class for adding warnings.
243};
244
245#endif
unsigned long UValue
TPEF::StringSection * strings_
The string section of TPEF.
std::map< std::string, UValue > opOrPortIDs_
Bookkeeping of already added ports, operations and special registers.
ResourceID & resourceID(UValue currentLine, const RegisterTerm &term, UValue slotNumber, RequestType type)
AssemblyParserDiagnostic * parent_
Assembler root class for adding warnings.
void addResourceElement(TPEF::ResourceElement *resource)
const TTAMachine::Machine & adf_
Machine where manager tries to find used resources.
UValue lastRegisterFileID_
For generating register file resource ids.
UValue functionUnitID(TTAMachine::FunctionUnit *unit)
std::map< TTAMachine::BaseRegisterFile *, UValue > registerFileIDs_
Bookkeeping of already added register files.
std::string requestTypeString(RequestType type) const
ResourceID rFPortOrFUIndexReference(TTAMachine::FunctionUnit *fu, TTAMachine::BaseRegisterFile *rf, UValue currentLine, const RegisterTerm &term, UValue slotNumber, RequestType type, std::string &resourceKeyString)
ResourceID functionUnitPortResource(const RegisterTerm &term)
TPEF::ResourceSection * resourceSection_
The resource section of TPEF.
UValue lastOpOrSpecRegisterID_
For generating shared ids for ports, operations or special registers.
ResourceID registerFileIndexReference(TTAMachine::BaseRegisterFile *rf, const RegisterTerm &term, UValue slotNumber, RequestType type, std::string &resourceKeyString)
std::map< std::string, TPEF::ASpaceElement * > addressSpaces_
Bookkeeping for already requested address spaces.
UValue findBusWidth(UValue slotNumber)
@ RQST_INVGUARD
Inverted register or port guard.
@ RQST_READ
Register of port for reading.
@ RQST_WRITE
Register or port for writing.
@ RQST_GUARD
Register or port guard.
UValue opOrPortID(std::string opOrPortString, const TTAMachine::Port *port)
TPEF::Binary & tpef_
Binary where all used resources are added.
TPEF::ASpaceSection * aSpaceSection_
The address space section of TPEF.
TPEF::StringSection * stringSection()
TPEF::ASpaceElement * findDataAddressSpace(std::string name)
ResourceID indexResource(UValue currentLine, const RegisterTerm &term, UValue slotNumber, RequestType type, std::string &resourceKeyString)
TPEF::ASpaceElement * codeASpace_
The instruction address space element of TPEF.
TPEF::ASpaceElement * undefinedAddressSpace()
TPEF::Chunk * stringToChunk(const std::string aStr)
std::map< TTAMachine::FunctionUnit *, UValue > functionUnitIDs_
Bookkeeping of already added function units.
TPEF::ASpaceElement * codeAddressSpace()
UValue lastFunctionUnitID_
For generating function unit resource ids.
UValue registerFileID(TTAMachine::BaseRegisterFile *rf)
TPEF::ASpaceElement * undefASpace_
The undefined address space element of TPEF.
TPEF::NullSection * nullSection_
The null section of TPEF.
std::map< ResourceKey, ResourceID > resourceMap_
Bookkeeping for already requested resources.
TPEF::ResourceSection * resourceSection()
UValue width
Width of accessed port or other resource.
TPEF::MoveElement::FieldType type
Resource type.
UValue index
TPEF Resource operand id or register file index.
std::string keyString
Key string for resource.
bool operator<(const ResourceKey &comp) const
RequestType type
Was resource read or written or was it guard.