OpenASIP  2.0
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 
56 using std::string;
57 
58 /**
59  * Constructor.
60  */
62  GCUState_(NULL), fuStateCount_(0), finished_(false) {
63 }
64 
65 /**
66  * Destructor.
67  */
69  clear();
70 }
71 
72 /**
73  * Reserved memory is freed, containers are emptied.
74  */
75 void
77  delete GCUState_;
78  GCUState_ = NULL;
79 
80  // Clear all caches
81  busCache_.clear();
82  fuCache_.clear();
83  portCache_.clear();
84  longImmediateCache_.clear();
85  rfCache_.clear();
86  guardCache_.clear();
87 
95 }
96 
97 /**
98  * Returns the GCUState of the machine state.
99  *
100  * @return GCUState.
101  */
102 GCUState&
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  */
115 BusState&
116 MachineState::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  */
132 FUState&
133 MachineState::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  */
148 FUState&
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  */
174 PortState&
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())
182  return NullPortState::instance();
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  */
196 MachineState::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  */
213 MachineState::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  */
229 GuardState&
231  GuardContainer::iterator iter = guards_.find(&guard);
232  if (iter == guards_.end()) {
233  return NullGuardState::instance();
234  }
235  return *((*iter).second);
236 }
237 
238 /**
239  * Adds GCUState to machine state.
240  *
241  * @param state GCUState to be added.
242  */
243 void
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  */
254 void
255 MachineState::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  */
266 void
267 MachineState::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  */
279 void
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  */
294 void
296  LongImmediateUnitState* state,
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  */
309 void
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  */
324 void
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  */
338 void
340  executors_.push_back(executor);
341 }
TTAMachine::Guard
Definition: Guard.hh:55
MachineState::longImmediateUnitState
LongImmediateUnitState & longImmediateUnitState(const std::string &name)
Definition: MachineState.cc:196
GCUState.hh
MachineState::MachineState
MachineState()
Definition: MachineState.cc:61
MachineState::addOperationExecutor
void addOperationExecutor(OperationExecutor *executor)
Definition: MachineState.cc:339
GCUState
Definition: GCUState.hh:46
NullLongImmediateUnitState::instance
static NullLongImmediateUnitState & instance()
Definition: LongImmediateUnitState.cc:191
RegisterFileState.hh
MachineState::portState
PortState & portState(const std::string &portName, const std::string &fuName)
Definition: MachineState.cc:175
MachineState::gcuState
GCUState & gcuState()
Definition: MachineState.cc:103
OutOfRange
Definition: Exception.hh:320
MapTools.hh
SequenceTools.hh
MapTools::deleteAllValues
static void deleteAllValues(MapType &aMap)
GuardState.hh
FUState.hh
BusState
Definition: BusState.hh:48
NullPortState::instance
static NullPortState & instance()
Definition: PortState.cc:96
MachineState::rfCache_
RegisterFileCache rfCache_
Definition: MachineState.hh:162
MachineState::portCache_
PortCache portCache_
Definition: MachineState.hh:160
MachineState::FUStateCount
int FUStateCount() const
LongImmediateUnitState.hh
OutputPortState.hh
StringTools.hh
MachineState::~MachineState
virtual ~MachineState()
Definition: MachineState.cc:68
FUState
Definition: FUState.hh:58
InputPortState.hh
MachineState::addPortState
void addPortState(PortState *state, const std::string &name, const std::string &fuName)
Definition: MachineState.cc:280
SequenceTools::deleteAllItems
static void deleteAllItems(SequenceType &aSequence)
SimulatorToolbox.hh
MachineState::clear
void clear()
Definition: MachineState.cc:76
MachineState::guardState
GuardState & guardState(const TTAMachine::Guard &guard)
Definition: MachineState.cc:230
NullGuardState::instance
static NullGuardState & instance()
Definition: GuardState.cc:118
MachineState::busState
BusState & busState(const std::string &name)
Definition: MachineState.cc:116
NullFUState::instance
static NullFUState & instance()
Definition: FUState.cc:392
MachineState::FUStates_
FUContainer FUStates_
Container of function unit states for fast traversal.
Definition: MachineState.hh:143
OperationExecutor.hh
BusState.hh
Application.hh
__func__
#define __func__
Definition: Application.hh:67
Operation.hh
MachineState::addGCUState
void addGCUState(GCUState *state)
Definition: MachineState.cc:244
MachineState::longImmediateCache_
LongImmediateUnitCache longImmediateCache_
Definition: MachineState.hh:161
NullRegisterFileState::instance
static NullRegisterFileState & instance()
Definition: RegisterFileState.cc:111
MachineState::addLongImmediateUnitState
void addLongImmediateUnitState(LongImmediateUnitState *state, const std::string &name)
Definition: MachineState.cc:295
PortState
Definition: PortState.hh:51
MachineState::addGuardState
void addGuardState(GuardState *state, const TTAMachine::Guard &guard)
Definition: MachineState.cc:325
OperationExecutor
Definition: OperationExecutor.hh:49
MachineState::addRegisterFileState
void addRegisterFileState(RegisterFileState *state, const std::string &name)
Definition: MachineState.cc:310
NullBusState::instance
static NullBusState & instance()
Definition: BusState.cc:112
MachineState::GCUState_
GCUState * GCUState_
GCU state.
Definition: MachineState.hh:139
MachineState::addFUState
void addFUState(FUState *state, const std::string &name)
Definition: MachineState.cc:267
MachineState::longImmediates_
LongImmediateContainer longImmediates_
Contains all long immediate unit states.
Definition: MachineState.hh:147
MachineState::executors_
ExecutorContainer executors_
Contains all operation executors.
Definition: MachineState.hh:151
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
MachineState::ports_
PortContainer ports_
Contains all port states.
Definition: MachineState.hh:145
MachineState::fuState
FUState & fuState(const std::string &name)
Definition: MachineState.cc:133
TriggeringInputPortState.hh
MachineState::registers_
RegisterFileContainer registers_
Contains all register file states.
Definition: MachineState.hh:149
MachineState.hh
RegisterFileState
Definition: RegisterFileState.hh:49
MachineState::busCache_
BusCache busCache_
Definition: MachineState.hh:158
GuardState
Definition: GuardState.hh:60
MachineState::addBusState
void addBusState(BusState *state, const std::string &name)
Definition: MachineState.cc:255
MachineState::fuCache_
FUCache fuCache_
Definition: MachineState.hh:159
OperationPool.hh
MachineState::busses_
BusContainer busses_
Contains all bus states.
Definition: MachineState.hh:141
MachineState::guards_
GuardContainer guards_
Contains all guard states.
Definition: MachineState.hh:153
OperationContext.hh
StringTools::stringToLower
static std::string stringToLower(const std::string &source)
Definition: StringTools.cc:160
OpcodeSettingVirtualInputPortState.hh
MachineState::guardCache_
GuardCache guardCache_
Definition: MachineState.hh:163
LongImmediateUnitState
Definition: LongImmediateUnitState.hh:55
MachineState::registerFileState
RegisterFileState & registerFileState(const std::string &name)
Definition: MachineState.cc:213