OpenASIP  2.0
OperationContext.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2020 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 OperationContext.cc
26  *
27  * Non-inline definitions of OperationContext class.
28  *
29  * @author Pekka Jääskeläinen 2004 (pekka.jaaskelainen-no.spam-tut.fi)
30  * @note rating: yellow
31  * @note reviewed 7 September 2004 by pj, jn, jm, ao
32  */
33 
34 #include <string>
35 
36 #include "OperationContext.hh"
37 #include "Application.hh"
38 #include "Memory.hh"
39 #include "OperationState.hh"
40 #include "SimValue.hh"
41 #include "OperationContextPimpl.hh"
42 
43 using std::string;
44 
45 /**
46  * Constructor for contexts suitable for basic operations.
47  */
49 }
50 
51 /**
52  * Constructor for basic operations in simulation -- FU name passed.
53  */
55 }
56 
57 /**
58  * Constructor for contexts suitable for any kinds of operations.
59  *
60  * @param memory The memory model instance.
61  * @param programCounter The program counter register.
62  * @param returnAddress The return address register.
63  *
64  */
66  Memory* memory,
67  InstructionAddress& programCounter,
68  SimValue& returnAddress,
69  int delayCycles) :
70  pimpl_(new OperationContextPimpl(
71  DEFAULT_FU_NAME, memory, programCounter,
72  returnAddress, delayCycles)) {
73 }
74 
75 /**
76  * A copy constructor that performs a deep copy for the pimpl_
77  *
78  * @param context OperationContext
79  */
81  pimpl_(new OperationContextPimpl(*context.pimpl_)) {
82 }
83 
84 /**
85  * Destructor. Deletes the pimpl object
86  */
88  delete pimpl_;
89  pimpl_ = NULL;
90 }
91 
92 /**
93  * Looks up the (concrete) operation state identified by the string name.
94  *
95  * @param name The state identifier.
96  * @return The found operation state instance.
97  * @exception KeyNotFound If state by name couldn't be found.
98  */
100 OperationContext::state(const char* name) const {
101  return pimpl_->state(name);
102 }
103 
104 /**
105  * Advances the internal clock of each registered operation state object.
106  */
107 void
109  pimpl_->advanceClock(*this);
110 }
111 
112 /**
113  * Registers the operation state for given name.
114  *
115  * Called in the createState() of the custom OperationBehavior classes.
116  * If state with given identifier is already found in the context, program
117  * is aborted. This method is only for internal use. Used by the macro
118  * definitions of OSAL.hh.
119  *
120  * @param name The identifier for the registered state instance.
121  * @param stateToRegister The state instance.
122  */
123 void
125  pimpl_->registerState(stateToRegister);
126 }
127 
128 /**
129  * Unregisters the operation state of given name.
130  *
131  * This method is only for internal use. Used by the macro
132  * definitions of OSAL.hh.
133  *
134  * Called in deleteState() of the custom OperationBehavior classes.
135  * Aborts if there's no state with given identifier in the context.
136  */
137 void
139  pimpl_->unregisterState(name);
140 }
141 
142 /**
143  * Returns a reference to the current value of the program counter register.
144  *
145  * The value of the program counter can be changed through this reference.
146  * This is used to implement control transfer operations like jumps and calls
147  * to subroutines.
148  *
149  * @return The program counter value as a reference.
150  */
153  return pimpl_->programCounter();
154 }
155 
156 const InstructionAddress&
158  return pimpl_->programCounter();
159 }
160 
161 void
164 }
165 
166 
167 
168 bool
170  return pimpl_->updateProgramCounter();
171 }
172 
173 
174 /**
175  * Makes the return address to be saved in the RA register.
176  *
177  * This is used by CALL instruction to save the RA before jumping.
178  *
179  * @param value Value to set to.
180  * @return The return address value as a reference.
181  */
182 void
185 }
186 
187 /**
188  * Returns true if RA should saved before executing next control flow
189  * operation.
190  *
191  * @return The return address value as a reference.
192  */
193 bool
195  return pimpl_->saveReturnAddress();
196 }
197 
198 /**
199  * Returns a reference to the current value of the return address register.
200  *
201  * The value of the return address can be changed through this reference.
202  * This is used in implementing calls to subroutines.
203  *
204  * @return The return address value as a reference.
205  */
206 SimValue&
208  return pimpl_->returnAddress();
209 }
210 
211 const SimValue&
213  return pimpl_->returnAddress();
214 }
215 
216 /**
217  * Returns true if there are no operation state objects stored in the
218  * context.
219  *
220  * @return True if there are no operation state objects stored in the
221  * context.
222  */
223 bool
225  return pimpl_->isEmpty();
226 }
227 
228 
229 /**
230  * Sets the reference to a Memory Module instance.
231  *
232  * This instance can be accessed by the function unit and behavior
233  * simulation methods to simulate memory access.
234  *
235  * @param memory The Memory instance.
236  */
237 void
240 }
241 
242 /**
243  * Returns a reference to a Memory Module wrapper instance.
244  *
245  * This instance can be accessed by the function unit and behavior
246  * simulation methods to simulate memory access.
247  *
248  * @return The Memory instance.
249  */
250 Memory&
252  return pimpl_->memory();
253 }
254 
255 const Memory&
256 OperationContext::memory() const {
257  return pimpl_->memory();
258 }
259 
260 /**
261  * Returns the unique id of the OperationContext instance.
262  *
263  * @return The unique id for the OperationContext instance.
264  */
265 int
267  return pimpl_->contextId();
268 }
269 
270 /**
271  * Returns the FU name of the OperationContext instance.
272  *
273  * @return The FU name for the OperationContext instance.
274  */
275 const TCEString&
277  return pimpl_->functionUnitName();
278 }
279 
280 /**
281  * Returns the elapsed time since the beginning of simulation.
282  *
283  * Can be used to implement real time timer operations, etc. Uses
284  * the simulator's cycle count, if available, otherwise uses internal
285  * cycle counter that is incremented with the advanceClock();
286  */
289  return pimpl_->cycleCount();
290 }
291 
292 /**
293  * Sets the variable that contains the current simulation cycle count
294  * at the best possible accuracy.
295  *
296  * Used by real time operations to track simulation time during
297  * simulations.
298  */
299 void
302 }
303 
304 /**
305  * Returns the amount of pipeline delay cycles.
306  */
307 int
309  return pimpl_->branchDelayCycles();
310 }
311 
312 void
315 }
316 
317 void
320 }
321 
324  return pimpl_->stateRegistry();
325 }
OperationContextPimpl::unregisterState
void unregisterState(const char *name)
Definition: OperationContextPimpl.cc:197
OperationContext::setSaveReturnAddress
void setSaveReturnAddress(bool value)
Definition: OperationContext.cc:183
OperationContext::setMemory
void setMemory(Memory *memory)
Definition: OperationContext.cc:238
OperationContextPimpl::registerState
void registerState(OperationState *state)
Definition: OperationContextPimpl.cc:178
OperationContext::pimpl_
OperationContextPimpl * pimpl_
Implementation in separate source file to speed up compiling.
Definition: OperationContext.hh:113
OperationState
Definition: OperationState.hh:46
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
OperationContext::cycleCount
CycleCount cycleCount() const
Definition: OperationContext.cc:288
OperationContextPimpl::stateRegistry
StateRegistry & stateRegistry()
Definition: OperationContextPimpl.hh:59
OperationContextPimpl.hh
Memory.hh
OperationContext::memory
Memory & memory()
Definition: OperationContext.cc:251
OperationContext
Definition: OperationContext.hh:56
OperationContext::unregisterState
void unregisterState(const char *name)
Definition: OperationContext.cc:138
OperationContextPimpl::setUpdateProgramCounter
void setUpdateProgramCounter(bool value)
Definition: OperationContextPimpl.cc:269
OperationContext::functionUnitName
const TCEString & functionUnitName() const
Definition: OperationContext.cc:276
OperationContext::setStateRegistry
void setStateRegistry(StateRegistry &stateRegistry)
Definition: OperationContext.cc:313
OperationContext::saveReturnAddress
bool saveReturnAddress()
Definition: OperationContext.cc:194
OperationContext::setCycleCountVariable
void setCycleCountVariable(CycleCount &cycleCount)
Definition: OperationContext.cc:300
OperationContext::~OperationContext
virtual ~OperationContext()
Definition: OperationContext.cc:87
DEFAULT_FU_NAME
#define DEFAULT_FU_NAME
Definition: OperationContext.hh:47
OperationState.hh
OperationContextPimpl::advanceClock
void advanceClock(OperationContext &)
Definition: OperationContextPimpl.cc:155
OperationContextPimpl::state
OperationState & state(const char *name) const
Definition: OperationContextPimpl.cc:139
OperationContext::contextId
int contextId() const
Definition: OperationContext.cc:266
SimValue
Definition: SimValue.hh:96
OperationContext::registerState
void registerState(OperationState *state)
Definition: OperationContext.cc:124
OperationContext::isEmpty
bool isEmpty() const
Definition: OperationContext.cc:224
OperationContextPimpl::setMemory
void setMemory(Memory *memory)
Definition: OperationContextPimpl.cc:227
OperationContextPimpl::branchDelayCycles
int branchDelayCycles()
Definition: OperationContextPimpl.cc:360
OperationContext::branchDelayCycles
int branchDelayCycles() const
Definition: OperationContext.cc:308
OperationContext::stateRegistry
StateRegistry & stateRegistry()
Definition: OperationContext.cc:323
OperationContextPimpl::returnAddress
SimValue & returnAddress()
Definition: OperationContextPimpl.cc:290
Application.hh
OperationContextPimpl::setStateRegistry
void setStateRegistry(StateRegistry &stateRegistry)
Definition: OperationContextPimpl.hh:56
OperationContextPimpl::memory
Memory & memory()
Definition: OperationContextPimpl.cc:214
OperationContext::OperationContext
OperationContext()
Definition: OperationContext.cc:48
OperationContextPimpl::programCounter
InstructionAddress & programCounter()
Definition: OperationContextPimpl.cc:261
OperationContextPimpl::contextId
int contextId() const
Definition: OperationContextPimpl.cc:237
OperationContextPimpl::setCycleCountVariable
void setCycleCountVariable(CycleCount &cycleCount)
Definition: OperationContextPimpl.hh:74
OperationContextPimpl::cycleCount
CycleCount cycleCount() const
Definition: OperationContextPimpl.cc:348
OperationContext::programCounter
InstructionAddress & programCounter()
Definition: OperationContext.cc:152
OperationContextPimpl::updateProgramCounter
bool updateProgramCounter() const
Definition: OperationContextPimpl.cc:277
CycleCount
long long CycleCount
Type for storing simulation cycle counts.
Definition: BaseType.hh:187
SimValue.hh
TCEString
Definition: TCEString.hh:53
OperationContextPimpl::saveReturnAddress
bool saveReturnAddress()
Definition: OperationContextPimpl.cc:314
OperationContext::StateRegistry
std::map< std::string, OperationState * > StateRegistry
Type of state registry.
Definition: OperationContext.hh:72
OperationContext::setUpdateProgramCounter
void setUpdateProgramCounter(bool value)
Definition: OperationContext.cc:162
OperationContextPimpl::setSaveReturnAddress
void setSaveReturnAddress(bool value)
Definition: OperationContextPimpl.cc:303
OperationContextPimpl::unsetStateRegistry
void unsetStateRegistry()
Definition: OperationContextPimpl.hh:58
OperationContext::state
OperationState & state(const char *name) const
Definition: OperationContext.cc:100
OperationContext::unsetStateRegistry
void unsetStateRegistry()
Definition: OperationContext.cc:318
OperationContextPimpl
Definition: OperationContextPimpl.hh:47
OperationContextPimpl::functionUnitName
const TCEString & functionUnitName()
Definition: OperationContextPimpl.cc:247
OperationContext::updateProgramCounter
bool updateProgramCounter() const
Definition: OperationContext.cc:169
OperationContext::advanceClock
void advanceClock()
Definition: OperationContext.cc:108
OperationContext::returnAddress
SimValue & returnAddress()
Definition: OperationContext.cc:207
OperationContext.hh
Memory
Definition: Memory.hh:74
OperationContextPimpl::isEmpty
bool isEmpty() const
Definition: OperationContextPimpl.cc:326