OpenASIP 2.2
Loading...
Searching...
No Matches
MachineState.cc
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 MachineState.cc
26 *
27 * Definition of MachineState class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
31 * @note rating: red
32 */
33
34#include "MachineState.hh"
35#include "GCUState.hh"
36#include "BusState.hh"
37#include "FUState.hh"
39#include "RegisterFileState.hh"
40#include "MapTools.hh"
41#include "OutputPortState.hh"
42#include "OperationExecutor.hh"
43#include "SequenceTools.hh"
44#include "SimulatorToolbox.hh"
45#include "Operation.hh"
46#include "InputPortState.hh"
47#include "OperationContext.hh"
48#include "OperationPool.hh"
51#include "MapTools.hh"
52#include "StringTools.hh"
53#include "Application.hh"
54#include "GuardState.hh"
55
56using std::string;
57
58/**
59 * Constructor.
60 */
62 GCUState_(NULL), fuStateCount_(0), finished_(false) {
63}
64
65/**
66 * Destructor.
67 */
71
72/**
73 * Reserved memory is freed, containers are emptied.
74 */
75void
96
97/**
98 * Returns the GCUState of the machine state.
99 *
100 * @return GCUState.
101 */
104 return *GCUState_;
105}
106
107/**
108 * Returns bus state with a given name.
109 *
110 * If bus state with a given name is not found, return NullBusState.
111 *
112 * @param name Name of the bus state.
113 * @return Bus state with a given name.
114 */
116MachineState::busState(const std::string& name) {
117 BusContainer::iterator iter = busses_.find(name);
118 if (iter == busses_.end()) {
119 return NullBusState::instance();
120 }
121 return *((*iter).second);
122}
123
124/**
125 * Returns the FUState with a given name.
126 *
127 * If FUState is not found, returns NullFUState.
128 *
129 * @param name Name of the FUState.
130 * @return FUState with a given name.
131 */
132FUState&
133MachineState::fuState(const std::string& name) {
134 FUContainer::iterator iter = FUStates_.find(name);
135 if (iter == FUStates_.end()) {
136 return NullFUState::instance();
137 }
138 return *((*iter).second);
139}
140
141/**
142 * Returns the FUState with a given index.
143 *
144 * @param index The index of the FUState.
145 * @return The FUState with a given index.
146 * @exception OutOfRange If index is out of range.
147 */
148FUState&
150 const int count = FUStateCount();
151 if (index < 0 || (index > count - 1)) {
152 string msg = "FUState index out of range";
153 throw OutOfRange(__FILE__, __LINE__, __func__, msg);
154 }
155
156 int i = 0;
157 FUContainer::iterator iter = FUStates_.begin();
158 while (i < index) {
159 iter++;
160 ++i;
161 }
162 return *((*iter).second);
163}
164
165/**
166 * Returns PortState with a given name.
167 *
168 * If PortState is not found, return NullPortState.
169 *
170 * @param portName The name of the PortState.
171 * @param fuName The name of the parent FU of the port.
172 * @return PortState with a given name.
173 */
176 const std::string& portName,
177 const std::string& fuName) {
178
179 PortContainer::iterator i =
180 ports_.find(fuName + "." + StringTools::stringToLower(portName));
181 if (i == ports_.end())
183 else
184 return *(*i).second;
185}
186
187/**
188 * Returns LongImmediateUnitState with a given name.
189 *
190 * If LongImmediateUnitState is not found, returns NullLongImmediateUnistState.
191 *
192 * @param name The name of the LongImmediateUnitState.
193 * @return LongImmediateUnitState with a given name.
194 */
196MachineState::longImmediateUnitState(const std::string& name) {
197 LongImmediateContainer::iterator iter = longImmediates_.find(name);
198 if (iter == longImmediates_.end()) {
200 }
201 return *((*iter).second);
202}
203
204/**
205 * Returns RegisterFileState with a given name.
206 *
207 * If RegisterFileState is not found, return NullRegisterFileState.
208 *
209 * @param name The name of the state.
210 * @return RegisterFileState with a given name.
211 */
213MachineState::registerFileState(const std::string& name) {
214 RegisterFileContainer::iterator iter = registers_.find(name);
215 if (iter == registers_.end()) {
217 }
218 return *((*iter).second);
219}
220
221/**
222 * Returns the GuardState associated with the given MOM Guard.
223 *
224 * If not found, returns NullGuardState::instace().
225 *
226 * @param name The MOM Guard instance.
227 * @return GuardState associated with the instance.
228 */
231 GuardContainer::iterator iter = guards_.find(&guard);
232 if (iter == guards_.end()) {
234 }
235 return *((*iter).second);
236}
237
238/**
239 * Adds GCUState to machine state.
240 *
241 * @param state GCUState to be added.
242 */
243void
245 GCUState_ = state;
246}
247
248/**
249 * Adds BusState to machine state.
250 *
251 * @param state BusState to be added.
252 * @param name The name of the BusState.
253 */
254void
255MachineState::addBusState(BusState* state, const std::string& name) {
256 busses_[name] = state;
257 busCache_.push_back(state);
258}
259
260/**
261 * Adds FUState.
262 *
263 * @param state FUState to be added.
264 * @param name The name of the FU in ADF.
265 */
266void
267MachineState::addFUState(FUState* state, const std::string& name) {
268 FUStates_[name] = state;
269 fuCache_.push_back(state);
270}
271
272/**
273 * Adds PortState.
274 *
275 * @param state PortState to be added.
276 * @param name Name of the port in ADF.
277 * @param fuName Name of the FU of the port in ADF.
278 */
279void
281 PortState* state,
282 const std::string& name,
283 const std::string& fuName) {
284 ports_[fuName + "." + StringTools::stringToLower(name)] = state;
285 portCache_.push_back(state);
286}
287
288/**
289 * Adds LongImmediateUnitState.
290 *
291 * @param state LongImmediateUnitState to be added.
292 * @param name The name of the state.
293 */
294void
297 const std::string& name) {
298
299 longImmediates_[name] = state;
300 longImmediateCache_.push_back(state);
301}
302
303/**
304 * Adds RegisterFileState.
305 *
306 * @param state State to be added.
307 * @param name Name of the state.
308 */
309void
311 RegisterFileState* state,
312 const std::string& name) {
313
314 registers_[name] = state;
315 rfCache_.push_back(state);
316}
317
318/**
319 * Adds GuardState.
320 *
321 * @param state State to be added.
322 * @param guard The machine object model guard the state represents.
323 */
324void
326 GuardState* state,
327 const TTAMachine::Guard& guard) {
328
329 guards_[&guard] = state;
330 guardCache_.push_back(state);
331}
332
333/**
334 * Adds operation executor.
335 *
336 * @param executor Operation executor.
337 */
338void
340 executors_.push_back(executor);
341}
#define __func__
find Finds info of the inner loops in the false
BusCache busCache_
ExecutorContainer executors_
Contains all operation executors.
LongImmediateContainer longImmediates_
Contains all long immediate unit states.
void addRegisterFileState(RegisterFileState *state, const std::string &name)
GCUState * GCUState_
GCU state.
PortState & portState(const std::string &portName, const std::string &fuName)
RegisterFileCache rfCache_
void addBusState(BusState *state, const std::string &name)
LongImmediateUnitState & longImmediateUnitState(const std::string &name)
GuardState & guardState(const TTAMachine::Guard &guard)
FUState & fuState(const std::string &name)
RegisterFileContainer registers_
Contains all register file states.
void addFUState(FUState *state, const std::string &name)
void addGuardState(GuardState *state, const TTAMachine::Guard &guard)
int FUStateCount() const
FUContainer FUStates_
Container of function unit states for fast traversal.
RegisterFileState & registerFileState(const std::string &name)
void addOperationExecutor(OperationExecutor *executor)
LongImmediateUnitCache longImmediateCache_
void addPortState(PortState *state, const std::string &name, const std::string &fuName)
void addGCUState(GCUState *state)
PortContainer ports_
Contains all port states.
PortCache portCache_
GuardContainer guards_
Contains all guard states.
BusState & busState(const std::string &name)
GCUState & gcuState()
virtual ~MachineState()
GuardCache guardCache_
BusContainer busses_
Contains all bus states.
void addLongImmediateUnitState(LongImmediateUnitState *state, const std::string &name)
static void deleteAllValues(MapType &aMap)
static NullBusState & instance()
Definition BusState.cc:112
static NullFUState & instance()
Definition FUState.cc:392
static NullGuardState & instance()
static NullLongImmediateUnitState & instance()
static NullPortState & instance()
Definition PortState.cc:96
static NullRegisterFileState & instance()
static void deleteAllItems(SequenceType &aSequence)
static std::string stringToLower(const std::string &source)