OpenASIP 2.2
Loading...
Searching...
No Matches
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"
42
43using std::string;
44
45/**
46 * Constructor for contexts suitable for basic operations.
47 */
50
51/**
52 * Constructor for basic operations in simulation -- FU name passed.
53 */
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 */
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 */
100OperationContext::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 */
107void
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 */
123void
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 */
137void
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 */
155
160
161void
165
166
167
168bool
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 */
182void
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 */
193bool
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 */
206SimValue&
210
211const SimValue&
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 */
223bool
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 */
237void
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 */
250Memory&
252 return pimpl_->memory();
253}
254
255const Memory&
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 */
265int
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 */
275const TCEString&
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 */
299void
303
304/**
305 * Returns the amount of pipeline delay cycles.
306 */
307int
311
312void
316
317void
321
long long CycleCount
Type for storing simulation cycle counts.
Definition BaseType.hh:187
UInt32 InstructionAddress
Definition BaseType.hh:175
#define DEFAULT_FU_NAME
void setMemory(Memory *memory)
StateRegistry & stateRegistry()
void setUpdateProgramCounter(bool value)
InstructionAddress & programCounter()
void advanceClock(OperationContext &)
void setCycleCountVariable(CycleCount &cycleCount)
const TCEString & functionUnitName()
void registerState(OperationState *state)
void setSaveReturnAddress(bool value)
void unregisterState(const char *name)
void setStateRegistry(StateRegistry &stateRegistry)
OperationState & state(const char *name) const
void registerState(OperationState *state)
void setSaveReturnAddress(bool value)
void setUpdateProgramCounter(bool value)
CycleCount cycleCount() const
int branchDelayCycles() const
OperationState & state(const char *name) const
bool updateProgramCounter() const
void setCycleCountVariable(CycleCount &cycleCount)
void setStateRegistry(StateRegistry &stateRegistry)
StateRegistry & stateRegistry()
void setMemory(Memory *memory)
const TCEString & functionUnitName() const
std::map< std::string, OperationState * > StateRegistry
Type of state registry.
SimValue & returnAddress()
virtual ~OperationContext()
void unregisterState(const char *name)
InstructionAddress & programCounter()
OperationContextPimpl * pimpl_
Implementation in separate source file to speed up compiling.