OpenASIP  2.0
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
OperationContextPimpl Class Reference

#include <OperationContextPimpl.hh>

Collaboration diagram for OperationContextPimpl:
Collaboration graph

Public Types

typedef std::map< std::string, OperationState * > StateRegistry
 Type of state registry. More...
 

Public Member Functions

 ~OperationContextPimpl ()
 
void setStateRegistry (StateRegistry &stateRegistry)
 
void unsetStateRegistry ()
 
StateRegistrystateRegistry ()
 

Private Member Functions

 OperationContextPimpl (const TCEString &name)
 
 OperationContextPimpl (const TCEString &name, Memory *memory, InstructionAddress &programCounter, SimValue &returnAddress, int delayCycles)
 
Memorymemory ()
 
void setMemory (Memory *memory)
 
int contextId () const
 
CycleCount cycleCount () const
 
void setCycleCountVariable (CycleCount &cycleCount)
 
InstructionAddressprogramCounter ()
 
InstructionAddressirfBlockStart ()
 
void setUpdateProgramCounter (bool value)
 
bool updateProgramCounter () const
 
void setSaveReturnAddress (bool value)
 
bool saveReturnAddress ()
 
SimValuereturnAddress ()
 
void advanceClock (OperationContext &)
 
bool isEmpty () const
 
bool hasMemoryModel () const
 
const TCEStringfunctionUnitName ()
 
int branchDelayCycles ()
 
void registerState (OperationState *state)
 
void unregisterState (const char *name)
 
OperationStatestate (const char *name) const
 
bool hasState (const char *name) const
 
void initializeContextId ()
 

Private Attributes

Memorymemory_
 The Memory model instance. More...
 
int contextId_
 Unique number that identifies a context instance. More...
 
InstructionAddressprogramCounter_
 Simulates the program counter value. More...
 
SimValuereturnAddress_
 Simulates the procedure return address. More...
 
StateRegistrystateRegistry_
 The state registry. More...
 
bool saveReturnAddress_
 Should the return address be saved? More...
 
bool updateProgramCounter_
 Should program counter be updated? More...
 
CycleCount cycleCount_
 Number of times advanceClock() has been called since the creation. More...
 
CycleCountcycleCountVar_
 The external variable that contains the current simulation cycle count. More...
 
const TCEString FUName_
 Name of the FU instance – passed down from MachineStateBuilder. More...
 
int branchDelayCycles_
 Amount of delay cycles caused by pipeline. More...
 

Static Private Attributes

static int nextContextId_ = 0
 Context id for the next created context instance. More...
 

Friends

class OperationContext
 

Detailed Description

Definition at line 47 of file OperationContextPimpl.hh.

Member Typedef Documentation

◆ StateRegistry

typedef std::map<std::string, OperationState*> OperationContextPimpl::StateRegistry

Type of state registry.

Definition at line 54 of file OperationContextPimpl.hh.

Constructor & Destructor Documentation

◆ ~OperationContextPimpl()

OperationContextPimpl::~OperationContextPimpl ( )

Default destructor

Definition at line 101 of file OperationContextPimpl.cc.

101  {
102  delete stateRegistry_;
103  stateRegistry_ = NULL;
104 }

References stateRegistry_.

◆ OperationContextPimpl() [1/2]

OperationContextPimpl::OperationContextPimpl ( const TCEString name)
private

Constructor for contexts suitable for basic operations.

Definition at line 54 of file OperationContextPimpl.cc.

References initializeContextId(), and stateRegistry_.

Here is the call graph for this function:

◆ OperationContextPimpl() [2/2]

OperationContextPimpl::OperationContextPimpl ( const TCEString name,
Memory memory,
InstructionAddress programCounter,
SimValue returnAddress,
int  delayCycles 
)
private

Constructor for contexts suitable for any kinds of operations.

Parameters
memoryThe memory model instance.
nwwThe natural word width of the memory model.
programCounterThe program counter register.
returnAddressThe return address register.
syscallHandlerThe syscall handler register.
syscallNumberThe syscall code register.

Definition at line 79 of file OperationContextPimpl.cc.

84  :
85  memory_(memory),
88  saveReturnAddress_(false),
89  updateProgramCounter_(false),
90  cycleCount_(0),
91  cycleCountVar_(NULL),
92  FUName_(name),
93  branchDelayCycles_(delayCycles) {
96 }

References initializeContextId(), and stateRegistry_.

Here is the call graph for this function:

Member Function Documentation

◆ advanceClock()

void OperationContextPimpl::advanceClock ( OperationContext context)
private

Advances the internal clock of each registered operation state object.

Definition at line 155 of file OperationContextPimpl.cc.

155  {
156 
157  StateRegistry::iterator i = stateRegistry_->begin();
158 
159  while (i != stateRegistry_->end()) {
160  (*i).second->advanceClock(context);
161  ++i;
162  }
163  ++cycleCount_;
164 }

References cycleCount_, and stateRegistry_.

Referenced by OperationContext::advanceClock().

◆ branchDelayCycles()

int OperationContextPimpl::branchDelayCycles ( )
private

Returns the amount of pipeline delay cycles.

Definition at line 360 of file OperationContextPimpl.cc.

360  {
361  return branchDelayCycles_;
362 }

References branchDelayCycles_.

Referenced by OperationContext::branchDelayCycles().

◆ contextId()

int OperationContextPimpl::contextId ( ) const
private

Returns the unique id of the OperationContext instance.

Returns
The unique id for the OperationContext instance.

Definition at line 237 of file OperationContextPimpl.cc.

237  {
238  return contextId_;
239 }

References contextId_.

Referenced by OperationContext::contextId().

◆ cycleCount()

CycleCount OperationContextPimpl::cycleCount ( ) const
private

Returns the count of cycles simulated.

Can be used to implement real time timer operations, etc. Uses the simulator's cycle count, if available, otherwise uses internal cycle counter that is incremented with the advanceClock();

Definition at line 348 of file OperationContextPimpl.cc.

348  {
349  if (cycleCountVar_ != NULL) {
350  return *cycleCountVar_;
351  } else {
352  return cycleCount_;
353  }
354 }

References cycleCount_, and cycleCountVar_.

Referenced by OperationContext::cycleCount(), and setCycleCountVariable().

◆ functionUnitName()

const TCEString & OperationContextPimpl::functionUnitName ( )
private

Returns the FU name of the OperationContext instance.

Returns
The FU name for the OperationContext instance.

Definition at line 247 of file OperationContextPimpl.cc.

247  {
248  return FUName_;
249 }

References FUName_.

Referenced by OperationContext::functionUnitName().

◆ hasMemoryModel()

bool OperationContextPimpl::hasMemoryModel ( ) const
private

Returns true if the context has memory model associated with it.

Returns
True if the context has memory model associated with it.

Definition at line 336 of file OperationContextPimpl.cc.

336  {
337  return (memory_ != NULL);
338 }

References memory_.

◆ hasState()

bool OperationContextPimpl::hasState ( const char *  name) const
private

Checks if state with given name can be found in the context.

Parameters
nameName of the state.
Returns
True if the state is found.

Definition at line 113 of file OperationContextPimpl.cc.

113  {
114  try {
115  state(name);
116  } catch (const KeyNotFound&) {
117  return false;
118  }
119  return true;
120 }

References state().

Referenced by registerState(), and unregisterState().

Here is the call graph for this function:

◆ initializeContextId()

void OperationContextPimpl::initializeContextId ( )
private

Generates an unique context id for the current OperationContext instance.

Definition at line 126 of file OperationContextPimpl.cc.

126  {
128  nextContextId_++;
129 }

References contextId_, and nextContextId_.

Referenced by OperationContextPimpl().

◆ irfBlockStart()

InstructionAddress& OperationContextPimpl::irfBlockStart ( )
private

◆ isEmpty()

bool OperationContextPimpl::isEmpty ( ) const
private

Returns true if there are no operation state objects stored in the context.

Returns
True if there are no operation state objects stored in the context.

Definition at line 326 of file OperationContextPimpl.cc.

326  {
327  return stateRegistry_->size() == 0;
328 }

References stateRegistry_.

Referenced by OperationContext::isEmpty().

◆ memory()

Memory & OperationContextPimpl::memory ( )
private

Returns a reference to a Memory Module wrapper instance.

This instance can be accessed by the function unit and behavior simulation methods to simulate memory access.

Returns
The Memory instance.

Definition at line 214 of file OperationContextPimpl.cc.

214  {
215  return *memory_;
216 }

References memory_.

Referenced by OperationContext::memory(), and setMemory().

◆ programCounter()

InstructionAddress & OperationContextPimpl::programCounter ( )
private

Returns a reference to the current value of the program counter register.

The value of the program counter can be changed through this reference. This is used to implement control transfer operations like jumps and calls to subroutines.

Returns
The program counter value as a reference.

Definition at line 261 of file OperationContextPimpl.cc.

261  {
262  return programCounter_;
263 }

References programCounter_.

Referenced by OperationContext::programCounter().

◆ registerState()

void OperationContextPimpl::registerState ( OperationState stateToRegister)
private

Registers the operation state for given name.

Called in the createState() of the custom OperationBehavior classes. If state with given identifier is already found in the context, program is aborted. This method is only for internal use. Used by the macro definitions of OSAL.hh.

Parameters
nameThe identifier for the registered state instance.
stateToRegisterThe state instance.

Definition at line 178 of file OperationContextPimpl.cc.

178  {
179  string stateName = stateToRegister->name();
180  // RegisterState() and unregisterState() are supposed to be used
181  // only internally, they are not part of the "client IF", therefore
182  // it's reasonable to assert.
183  assert(!hasState(stateName.c_str()));
184  (*stateRegistry_)[stateName] = stateToRegister;
185 }

References assert, hasState(), and OperationState::name().

Referenced by OperationContext::registerState().

Here is the call graph for this function:

◆ returnAddress()

SimValue & OperationContextPimpl::returnAddress ( )
private

Returns a reference to the current value of the return address register.

The value of the return address can be changed through this reference. This is used in implementing calls to subroutines.

Returns
The return address value as a reference.

Definition at line 290 of file OperationContextPimpl.cc.

290  {
291  return returnAddress_;
292 }

References returnAddress_.

Referenced by OperationContext::returnAddress().

◆ saveReturnAddress()

bool OperationContextPimpl::saveReturnAddress ( )
private

Returns true if RA should saved before executing next control flow operation.

Returns
The return address value as a reference.

Definition at line 314 of file OperationContextPimpl.cc.

314  {
315  return saveReturnAddress_;
316 }

References saveReturnAddress_.

Referenced by OperationContext::saveReturnAddress().

◆ setCycleCountVariable()

void OperationContextPimpl::setCycleCountVariable ( CycleCount cycleCount)
inlineprivate

Definition at line 74 of file OperationContextPimpl.hh.

74  {
76  }

References cycleCount(), and cycleCountVar_.

Referenced by OperationContext::setCycleCountVariable().

Here is the call graph for this function:

◆ setMemory()

void OperationContextPimpl::setMemory ( Memory memory)
private

Sets the reference to a Memory Module instance.

This instance can be accessed by the function unit and behavior simulation methods to simulate memory access.

Parameters
memoryThe Memory instance.

Definition at line 227 of file OperationContextPimpl.cc.

227  {
228  memory_ = memory;
229 }

References memory(), and memory_.

Referenced by OperationContext::setMemory().

Here is the call graph for this function:

◆ setSaveReturnAddress()

void OperationContextPimpl::setSaveReturnAddress ( bool  value)
private

Makes the return address to be saved in the RA register.

This is used by CALL instruction to save the RA before jumping.

Parameters
valueValue to set to.
Returns
The return address value as a reference.

Definition at line 303 of file OperationContextPimpl.cc.

303  {
304  saveReturnAddress_ = value;
305 }

References saveReturnAddress_.

Referenced by OperationContext::setSaveReturnAddress().

◆ setStateRegistry()

void OperationContextPimpl::setStateRegistry ( StateRegistry stateRegistry)
inline

Definition at line 56 of file OperationContextPimpl.hh.

References stateRegistry(), and stateRegistry_.

Referenced by OperationContext::setStateRegistry().

Here is the call graph for this function:

◆ setUpdateProgramCounter()

void OperationContextPimpl::setUpdateProgramCounter ( bool  value)
private

TODO

Definition at line 269 of file OperationContextPimpl.cc.

269  {
270  updateProgramCounter_ = value;
271 }

References updateProgramCounter_.

Referenced by OperationContext::setUpdateProgramCounter().

◆ state()

OperationState & OperationContextPimpl::state ( const char *  name) const
private

Looks up the (concrete) operation state identified by the string name.

Parameters
nameThe state identifier.
Returns
The found operation state instance.
Exceptions
KeyNotFoundIf state by name couldn't be found.

Definition at line 139 of file OperationContextPimpl.cc.

139  {
140 
141  StateRegistry::const_iterator i = stateRegistry_->find(name);
142 
143  if (i == stateRegistry_->end()) {
144  throw KeyNotFound(__FILE__, __LINE__, __func__,
145  "OperationContextPimpl: State not found.");
146  }
147 
148  return *(*i).second;
149 }

References __func__, and stateRegistry_.

Referenced by hasState(), and OperationContext::state().

◆ stateRegistry()

StateRegistry& OperationContextPimpl::stateRegistry ( )
inline

Definition at line 59 of file OperationContextPimpl.hh.

59 { return *stateRegistry_; }

References stateRegistry_.

Referenced by setStateRegistry(), and OperationContext::stateRegistry().

◆ unregisterState()

void OperationContextPimpl::unregisterState ( const char *  name)
private

Unregisters the operation state of given name.

This method is only for internal use. Used by the macro definitions of OSAL.hh.

Called in deleteState() of the custom OperationBehavior classes. Aborts if there's no state with given identifier in the context.

Definition at line 197 of file OperationContextPimpl.cc.

197  {
198  // RegisterState() and unregisterState() are supposed to be used
199  // only internally, they are not part of the "client IF", therefore
200  // it's reasonable to assert.
201  assert(hasState(name));
202  stateRegistry_->erase(name);
203 }

References assert, hasState(), and stateRegistry_.

Referenced by OperationContext::unregisterState().

Here is the call graph for this function:

◆ unsetStateRegistry()

void OperationContextPimpl::unsetStateRegistry ( )
inline

Definition at line 58 of file OperationContextPimpl.hh.

58 { stateRegistry_ = NULL; }

References stateRegistry_.

Referenced by OperationContext::unsetStateRegistry().

◆ updateProgramCounter()

bool OperationContextPimpl::updateProgramCounter ( ) const
private

TODO

Definition at line 277 of file OperationContextPimpl.cc.

277  {
278  return updateProgramCounter_;
279 }

References updateProgramCounter_.

Referenced by OperationContext::updateProgramCounter().

Friends And Related Function Documentation

◆ OperationContext

friend class OperationContext
friend

Definition at line 49 of file OperationContextPimpl.hh.

Member Data Documentation

◆ branchDelayCycles_

int OperationContextPimpl::branchDelayCycles_
private

Amount of delay cycles caused by pipeline.

Definition at line 127 of file OperationContextPimpl.hh.

Referenced by branchDelayCycles().

◆ contextId_

int OperationContextPimpl::contextId_
private

Unique number that identifies a context instance.

Definition at line 105 of file OperationContextPimpl.hh.

Referenced by contextId(), and initializeContextId().

◆ cycleCount_

CycleCount OperationContextPimpl::cycleCount_
private

Number of times advanceClock() has been called since the creation.

Definition at line 120 of file OperationContextPimpl.hh.

Referenced by advanceClock(), and cycleCount().

◆ cycleCountVar_

CycleCount* OperationContextPimpl::cycleCountVar_
private

The external variable that contains the current simulation cycle count.

Definition at line 123 of file OperationContextPimpl.hh.

Referenced by cycleCount(), and setCycleCountVariable().

◆ FUName_

const TCEString OperationContextPimpl::FUName_
private

Name of the FU instance – passed down from MachineStateBuilder.

Definition at line 125 of file OperationContextPimpl.hh.

Referenced by functionUnitName().

◆ memory_

Memory* OperationContextPimpl::memory_
private

The Memory model instance.

Definition at line 103 of file OperationContextPimpl.hh.

Referenced by hasMemoryModel(), memory(), and setMemory().

◆ nextContextId_

int OperationContextPimpl::nextContextId_ = 0
staticprivate

Context id for the next created context instance.

Id given for the next created OperationContext instance.

Definition at line 107 of file OperationContextPimpl.hh.

Referenced by initializeContextId().

◆ programCounter_

InstructionAddress& OperationContextPimpl::programCounter_
private

Simulates the program counter value.

Definition at line 109 of file OperationContextPimpl.hh.

Referenced by programCounter().

◆ returnAddress_

SimValue& OperationContextPimpl::returnAddress_
private

Simulates the procedure return address.

Definition at line 111 of file OperationContextPimpl.hh.

Referenced by returnAddress().

◆ saveReturnAddress_

bool OperationContextPimpl::saveReturnAddress_
private

Should the return address be saved?

Definition at line 115 of file OperationContextPimpl.hh.

Referenced by saveReturnAddress(), and setSaveReturnAddress().

◆ stateRegistry_

StateRegistry* OperationContextPimpl::stateRegistry_
private

◆ updateProgramCounter_

bool OperationContextPimpl::updateProgramCounter_
private

Should program counter be updated?

Definition at line 117 of file OperationContextPimpl.hh.

Referenced by setUpdateProgramCounter(), and updateProgramCounter().


The documentation for this class was generated from the following files:
OperationContextPimpl::returnAddress_
SimValue & returnAddress_
Simulates the procedure return address.
Definition: OperationContextPimpl.hh:111
OperationContextPimpl::stateRegistry
StateRegistry & stateRegistry()
Definition: OperationContextPimpl.hh:59
OperationContextPimpl::StateRegistry
std::map< std::string, OperationState * > StateRegistry
Type of state registry.
Definition: OperationContextPimpl.hh:54
OperationContextPimpl::contextId_
int contextId_
Unique number that identifies a context instance.
Definition: OperationContextPimpl.hh:105
NullSimValue::instance
static SimValue & instance()
Definition: SimValue.cc:1642
dummyInt
int dummyInt
Definition: OperationContextPimpl.cc:49
OperationContextPimpl::saveReturnAddress_
bool saveReturnAddress_
Should the return address be saved?
Definition: OperationContextPimpl.hh:115
OperationContextPimpl::cycleCountVar_
CycleCount * cycleCountVar_
The external variable that contains the current simulation cycle count.
Definition: OperationContextPimpl.hh:123
OperationContextPimpl::state
OperationState & state(const char *name) const
Definition: OperationContextPimpl.cc:139
assert
#define assert(condition)
Definition: Application.hh:86
OperationContextPimpl::cycleCount_
CycleCount cycleCount_
Number of times advanceClock() has been called since the creation.
Definition: OperationContextPimpl.hh:120
OperationContextPimpl::memory_
Memory * memory_
The Memory model instance.
Definition: OperationContextPimpl.hh:103
OperationContextPimpl::returnAddress
SimValue & returnAddress()
Definition: OperationContextPimpl.cc:290
OperationContextPimpl::FUName_
const TCEString FUName_
Name of the FU instance – passed down from MachineStateBuilder.
Definition: OperationContextPimpl.hh:125
OperationContextPimpl::updateProgramCounter_
bool updateProgramCounter_
Should program counter be updated?
Definition: OperationContextPimpl.hh:117
__func__
#define __func__
Definition: Application.hh:67
OperationContextPimpl::memory
Memory & memory()
Definition: OperationContextPimpl.cc:214
OperationState::name
virtual const char * name()=0
OperationContextPimpl::programCounter
InstructionAddress & programCounter()
Definition: OperationContextPimpl.cc:261
OperationContextPimpl::cycleCount
CycleCount cycleCount() const
Definition: OperationContextPimpl.cc:348
OperationContextPimpl::initializeContextId
void initializeContextId()
Definition: OperationContextPimpl.cc:126
OperationContextPimpl::nextContextId_
static int nextContextId_
Context id for the next created context instance.
Definition: OperationContextPimpl.hh:107
KeyNotFound
Definition: Exception.hh:285
OperationContextPimpl::branchDelayCycles_
int branchDelayCycles_
Amount of delay cycles caused by pipeline.
Definition: OperationContextPimpl.hh:127
dummyInstructionAddress
InstructionAddress dummyInstructionAddress
Definition: OperationContextPimpl.cc:48
OperationContextPimpl::hasState
bool hasState(const char *name) const
Definition: OperationContextPimpl.cc:113
OperationContextPimpl::programCounter_
InstructionAddress & programCounter_
Simulates the program counter value.
Definition: OperationContextPimpl.hh:109
OperationContextPimpl::stateRegistry_
StateRegistry * stateRegistry_
The state registry.
Definition: OperationContextPimpl.hh:113