OpenASIP  2.0
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 
43 namespace 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 
55 namespace 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  */
77 public:
78  /**
79  * Type of resource id request.
80  */
81  enum RequestType {
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 
131 private:
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 
194  ResourceID registerFileIndexReference(
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
MachineResourceManager::ResourceKey
Definition: MachineResourceManager.hh:136
MachineResourceManager::stringToChunk
TPEF::Chunk * stringToChunk(const std::string aStr)
Definition: MachineResourceManager.cc:249
MachineResourceManager::requestTypeString
std::string requestTypeString(RequestType type) const
Definition: MachineResourceManager.cc:557
TPEF::ResourceSection
Definition: ResourceSection.hh:47
MachineResourceManager::opOrPortIDs_
std::map< std::string, UValue > opOrPortIDs_
Bookkeeping of already added ports, operations and special registers.
Definition: MachineResourceManager.hh:239
MachineResourceManager::nullSection_
TPEF::NullSection * nullSection_
The null section of TPEF.
Definition: MachineResourceManager.hh:219
MachineResourceManager::ResourceID
Definition: MachineResourceManager.hh:91
MachineResourceManager::codeASpace_
TPEF::ASpaceElement * codeASpace_
The instruction address space element of TPEF.
Definition: MachineResourceManager.hh:214
Exception.hh
MachineResourceManager::lastRegisterFileID_
UValue lastRegisterFileID_
For generating register file resource ids.
Definition: MachineResourceManager.hh:232
MachineResourceManager::RequestType
RequestType
Definition: MachineResourceManager.hh:81
MachineResourceManager::functionUnitID
UValue functionUnitID(TTAMachine::FunctionUnit *unit)
Definition: MachineResourceManager.cc:446
MachineResourceManager::resourceSection
TPEF::ResourceSection * resourceSection()
Definition: MachineResourceManager.cc:373
TPEF::Binary
Definition: Binary.hh:49
MachineResourceManager::findBusWidth
UValue findBusWidth(UValue slotNumber)
Definition: MachineResourceManager.cc:129
TPEF::MoveElement::FieldType
FieldType
Definition: MoveElement.hh:52
TPEF::ResourceElement
Definition: ResourceElement.hh:47
MachineResourceManager::registerFileID
UValue registerFileID(TTAMachine::BaseRegisterFile *rf)
Definition: MachineResourceManager.cc:480
MachineResourceManager::adf_
const TTAMachine::Machine & adf_
Machine where manager tries to find used resources.
Definition: MachineResourceManager.hh:202
ParserStructs.hh
MachineResourceManager::stringSection
TPEF::StringSection * stringSection()
Definition: MachineResourceManager.cc:166
MachineResourceManager::ResourceID::index
UValue index
TPEF Resource operand id or register file index.
Definition: MachineResourceManager.hh:102
MachineResourceManager::RQST_READ
@ RQST_READ
Register of port for reading.
Definition: MachineResourceManager.hh:82
AssemblyParserDiagnostic
Definition: AssemblyParserDiagnostic.hh:68
MachineResourceManager::nullSection
TPEF::Section * nullSection()
Definition: MachineResourceManager.cc:140
TPEF::Section
Definition: Section.hh:64
TPEF::StringSection
Definition: StringSection.hh:48
MachineResourceManager::MachineResourceManager
MachineResourceManager(TPEF::Binary &tpef, const TTAMachine::Machine &adf, AssemblyParserDiagnostic *parent_)
Definition: MachineResourceManager.cc:63
MachineResourceManager::parent_
AssemblyParserDiagnostic * parent_
Assembler root class for adding warnings.
Definition: MachineResourceManager.hh:242
MachineResourceManager::ResourceKey::operator<
bool operator<(const ResourceKey &comp) const
Definition: MachineResourceManager.hh:144
MachineResourceManager::ResourceKey::keyString
std::string keyString
Key string for resource.
Definition: MachineResourceManager.hh:138
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
MachineResourceManager::functionUnitIDs_
std::map< TTAMachine::FunctionUnit *, UValue > functionUnitIDs_
Bookkeeping of already added function units.
Definition: MachineResourceManager.hh:229
MachineResourceManager::indexResource
ResourceID indexResource(UValue currentLine, const RegisterTerm &term, UValue slotNumber, RequestType type, std::string &resourceKeyString)
Definition: MachineResourceManager.cc:670
TPEF::NullSection
Definition: NullSection.hh:46
TTAMachine::BaseRegisterFile
Definition: BaseRegisterFile.hh:48
MachineResourceManager::ResourceID::type
TPEF::MoveElement::FieldType type
Resource type.
Definition: MachineResourceManager.hh:98
UValue
unsigned long UValue
Definition: ParserStructs.hh:44
MachineResourceManager::ResourceID::width
UValue width
Width of accessed port or other resource.
Definition: MachineResourceManager.hh:104
TPEF::ASpaceElement
Definition: ASpaceElement.hh:48
MachineResourceManager
Definition: MachineResourceManager.hh:76
MachineResourceManager::rFPortOrFUIndexReference
ResourceID rFPortOrFUIndexReference(TTAMachine::FunctionUnit *fu, TTAMachine::BaseRegisterFile *rf, UValue currentLine, const RegisterTerm &term, UValue slotNumber, RequestType type, std::string &resourceKeyString)
Definition: MachineResourceManager.cc:755
MachineResourceManager::RQST_INVGUARD
@ RQST_INVGUARD
Inverted register or port guard.
Definition: MachineResourceManager.hh:85
TTAMachine::Port
Definition: Port.hh:54
MachineResourceManager::registerFileIDs_
std::map< TTAMachine::BaseRegisterFile *, UValue > registerFileIDs_
Bookkeeping of already added register files.
Definition: MachineResourceManager.hh:234
MachineResourceManager::registerFileIndexReference
ResourceID registerFileIndexReference(TTAMachine::BaseRegisterFile *rf, const RegisterTerm &term, UValue slotNumber, RequestType type, std::string &resourceKeyString)
Definition: MachineResourceManager.cc:983
MachineResourceManager::tpef_
TPEF::Binary & tpef_
Binary where all used resources are added.
Definition: MachineResourceManager.hh:199
MachineResourceManager::ResourceKey::type
RequestType type
Was resource read or written or was it guard.
Definition: MachineResourceManager.hh:142
MachineResourceManager::strings_
TPEF::StringSection * strings_
The string section of TPEF.
Definition: MachineResourceManager.hh:208
MachineResourceManager::lastOpOrSpecRegisterID_
UValue lastOpOrSpecRegisterID_
For generating shared ids for ports, operations or special registers.
Definition: MachineResourceManager.hh:237
MachineResourceManager::ResourceID::ResourceID
ResourceID()
Definition: MachineResourceManager.hh:92
MachineResourceManager::opOrPortID
UValue opOrPortID(std::string opOrPortString, const TTAMachine::Port *port)
Definition: MachineResourceManager.cc:518
MachineResourceManager::initResourceSection
void initResourceSection()
Definition: MachineResourceManager.cc:382
MachineResourceManager::addressSpaces_
std::map< std::string, TPEF::ASpaceElement * > addressSpaces_
Bookkeeping for already requested address spaces.
Definition: MachineResourceManager.hh:216
MachineResourceManager::findDataAddressSpace
TPEF::ASpaceElement * findDataAddressSpace(std::string name)
Definition: MachineResourceManager.cc:83
MachineResourceManager::aSpaceSection_
TPEF::ASpaceSection * aSpaceSection_
The address space section of TPEF.
Definition: MachineResourceManager.hh:205
MachineResourceManager::ResourceID::unit
UValue unit
TPEF Resource unit id.
Definition: MachineResourceManager.hh:100
MachineResourceManager::RQST_GUARD
@ RQST_GUARD
Register or port guard.
Definition: MachineResourceManager.hh:84
MachineResourceManager::resourceID
ResourceID & resourceID(UValue currentLine, const RegisterTerm &term, UValue slotNumber, RequestType type)
Definition: MachineResourceManager.cc:285
MachineResourceManager::resourceMap_
std::map< ResourceKey, ResourceID > resourceMap_
Bookkeeping for already requested resources.
Definition: MachineResourceManager.hh:224
MachineResourceManager::resourceSection_
TPEF::ResourceSection * resourceSection_
The resource section of TPEF.
Definition: MachineResourceManager.hh:222
MachineResourceManager::functionUnitPortResource
ResourceID functionUnitPortResource(const RegisterTerm &term)
Definition: MachineResourceManager.cc:577
MachineResourceManager::undefinedAddressSpace
TPEF::ASpaceElement * undefinedAddressSpace()
Definition: MachineResourceManager.cc:179
RegisterTerm
Definition: ParserStructs.hh:136
TTAMachine
Definition: Assembler.hh:48
MachineResourceManager::codeAddressSpace
TPEF::ASpaceElement * codeAddressSpace()
Definition: MachineResourceManager.cc:213
TPEF::ASpaceSection
Definition: ASpaceSection.hh:44
MoveElement.hh
MachineResourceManager::lastFunctionUnitID_
UValue lastFunctionUnitID_
For generating function unit resource ids.
Definition: MachineResourceManager.hh:227
MachineResourceManager::undefASpace_
TPEF::ASpaceElement * undefASpace_
The undefined address space element of TPEF.
Definition: MachineResourceManager.hh:211
MachineResourceManager::ResourceKey::slotNumber
UValue slotNumber
Bus that was used.
Definition: MachineResourceManager.hh:140
TPEF::Chunk
Definition: Chunk.hh:45
MachineResourceManager::addResourceElement
void addResourceElement(TPEF::ResourceElement *resource)
Definition: MachineResourceManager.cc:418
MachineResourceManager::RQST_WRITE
@ RQST_WRITE
Register or port for writing.
Definition: MachineResourceManager.hh:83
TPEF
Definition: Assembler.hh:43
TTAMachine::Machine
Definition: Machine.hh:73