OpenASIP  2.0
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
CompiledSimulation Class Referenceabstract

#include <CompiledSimulation.hh>

Collaboration diagram for CompiledSimulation:
Collaboration graph

Public Member Functions

 CompiledSimulation (const TTAMachine::Machine &machine, InstructionAddress entryAddress, InstructionAddress lastInstruction, SimulatorFrontend &frontend, CompiledSimController &controller, MemorySystem &memorySystem, bool dynamicCompilation, ProcedureBBRelations &procedureBBRelations)
 
virtual ~CompiledSimulation ()
 
virtual void simulateCycle ()=0
 
virtual void cycleEnd ()
 
virtual void step (double count)
 
virtual void next (int count)
 
virtual void run ()
 
virtual void runUntil (UIntWord address)
 
virtual InstructionAddress programCounter () const
 
virtual InstructionAddress lastExecutedInstruction () const
 
virtual ClockCycleCount cycleCount () const
 
virtual SimValue registerFileValue (const char *rfName, int registerIndex)
 
virtual SimValue immediateUnitRegisterValue (const char *iuName, int index)
 
virtual SimValue FUPortValue (const char *fuName, const char *portName)
 
virtual void requestToStop ()
 
virtual bool stopRequested () const
 
virtual bool isFinished () const
 
virtual ClockCycleCount moveExecutionCount (int moveNumber, InstructionAddress address) const
 
virtual InstructionAddress basicBlockStart (InstructionAddress address) const
 

Static Public Member Functions

static void clearFUResults (FUResultType &results)
 
static void addFUResult (FUResultType &results, ClockCycleCount cycleCount, const SimValue &value, int latency)
 
static void addFUResult (FUResultType &results, ClockCycleCount cycleCount, const UIntWord &value, int latency)
 
static void FUResult (SimValue &target, FUResultType &results, ClockCycleCount cycles)
 

Public Attributes

ClockCycleCount cycleCount_
 Number of cycles simulated so far. More...
 
int basicBlockCount_
 Number of basic blocks gone through. More...
 
InstructionAddress jumpTarget_
 The jump target. Allows jumping to different addresses in the code. More...
 
InstructionAddress programCounter_
 The program counter. i.e. which address the simulation is currently at. More...
 
InstructionAddress lastExecutedInstruction_
 Last executed instruction. More...
 
ClockCycleCount cyclesToSimulate_
 Number of cycles left to simulate until the execution returns. More...
 
bool stopRequested_
 Should the simulation stop or not? More...
 
bool isFinished_
 Is the simulation finished? More...
 
OperationPool operationPool_
 The operation pool. More...
 
SimulateFunction jumpTargetFunc_
 Next jump target as a function pointer" << endl. More...
 
bool conflictDetected_
 A flag for FU conflict detection. More...
 
ClockCycleCountmoveExecCounts_
 Move execution counts in a C style table. More...
 
ClockCycleCountbbExecCounts_
 Basic block execution counts in a C style table. More...
 

Protected Member Functions

TTAMachine::FunctionUnitfunctionUnit (const char *name) const
 
DirectAccessMemoryFUMemory (const char *FUName) const
 
MemorySystemmemorySystem () const
 
SimulatorFrontendfrontend () const
 
void msg (const char *message) const
 
void haltSimulation (const char *file, int line, const char *procedure, const char *message) const
 
void resizeJumpTable (int newSize)
 
SimulateFunction getSimulateFunction (InstructionAddress address)
 
void setJumpTargetFunction (InstructionAddress address, SimulateFunction fp)
 
void compileAndLoadFunction (InstructionAddress address)
 
SimValuegetSymbolValue (const char *symbolName)
 
void addSymbol (const char *symbolName, SimValue &value)
 

Protected Attributes

bool dynamicCompilation_
 Is this a dynamic compiled simulation? More...
 
ProcedureBBRelationsprocedureBBRelations_
 A struct for finding out procedure begins from procedure's basic blocks. More...
 
const TTAMachine::Machinemachine_
 The simulated machine. More...
 
const InstructionAddress entryAddress_
 Entry address of the program. More...
 
const InstructionAddress lastInstruction_
 Last instruction of the program. More...
 

Private Member Functions

 CompiledSimulation (const CompiledSimulation &)
 Copying not allowed. More...
 
CompiledSimulationoperator= (const CompiledSimulation &)
 Assignment not allowed. More...
 

Private Attributes

CompiledSimulationPimplpimpl_
 Private implementation in a separate source file. More...
 

Detailed Description

An abstract class that is used as a base for all the compiled simulations

The derived classes are generated by CompiledSimCodeGenerator and then get loaded as plugins by the CompiledSimController.

Definition at line 112 of file CompiledSimulation.hh.

Constructor & Destructor Documentation

◆ CompiledSimulation() [1/2]

CompiledSimulation::CompiledSimulation ( const TTAMachine::Machine machine,
InstructionAddress  entryAddress,
InstructionAddress  lastInstruction,
SimulatorFrontend frontend,
CompiledSimController controller,
MemorySystem memorySystem,
bool  dynamicCompilation,
ProcedureBBRelations procedureBBRelations 
)

The constructor

Grabs all shared data from machine and program and saves them for easy access for later usage.

Parameters
machineThe simulated machine
programThe simulated program
frontendThe simulation frontend
memorySystemThe memory system

Definition at line 72 of file CompiledSimulation.cc.

80  :
81  cycleCount_(0),
83  jumpTarget_(entryAddress),
84  programCounter_(entryAddress),
87  stopRequested_(false),
88  isFinished_(false),
89  conflictDetected_(false),
90  dynamicCompilation_(dynamicCompilation),
91  procedureBBRelations_(procedureBBRelations),
93  entryAddress_(entryAddress),
94  lastInstruction_(lastInstruction), pimpl_(new CompiledSimulationPimpl()) {
97  pimpl_->controller_ = &controller;
98 
99  // Allocate memory for calculating move and basic block execution counts
100  int moveCount = pimpl_->controller_->program().moveCount();
101  moveExecCounts_ = new ClockCycleCount[moveCount];
102  for (int i = 0; i < moveCount; ++i) {
103  moveExecCounts_[i] = 0;
104  }
105 
106  int bbCount = lastInstruction - entryAddress + 1;
107  bbExecCounts_ = new ClockCycleCount[bbCount];
108  for (int i = 0; i < bbCount; ++i) {
109  bbExecCounts_[i] = 0;
110  }
111 
112  // Find program exit points
115 }

References bbExecCounts_, CompiledSimulationPimpl::controller_, CompiledSimulationPimpl::exitPoints_, TTASimulationController::findProgramExitPoints(), frontend(), CompiledSimulationPimpl::frontend_, machine_, memorySystem(), CompiledSimulationPimpl::memorySystem_, TTAProgram::Program::moveCount(), moveExecCounts_, pimpl_, and CompiledSimController::program().

Here is the call graph for this function:

◆ ~CompiledSimulation()

CompiledSimulation::~CompiledSimulation ( )
virtual

The destructor. Frees private implementation

Definition at line 120 of file CompiledSimulation.cc.

120  {
121  delete[] bbExecCounts_;
122  bbExecCounts_ = NULL;
123 
124  delete[] moveExecCounts_;
125  moveExecCounts_ = NULL;
126 
127  delete pimpl_;
128  pimpl_ = NULL;
129 
130 }

References bbExecCounts_, moveExecCounts_, and pimpl_.

◆ CompiledSimulation() [2/2]

CompiledSimulation::CompiledSimulation ( const CompiledSimulation )
private

Copying not allowed.

Member Function Documentation

◆ addFUResult() [1/2]

static void CompiledSimulation::addFUResult ( FUResultType results,
ClockCycleCount  cycleCount,
const SimValue value,
int  latency 
)
inlinestatic

◆ addFUResult() [2/2]

static void CompiledSimulation::addFUResult ( FUResultType results,
ClockCycleCount  cycleCount,
const UIntWord value,
int  latency 
)
inlinestatic

◆ addSymbol()

void CompiledSimulation::addSymbol ( const char *  symbolName,
SimValue value 
)
protected

Adds a new symbol name -> SimValue pair to the symbols map

Parameters
symbolNamethe symbol name
valuethe SimValue

Definition at line 597 of file CompiledSimulation.cc.

597  {
598  pimpl_->symbols_[std::string(symbolName)] = &value;
599 }

References pimpl_, and CompiledSimulationPimpl::symbols_.

◆ basicBlockStart()

InstructionAddress CompiledSimulation::basicBlockStart ( InstructionAddress  address) const
virtual

Returns start of the basic block for given address of a basic block

Parameters
addressaddress of a basic block
Returns
start address of the basic block

Definition at line 389 of file CompiledSimulation.cc.

389  {
390  return pimpl_->controller_->basicBlockStart(address);
391 }

References CompiledSimController::basicBlockStart(), CompiledSimulationPimpl::controller_, and pimpl_.

Referenced by moveExecutionCount().

Here is the call graph for this function:

◆ clearFUResults()

static void CompiledSimulation::clearFUResults ( FUResultType results)
inlinestatic

◆ compileAndLoadFunction()

void CompiledSimulation::compileAndLoadFunction ( InstructionAddress  address)
protected

Compiles and loads all simulate functions belonging to a procedure containing the given address.

Parameters
address(any) address of a procedure to compile

Definition at line 535 of file CompiledSimulation.cc.

535  {
536 
537  InstructionAddress procedureStart =
539 
540  // Files compiled so far
541  std::set<std::string> compiledFiles;
542 
544 
545  // Get basic blocks of a procedure
546  typedef ProcedureBBRelations::BasicBlockStarts::iterator BBIterator;
547  std::pair<BBIterator, BBIterator> equalRange =
548  procedureBBRelations_.basicBlockStarts.equal_range(procedureStart);
549 
550  // Loop all basic blocks of a procedure, then compile all its files
551  for (BBIterator it = equalRange.first; it != equalRange.second; ++it) {
552  std::string file = procedureBBRelations_.basicBlockFiles[it->second];
553 
554  // Compile the file if it hasn't been already
555  if (compiledFiles.find(file) == compiledFiles.end()) {
557  std::string soPath = FileSystem::directoryOfPath(file)
559  + FileSystem::fileNameBody(file) + ".so";
561  compiledFiles.insert(file);
562  }
563 
564  // Load the generated simulate function
565  SimulateFunction fn;
567  symbolGen.basicBlockSymbol(it->second), fn);
568  setJumpTargetFunction(it->second, fn);
569  }
570 }

References ProcedureBBRelations::basicBlockFiles, ProcedureBBRelations::basicBlockStarts, CompiledSimSymbolGenerator::basicBlockSymbol(), CompiledSimulationPimpl::compiler_, CompiledSimCompiler::compileToSO(), CompiledSimulationPimpl::controller_, FileSystem::DIRECTORY_SEPARATOR, FileSystem::directoryOfPath(), FileSystem::fileNameBody(), PluginTools::importSymbol(), pimpl_, CompiledSimulationPimpl::pluginTools_, procedureBBRelations_, ProcedureBBRelations::procedureStart, PluginTools::registerModule(), setJumpTargetFunction(), and Conversion::toString().

Referenced by getSimulateFunction().

Here is the call graph for this function:

◆ cycleCount()

ClockCycleCount CompiledSimulation::cycleCount ( ) const
virtual

Returns the current cycle count

Returns
the current cycle count

Definition at line 242 of file CompiledSimulation.cc.

242  {
243  return cycleCount_;
244 }

References cycleCount_.

◆ cycleEnd()

void CompiledSimulation::cycleEnd ( )
virtual

Lets the simulator frontend handle a single cycle end.

Used for example when generating traces.

Definition at line 138 of file CompiledSimulation.cc.

References SimulatorFrontend::eventHandler(), CompiledSimulationPimpl::frontend_, Informer::handleEvent(), lastExecutedInstruction_, pimpl_, programCounter_, and SimulationEventHandler::SE_CYCLE_END.

Here is the call graph for this function:

◆ frontend()

SimulatorFrontend & CompiledSimulation::frontend ( ) const
protected

Returns a reference to the simulator frontend

Returns
a reference to the simulator frontend

Definition at line 440 of file CompiledSimulation.cc.

440  {
441  return *(pimpl_->frontend_);
442 }

References CompiledSimulationPimpl::frontend_, and pimpl_.

Referenced by CompiledSimulation().

◆ FUMemory()

DirectAccessMemory & CompiledSimulation::FUMemory ( const char *  FUName) const
protected

Returns a memory object of the given function unit

Parameters
FUNamename of the function unit
Returns
memory object of the given function unit
Exceptions
InstanceNotFoundIf an item is not found

Definition at line 413 of file CompiledSimulation.cc.

413  {
414  assert(
415  machine_.functionUnitNavigator().item(FUName)->addressSpace() != NULL);
416  return
417  dynamic_cast<DirectAccessMemory&>(
418  *memorySystem()->memory(
420  FUName)->addressSpace()).get());
421 }

References assert, TTAMachine::Machine::functionUnitNavigator(), TTAMachine::Machine::Navigator< ComponentType >::item(), machine_, MemorySystem::memory(), and memorySystem().

Here is the call graph for this function:

◆ functionUnit()

TTAMachine::FunctionUnit & CompiledSimulation::functionUnit ( const char *  name) const
protected

Returns a function unit of the given name

Parameters
namename of the function unit to return
Returns
function unit of given name
Exceptions
InstanceNotFoundIf a function unit is not found

Definition at line 401 of file CompiledSimulation.cc.

401  {
402  return *machine_.functionUnitNavigator().item(name);
403 }

References TTAMachine::Machine::functionUnitNavigator(), TTAMachine::Machine::Navigator< ComponentType >::item(), and machine_.

Referenced by FUPortValue().

Here is the call graph for this function:

◆ FUPortValue()

SimValue CompiledSimulation::FUPortValue ( const char *  fuName,
const char *  portName 
)
virtual

Returns the value of the given FU port

Parameters
fuNameName of the FU
portIndexindex of the port in the FU
Returns
A SimValue containing the port's present value
Exceptions
InstanceNotFoundIf the FU port cannot be found

Definition at line 306 of file CompiledSimulation.cc.

306  {
307 
309  FunctionUnit* fu = NULL;
310  try {
311  fu = &functionUnit(fuName);
312  } catch(InstanceNotFound& e) {
313  fu = machine_.controlUnit();
314  }
315 
316  std::string fuPort = symbolGen.portSymbol(*fu->port(portName));
317 
318  CompiledSimulationPimpl::Symbols::const_iterator fuPortIterator =
319  pimpl_->symbols_.find(fuPort);
320  if (fuPortIterator != pimpl_->symbols_.end()) {
321  return *(fuPortIterator->second);
322  } else {
323  throw InstanceNotFound(__FILE__, __LINE__, __func__,
324  "FU port " + std::string(fuPort) + " not found.");
325  }
326 }

References __func__, CompiledSimulationPimpl::controller_, TTAMachine::Machine::controlUnit(), functionUnit(), machine_, pimpl_, TTAMachine::FunctionUnit::port(), CompiledSimSymbolGenerator::portSymbol(), CompiledSimulationPimpl::symbols_, and Conversion::toString().

Here is the call graph for this function:

◆ FUResult()

static void CompiledSimulation::FUResult ( SimValue target,
FUResultType results,
ClockCycleCount  cycles 
)
inlinestatic

◆ getSimulateFunction()

SimulateFunction CompiledSimulation::getSimulateFunction ( InstructionAddress  address)
protected

Gets the simulate function of given address from the jump table.

If this is a dynamic compiled simulation, it'll first check if the simulate- function is available. If not, it will compile the required files first and then loads the simulate function symbols.

Parameters
addressaddress to get the simulate function for
Returns
Simulate Function of given address from the jump table
Exceptions
SimulationExecutionErrorIf the jump function couldn't be gotten

Definition at line 494 of file CompiledSimulation.cc.

494  {
495 
496  // Is there an already existing simulate function in the given address?
497  SimulateFunction targetFunction = pimpl_->jumpTable_[address];
498  if (targetFunction != 0) {
499  return targetFunction;
500  }
501 
502  if (dynamicCompilation_) {
503  compileAndLoadFunction(address);
504  targetFunction = pimpl_->jumpTable_[address];
505  if (targetFunction != 0) {
506  return targetFunction;
507  }
508  }
509 
510  throw SimulationExecutionError(__FILE__, __LINE__, __FUNCTION__,
511  "Cannot simulate jump to address " + Conversion::toString(address) +
512  ". Please try with the interpretive simulation engine." );
513 }

References compileAndLoadFunction(), dynamicCompilation_, CompiledSimulationPimpl::jumpTable_, pimpl_, and Conversion::toString().

Here is the call graph for this function:

◆ getSymbolValue()

SimValue * CompiledSimulation::getSymbolValue ( const char *  symbolName)
protected

Returns value of the given symbol (be it RF, FU, or IU)

Parameters
symbolNameSymbol name in the generated code
Returns
a pointer to the symbol's SimValue or 0 if the symbol wasn't found

Definition at line 579 of file CompiledSimulation.cc.

579  {
580 
581  CompiledSimulationPimpl::Symbols::iterator it = pimpl_->symbols_.find(
582  std::string(symbolName));
583 
584  if (it != pimpl_->symbols_.end()) {
585  return it->second;
586  } else {
587  return 0;
588  }
589 }

References pimpl_, and CompiledSimulationPimpl::symbols_.

◆ haltSimulation()

void CompiledSimulation::haltSimulation ( const char *  file,
int  line,
const char *  procedure,
const char *  message 
) const
protected

Halts simulation by throwing an exception with a message attached to it

Parameters
filefile where the exception happened, i.e. FILE
lineline where the exception happened, i.e. LINE
procedurefunction where the exception happened, i.e. FUNCTION
messagemessage to attach
Exceptions
SimulationExecutionErrorthrown always

Definition at line 464 of file CompiledSimulation.cc.

468  {
469  throw SimulationExecutionError(file, line, procedure, message);
470 }

◆ immediateUnitRegisterValue()

SimValue CompiledSimulation::immediateUnitRegisterValue ( const char *  iuName,
int  index 
)
virtual

Returns the value of the selected immediate unit register

Parameters
iuNameThe name of the immediate unit
indexIndex of the immediate register
Returns
A SimValue containing the present immediate register value
Exceptions
InstanceNotFoundIf the immediate unit cannot be found

Definition at line 280 of file CompiledSimulation.cc.

280  {
281 
284  std::string immediateUnit = symbolGen.immediateRegisterSymbol(
285  iu, index);
286 
287  CompiledSimulationPimpl::Symbols::const_iterator iuIterator =
288  pimpl_->symbols_.find(immediateUnit);
289  if (iuIterator != pimpl_->symbols_.end()) {
290  return *(iuIterator->second);
291  } else {
292  throw InstanceNotFound(__FILE__, __LINE__, __func__,
293  "Immediate unit " + std::string(iuName) + " not found.");
294  }
295 }

References __func__, CompiledSimulationPimpl::controller_, CompiledSimSymbolGenerator::immediateRegisterSymbol(), TTAMachine::Machine::immediateUnitNavigator(), TTAMachine::Machine::Navigator< ComponentType >::item(), machine_, pimpl_, CompiledSimulationPimpl::symbols_, and Conversion::toString().

Here is the call graph for this function:

◆ isFinished()

bool CompiledSimulation::isFinished ( ) const
virtual

Returns true if the simulation is finished

Returns
true if the simulation is finished

Definition at line 354 of file CompiledSimulation.cc.

354  {
355  return isFinished_;
356 }

References isFinished_.

◆ lastExecutedInstruction()

InstructionAddress CompiledSimulation::lastExecutedInstruction ( ) const
virtual

Returns address of the last executed instruction

Returns
Address of the last executed instruction

Definition at line 233 of file CompiledSimulation.cc.

233  {
234  return lastExecutedInstruction_;
235 }

References lastExecutedInstruction_.

◆ memorySystem()

MemorySystem * CompiledSimulation::memorySystem ( ) const
protected

Returns a pointer to the memory system

Returns
a pointer to the memory system

Definition at line 429 of file CompiledSimulation.cc.

429  {
430  assert (pimpl_->memorySystem_ != NULL);
431  return pimpl_->memorySystem_;
432 }

References assert, CompiledSimulationPimpl::memorySystem_, and pimpl_.

Referenced by CompiledSimulation(), and FUMemory().

◆ moveExecutionCount()

ClockCycleCount CompiledSimulation::moveExecutionCount ( int  moveNumber,
InstructionAddress  address 
) const
virtual

Returns move execution count for move #moveNumber.

Parameters
moveNumbermove number as in POM
Returns
move execution count

Definition at line 365 of file CompiledSimulation.cc.

367  {
369  InstructionAddress programStartAddress = program.startAddress().location();
370  const Move& move = program.moveAt(moveNumber);
371 
372  if (move.isUnconditional() && pimpl_->exitPoints_.find(address) ==
373  pimpl_->exitPoints_.end()) {
374  // Grab the whole basic block execution count
375  InstructionAddress bbStart = basicBlockStart(address -
376  programStartAddress);
377  return bbExecCounts_[bbStart];
378  } else { // guarded move or an exit point, grab single move execution count
379  return moveExecCounts_[moveNumber];
380  }
381 }

References basicBlockStart(), bbExecCounts_, CompiledSimulationPimpl::controller_, CompiledSimulationPimpl::exitPoints_, TTAProgram::Move::isUnconditional(), moveExecCounts_, pimpl_, program, and CompiledSimController::program().

Referenced by CompiledSimUtilizationStats::calculate().

Here is the call graph for this function:

◆ msg()

void CompiledSimulation::msg ( const char *  message) const
protected

A short cut for printing debugging info from the compiled code.

Parameters
messageThe message string to be shown on the log stream

Definition at line 450 of file CompiledSimulation.cc.

450  {
451  Application::logStream() << message << std::endl;
452 }

References Application::logStream().

Referenced by next().

Here is the call graph for this function:

◆ next()

void CompiledSimulation::next ( int  count)
virtual

Throws an exception since this feature is not supported yet!

Exceptions
SimulationExecutionErroralways thrown

Definition at line 170 of file CompiledSimulation.cc.

170  {
171 
172  std::string msg(
173  "Command nexti not yet supported in the compiled simulation!");
174  throw SimulationExecutionError(__FILE__, __LINE__, __FUNCTION__, msg);
175 
176  if (count) {}
177 }

References msg().

Here is the call graph for this function:

◆ operator=()

CompiledSimulation& CompiledSimulation::operator= ( const CompiledSimulation )
private

Assignment not allowed.

◆ programCounter()

InstructionAddress CompiledSimulation::programCounter ( ) const
virtual

Returns the value of the current PC

Returns
the value of the current PC

Definition at line 223 of file CompiledSimulation.cc.

223  {
224  return programCounter_;
225 }

References programCounter_.

◆ registerFileValue()

SimValue CompiledSimulation::registerFileValue ( const char *  rfName,
int  registerIndex 
)
virtual

Returns the value of the selected register

Parameters
rfNameThe name of the register file
registerIndexindex of the register in the RF
Returns
A SimValue containing the present register value
Exceptions
InstanceNotFoundIf the RF cannot be found

Definition at line 255 of file CompiledSimulation.cc.

255  {
256 
259  std::string registerFile = symbolGen.registerSymbol(rf, registerIndex);
260 
261  CompiledSimulationPimpl::Symbols::const_iterator rfIterator =
262  pimpl_->symbols_.find(registerFile);
263  if (rfIterator != pimpl_->symbols_.end()) {
264  return *(rfIterator->second);
265  } else {
266  throw InstanceNotFound(__FILE__, __LINE__, __func__,
267  "Register file " + std::string(rfName) + " not found.");
268  }
269 }

References __func__, CompiledSimulationPimpl::controller_, TTAMachine::Machine::Navigator< ComponentType >::item(), machine_, pimpl_, TTAMachine::Machine::registerFileNavigator(), CompiledSimSymbolGenerator::registerSymbol(), CompiledSimulationPimpl::symbols_, and Conversion::toString().

Here is the call graph for this function:

◆ requestToStop()

void CompiledSimulation::requestToStop ( )
virtual

Sets the simulation to be requested to stop

Definition at line 332 of file CompiledSimulation.cc.

332  {
333  stopRequested_ = true;
334 }

References stopRequested_.

◆ resizeJumpTable()

void CompiledSimulation::resizeJumpTable ( int  newSize)
protected

Resizes the jump table

Parameters
newSizeNew size

Definition at line 478 of file CompiledSimulation.cc.

478  {
479  pimpl_->jumpTable_.resize(newSize, 0);
480 }

References CompiledSimulationPimpl::jumpTable_, and pimpl_.

◆ run()

void CompiledSimulation::run ( )
virtual

Runs the simulation until it is finished or an exception occurs

Note
Advances only at an accuracy of a one basic block!
Parameters
addressAn address the simulation is allowed to stop after
Exceptions
SimulationExecutionErrorIf a runtime error occurs in the simulated program.

Definition at line 189 of file CompiledSimulation.cc.

189  {
191  stopRequested_ = false;
192  while (!isFinished_ && !stopRequested_) {
193  simulateCycle();
194  }
195 }

References cyclesToSimulate_, isFinished_, MAX_CYCLES, simulateCycle(), and stopRequested_.

Here is the call graph for this function:

◆ runUntil()

void CompiledSimulation::runUntil ( UIntWord  address)
virtual

Advance the simulation until a given address is reached

Note
Advances only at an accuracy of a one basic block!
Parameters
addressAn address the simulation is allowed to stop after
Exceptions
SimulationExecutionErrorIf a runtime error occurs in the simulated program.

Definition at line 207 of file CompiledSimulation.cc.

207  {
209  stopRequested_ = false;
210  while ((!stopRequested_ && !isFinished_ &&
211  (jumpTarget_ != address || cycleCount_ == 0))) {
212  simulateCycle();
213  }
214 }

References cycleCount_, cyclesToSimulate_, isFinished_, jumpTarget_, MAX_CYCLES, simulateCycle(), and stopRequested_.

Here is the call graph for this function:

◆ setJumpTargetFunction()

void CompiledSimulation::setJumpTargetFunction ( InstructionAddress  address,
SimulateFunction  fp 
)
protected

Sets a jump target function for given address at the jump table

Parameters
addressaddress to set a jump function for
fpfunction pointer to set at the address

Definition at line 522 of file CompiledSimulation.cc.

524  {
525  pimpl_->jumpTable_[address] = fp;
526 }

References CompiledSimulationPimpl::jumpTable_, and pimpl_.

Referenced by compileAndLoadFunction().

◆ simulateCycle()

virtual void CompiledSimulation::simulateCycle ( )
pure virtual

Referenced by run(), runUntil(), and step().

◆ step()

void CompiledSimulation::step ( double  count)
virtual

Advance the simulation by a given amout of cycles.

Note
Advances only at an accuracy of a one basic block!
Parameters
countThe number of cycles the simulation should be advanced at least
Exceptions
SimulationExecutionErrorIf a runtime error occurs in the simulated program.

Definition at line 155 of file CompiledSimulation.cc.

155  {
156  cyclesToSimulate_ = cycleCount_ + static_cast<ClockCycleCount>(count);
157  stopRequested_ = false;
158 
159  while (!stopRequested_ && !isFinished_) {
160  simulateCycle();
161  }
162 }

References cycleCount_, cyclesToSimulate_, isFinished_, simulateCycle(), and stopRequested_.

Here is the call graph for this function:

◆ stopRequested()

bool CompiledSimulation::stopRequested ( ) const
virtual

Returns true if the simulation is requested to stop

This can be either because the simulation has finished or the requested amount of cycles has been simulated.

Returns
true if the simulation should stop

Definition at line 345 of file CompiledSimulation.cc.

345  {
346  return stopRequested_;
347 }

References stopRequested_.

Member Data Documentation

◆ basicBlockCount_

int CompiledSimulation::basicBlockCount_

Number of basic blocks gone through.

Definition at line 164 of file CompiledSimulation.hh.

◆ bbExecCounts_

ClockCycleCount* CompiledSimulation::bbExecCounts_

Basic block execution counts in a C style table.

Definition at line 192 of file CompiledSimulation.hh.

Referenced by CompiledSimulation(), moveExecutionCount(), and ~CompiledSimulation().

◆ conflictDetected_

bool CompiledSimulation::conflictDetected_

A flag for FU conflict detection.

Definition at line 184 of file CompiledSimulation.hh.

◆ cycleCount_

ClockCycleCount CompiledSimulation::cycleCount_

Number of cycles simulated so far.

Definition at line 162 of file CompiledSimulation.hh.

Referenced by cycleCount(), runUntil(), and step().

◆ cyclesToSimulate_

ClockCycleCount CompiledSimulation::cyclesToSimulate_

Number of cycles left to simulate until the execution returns.

Definition at line 172 of file CompiledSimulation.hh.

Referenced by run(), runUntil(), and step().

◆ dynamicCompilation_

bool CompiledSimulation::dynamicCompilation_
protected

Is this a dynamic compiled simulation?

Definition at line 236 of file CompiledSimulation.hh.

Referenced by getSimulateFunction().

◆ entryAddress_

const InstructionAddress CompiledSimulation::entryAddress_
protected

Entry address of the program.

Definition at line 245 of file CompiledSimulation.hh.

◆ isFinished_

bool CompiledSimulation::isFinished_

Is the simulation finished?

Definition at line 176 of file CompiledSimulation.hh.

Referenced by isFinished(), run(), runUntil(), and step().

◆ jumpTarget_

InstructionAddress CompiledSimulation::jumpTarget_

The jump target. Allows jumping to different addresses in the code.

Definition at line 166 of file CompiledSimulation.hh.

Referenced by runUntil().

◆ jumpTargetFunc_

SimulateFunction CompiledSimulation::jumpTargetFunc_

Next jump target as a function pointer" << endl.

Definition at line 181 of file CompiledSimulation.hh.

◆ lastExecutedInstruction_

InstructionAddress CompiledSimulation::lastExecutedInstruction_

Last executed instruction.

Definition at line 170 of file CompiledSimulation.hh.

Referenced by cycleEnd(), and lastExecutedInstruction().

◆ lastInstruction_

const InstructionAddress CompiledSimulation::lastInstruction_
protected

Last instruction of the program.

Definition at line 247 of file CompiledSimulation.hh.

◆ machine_

const TTAMachine::Machine& CompiledSimulation::machine_
protected

◆ moveExecCounts_

ClockCycleCount* CompiledSimulation::moveExecCounts_

Move execution counts in a C style table.

Definition at line 189 of file CompiledSimulation.hh.

Referenced by CompiledSimulation(), moveExecutionCount(), and ~CompiledSimulation().

◆ operationPool_

OperationPool CompiledSimulation::operationPool_

The operation pool.

Definition at line 179 of file CompiledSimulation.hh.

◆ pimpl_

CompiledSimulationPimpl* CompiledSimulation::pimpl_
private

◆ procedureBBRelations_

ProcedureBBRelations& CompiledSimulation::procedureBBRelations_
protected

A struct for finding out procedure begins from procedure's basic blocks.

Definition at line 239 of file CompiledSimulation.hh.

Referenced by compileAndLoadFunction().

◆ programCounter_

InstructionAddress CompiledSimulation::programCounter_

The program counter. i.e. which address the simulation is currently at.

Definition at line 168 of file CompiledSimulation.hh.

Referenced by cycleEnd(), and programCounter().

◆ stopRequested_

bool CompiledSimulation::stopRequested_

Should the simulation stop or not?

Definition at line 174 of file CompiledSimulation.hh.

Referenced by requestToStop(), run(), runUntil(), step(), and stopRequested().


The documentation for this class was generated from the following files:
CompiledSimulation::compileAndLoadFunction
void compileAndLoadFunction(InstructionAddress address)
Definition: CompiledSimulation.cc:535
TTAProgram::Program
Definition: Program.hh:63
CompiledSimulation::cycleCount_
ClockCycleCount cycleCount_
Number of cycles simulated so far.
Definition: CompiledSimulation.hh:162
ProcedureBBRelations::procedureStart
std::map< InstructionAddress, InstructionAddress > procedureStart
Procedure start per basic block starts.
Definition: CompiledSimCodeGenerator.hh:80
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
TTAProgram::Move::isUnconditional
bool isUnconditional() const
Definition: Move.cc:154
CompiledSimulation::setJumpTargetFunction
void setJumpTargetFunction(InstructionAddress address, SimulateFunction fp)
Definition: CompiledSimulation.cc:522
CompiledSimulation::frontend
SimulatorFrontend & frontend() const
Definition: CompiledSimulation.cc:440
CompiledSimulation::moveExecCounts_
ClockCycleCount * moveExecCounts_
Move execution counts in a C style table.
Definition: CompiledSimulation.hh:189
DirectAccessMemory
Definition: DirectAccessMemory.hh:55
CompiledSimulation::programCounter_
InstructionAddress programCounter_
The program counter. i.e. which address the simulation is currently at.
Definition: CompiledSimulation.hh:168
CompiledSimulationPimpl::memorySystem_
MemorySystem * memorySystem_
The memory system.
Definition: CompiledSimulationPimpl.hh:65
TTAMachine::FunctionUnit::port
virtual BaseFUPort * port(const std::string &name) const
Definition: FunctionUnit.cc:145
SimulationExecutionError
Definition: Exception.hh:951
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
CompiledSimulation::jumpTarget_
InstructionAddress jumpTarget_
The jump target. Allows jumping to different addresses in the code.
Definition: CompiledSimulation.hh:166
Conversion::toString
static std::string toString(const T &source)
CompiledSimulationPimpl::controller_
CompiledSimController * controller_
Simulation controller.
Definition: CompiledSimulationPimpl.hh:69
CompiledSimulation::lastExecutedInstruction_
InstructionAddress lastExecutedInstruction_
Last executed instruction.
Definition: CompiledSimulation.hh:170
CompiledSimulation::lastInstruction_
const InstructionAddress lastInstruction_
Last instruction of the program.
Definition: CompiledSimulation.hh:247
CompiledSimulation::memorySystem
MemorySystem * memorySystem() const
Definition: CompiledSimulation.cc:429
CompiledSimulation::basicBlockCount_
int basicBlockCount_
Number of basic blocks gone through.
Definition: CompiledSimulation.hh:164
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
CompiledSimulation::pimpl_
CompiledSimulationPimpl * pimpl_
Private implementation in a separate source file.
Definition: CompiledSimulation.hh:256
CompiledSimulation::isFinished_
bool isFinished_
Is the simulation finished?
Definition: CompiledSimulation.hh:176
TTAMachine::Machine::controlUnit
virtual ControlUnit * controlUnit() const
Definition: Machine.cc:345
CompiledSimulationPimpl
Definition: CompiledSimulationPimpl.hh:53
PluginTools::importSymbol
void importSymbol(const std::string &symbolName, T *&target, const std::string &module)
SimulateFunction
void(* SimulateFunction)(void *engine)
Type for the simulateXXXXX basic block functions.
Definition: CompiledSimulation.hh:62
CompiledSimulation::bbExecCounts_
ClockCycleCount * bbExecCounts_
Basic block execution counts in a C style table.
Definition: CompiledSimulation.hh:192
CompiledSimulation::procedureBBRelations_
ProcedureBBRelations & procedureBBRelations_
A struct for finding out procedure begins from procedure's basic blocks.
Definition: CompiledSimulation.hh:239
CompiledSimulationPimpl::jumpTable_
JumpTable jumpTable_
The jump table.
Definition: CompiledSimulationPimpl.hh:76
TTAMachine::Machine::immediateUnitNavigator
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition: Machine.cc:416
TTASimulationController::findProgramExitPoints
virtual std::set< InstructionAddress > findProgramExitPoints(const TTAProgram::Program &program, const TTAMachine::Machine &machine) const
Definition: TTASimulationController.cc:209
CompiledSimulationPimpl::frontend_
SimulatorFrontend * frontend_
The simulator frontend.
Definition: CompiledSimulationPimpl.hh:67
ProcedureBBRelations::basicBlockFiles
std::map< InstructionAddress, std::string > basicBlockFiles
Basic block starts and their corresponding .cpp files.
Definition: CompiledSimCodeGenerator.hh:89
SimulationEventHandler::SE_CYCLE_END
@ SE_CYCLE_END
Generated before advancing the simulator clock at the end of a simulation cycle.
Definition: SimulationEventHandler.hh:50
__func__
#define __func__
Definition: Application.hh:67
FileSystem::directoryOfPath
static std::string directoryOfPath(const std::string fileName)
Definition: FileSystem.cc:79
PluginTools::registerModule
void registerModule(const std::string &module)
Definition: PluginTools.cc:138
CompiledSimulation::simulateCycle
virtual void simulateCycle()=0
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
TTAProgram::Move
Definition: Move.hh:55
CompiledSimulation::machine_
const TTAMachine::Machine & machine_
The simulated machine.
Definition: CompiledSimulation.hh:242
CompiledSimulationPimpl::exitPoints_
std::set< InstructionAddress > exitPoints_
Program exit points in a set.
Definition: CompiledSimulationPimpl.hh:79
CompiledSimulationPimpl::symbols_
Symbols symbols_
A Symbol map for easily getting the SimValues out of the simulation.
Definition: CompiledSimulationPimpl.hh:74
ProcedureBBRelations::basicBlockStarts
BasicBlockStarts basicBlockStarts
All basic block start addresses per procedure start.
Definition: CompiledSimCodeGenerator.hh:86
CompiledSimulationPimpl::compiler_
CompiledSimCompiler compiler_
The Compiled Simulation compiler.
Definition: CompiledSimulationPimpl.hh:82
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
CompiledSimSymbolGenerator
Definition: CompiledSimSymbolGenerator.hh:66
CompiledSimController::basicBlockStart
InstructionAddress basicBlockStart(InstructionAddress address) const
Definition: CompiledSimController.cc:385
CompiledSimulation::entryAddress_
const InstructionAddress entryAddress_
Entry address of the program.
Definition: CompiledSimulation.hh:245
CompiledSimController::program
const TTAProgram::Program & program() const
Definition: CompiledSimController.cc:394
TTAMachine::Machine::registerFileNavigator
virtual RegisterFileNavigator registerFileNavigator() const
Definition: Machine.cc:450
SimulatorFrontend::eventHandler
SimulationEventHandler & eventHandler()
Definition: SimulatorFrontend.cc:2260
TTAProgram::Program::moveCount
int moveCount() const
Definition: Program.cc:494
CompiledSimulationPimpl::pluginTools_
PluginTools pluginTools_
Plugintools used to load the compiled .so files.
Definition: CompiledSimulationPimpl.hh:84
CompiledSimulation::dynamicCompilation_
bool dynamicCompilation_
Is this a dynamic compiled simulation?
Definition: CompiledSimulation.hh:236
CompiledSimulation::stopRequested_
bool stopRequested_
Should the simulation stop or not?
Definition: CompiledSimulation.hh:174
MemorySystem::memory
MemoryPtr memory(const TTAMachine::AddressSpace &as)
Definition: MemorySystem.cc:170
CompiledSimCompiler::compileToSO
int compileToSO(const std::string &path, const std::string &flags="", bool verbose=false) const
Definition: CompiledSimCompiler.cc:210
CompiledSimulation::conflictDetected_
bool conflictDetected_
A flag for FU conflict detection.
Definition: CompiledSimulation.hh:184
CompiledSimulation::cyclesToSimulate_
ClockCycleCount cyclesToSimulate_
Number of cycles left to simulate until the execution returns.
Definition: CompiledSimulation.hh:172
ClockCycleCount
CycleCount ClockCycleCount
Alias for ClockCycleCount.
Definition: SimulatorConstants.hh:57
MAX_CYCLES
static const ClockCycleCount MAX_CYCLES
Definition: CompiledSimulation.cc:57
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
CompiledSimulation::basicBlockStart
virtual InstructionAddress basicBlockStart(InstructionAddress address) const
Definition: CompiledSimulation.cc:389
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
Informer::handleEvent
void handleEvent(int event)
FileSystem::fileNameBody
static std::string fileNameBody(const std::string &fileName)
Definition: FileSystem.cc:291
CompiledSimulation::functionUnit
TTAMachine::FunctionUnit & functionUnit(const char *name) const
Definition: CompiledSimulation.cc:401
InstanceNotFound
Definition: Exception.hh:304
CompiledSimulation::msg
void msg(const char *message) const
Definition: CompiledSimulation.cc:450
TTAMachine::ImmediateUnit
Definition: ImmediateUnit.hh:50