OpenASIP  2.0
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
TTASimulationController Class Referenceabstract

#include <TTASimulationController.hh>

Inheritance diagram for TTASimulationController:
Inheritance graph
Collaboration diagram for TTASimulationController:
Collaboration graph

Public Types

enum  SimulationStatus {
  STA_INITIALIZING, STA_INITIALIZED, STA_RUNNING, STA_STOPPED,
  STA_FINISHED
}
 The states of simulation. More...
 

Public Member Functions

 TTASimulationController (SimulatorFrontend &frontend, const TTAMachine::Machine &machine, const TTAProgram::Program &program)
 
virtual ~TTASimulationController ()
 
virtual void step (double count=1)=0
 
virtual void next (int count=1)=0
 
virtual void run ()=0
 
virtual void runUntil (UIntWord address)=0
 
virtual void reset ()=0
 
virtual std::string registerFileValue (const std::string &rfName, int registerIndex=-1)=0
 
virtual SimValue immediateUnitRegisterValue (const std::string &iuName, int index=-1)=0
 
virtual SimValue FUPortValue (const std::string &fuName, const std::string &portName)=0
 
virtual void prepareToStop (StopReason reason)
 
virtual unsigned int stopReasonCount () const
 
virtual StopReason stopReason (unsigned int index) const
 
virtual SimulationStatus state () const
 
virtual InstructionAddress programCounter () const =0
 
virtual InstructionAddress lastExecutedInstruction (int coreId=-1) const
 
virtual ClockCycleCount clockCount () const
 
virtual MemorySystemmemorySystem (int coreId=-1)
 
virtual SimulatorFrontendfrontend ()
 
virtual bool automaticFinishImpossible () const
 
virtual std::set< InstructionAddressfindProgramExitPoints (const TTAProgram::Program &program, const TTAMachine::Machine &machine) const
 

Protected Types

typedef std::set< StopReasonStopReasonContainer
 The container type for reasons why simulation stop was requested. More...
 

Protected Member Functions

 TTASimulationController (const TTASimulationController &)
 Copying not allowed. More...
 
TTASimulationControlleroperator= (const TTASimulationController &)
 Assignment not allowed. More...
 

Protected Attributes

SimulatorFrontendfrontend_
 Reference to the simulator frontend. More...
 
const TTAMachine::MachinesourceMachine_
 The simulated Machine Object Model. More...
 
const TTAProgram::Programprogram_
 Program object model of the simulated program. More...
 
bool stopRequested_
 Flag indicating that simulation should stop. More...
 
StopReasonContainer stopReasons_
 The set of reasons the simulation was stopped. More...
 
SimulationStatus state_
 The current state of the simulation. More...
 
ClockCycleCount clockCount_
 How many clock cycles have been simulated. More...
 
std::vector< InstructionAddresslastExecutedInstruction_
 The address of the last executed instruction. More...
 
InstructionAddress initialPC_
 The address of the first executed instruction. More...
 
bool automaticFinishImpossible_
 If this is true, simulation cannot be finished automatically. More...
 
InstructionAddress firstIllegalInstructionIndex_
 The index of the first illegal instruction in the instruction sequence. More...
 

Detailed Description

An abstract interface class for controlling the simulation

Owns and is the main client of the machine state model.

Definition at line 69 of file TTASimulationController.hh.

Member Typedef Documentation

◆ StopReasonContainer

The container type for reasons why simulation stop was requested.

Definition at line 132 of file TTASimulationController.hh.

Member Enumeration Documentation

◆ SimulationStatus

The states of simulation.

Enumerator
STA_INITIALIZING 

Simulation is being initialized.

STA_INITIALIZED 

Simulation initialized and ready to run.

STA_RUNNING 

A run command (run, stepi, until...) given.

STA_STOPPED 

Simulation stopped for some reason.

STA_FINISHED 

Simulation ended after executing the last instruction.

Definition at line 72 of file TTASimulationController.hh.

72  {
73  STA_INITIALIZING,///< Simulation is being initialized.
74  STA_INITIALIZED, ///< Simulation initialized and ready to run.
75  STA_RUNNING, ///< A run command (run, stepi, until...) given.
76  STA_STOPPED, ///< Simulation stopped for some reason.
78  ///< Simulation ended after executing the last instruction.
79  };

Constructor & Destructor Documentation

◆ TTASimulationController() [1/2]

TTASimulationController::TTASimulationController ( SimulatorFrontend frontend,
const TTAMachine::Machine machine,
const TTAProgram::Program program 
)

Constructor.

Exceptions
ExceptionExceptions while building the simulation models are thrown forward.

Definition at line 60 of file TTASimulationController.cc.

63  :
68  initialPC_(program.entryAddress().location()),
71 }

◆ ~TTASimulationController()

TTASimulationController::~TTASimulationController ( )
virtual

Destructor.

Definition at line 76 of file TTASimulationController.cc.

76  {
77 }

◆ TTASimulationController() [2/2]

TTASimulationController::TTASimulationController ( const TTASimulationController )
protected

Copying not allowed.

Member Function Documentation

◆ automaticFinishImpossible()

bool TTASimulationController::automaticFinishImpossible ( ) const
virtual

Returns true in case simulation cannot be finished automatically.

In order for this method to return false, it means that while initializing the SimulationController, a probable ending point in the program was detected and it is possible that when running the simulation it is possible to finish it automatically at that position. If this method returns true it is impossible to finish simulation automatically.

Returns
True if it's not possible to end simulation automatically.

Definition at line 197 of file TTASimulationController.cc.

197  {
199 }

References automaticFinishImpossible_.

Referenced by SimulatorFrontend::automaticFinishImpossible().

◆ clockCount()

ClockCycleCount TTASimulationController::clockCount ( ) const
virtual

Returns the count of clock cycles simulated.

Returns
Count of simulated clock cycles.

Reimplemented in CompiledSimController.

Definition at line 161 of file TTASimulationController.cc.

161  {
162  return clockCount_;
163 }

References clockCount_.

Referenced by SimulatorFrontend::cycleCount(), ExecutionTracker::handleEvent(), StopPointManager::handleEvent(), and StopPointManager::stopCausingStopPointCount().

◆ findProgramExitPoints()

std::set< InstructionAddress > TTASimulationController::findProgramExitPoints ( const TTAProgram::Program program,
const TTAMachine::Machine machine 
) const
virtual

Initializes the variables that are used in programEnded() to evaluate whether the simulated program has simulated to its end.

Parameters
programThe simulated program.
machineThe simulated machine.

Definition at line 209 of file TTASimulationController.cc.

211  {
212  std::set<InstructionAddress> exitPoints;
213 
214  /* Set return points to be all the returns from the first executed
215  procedure. When control returns from that (usually the crt0(),
216  start(), or main()), we should stop simulation. This is for
217  convenience of simulating unmodified benchmark programs without
218  having infinite loops etc. */
219 
220  // find the entry procedure
221  Address entryAddr = program.entryAddress();
222  Procedure* entryProc = NULL;
223  for(int i = 0; i < program.procedureCount(); i++) {
224  Procedure& currProc = program.procedure(i);
225 
226  if (currProc.startAddress().location() <= entryAddr.location() &&
227  currProc.endAddress().location() > entryAddr.location()) {
228  entryProc = &currProc;
229  break;
230  }
231  }
232 
233  if (entryProc == NULL)
234  throw IllegalProgram(
235  __FILE__, __LINE__, __func__,
236  "The entry point of the program does not point to a procedure.");
237 
238  // If __exit procedure exists, the first instruction in it is set
239  // as an exit point.
240  for(int i = 0; i < program.procedureCount(); i++) {
241  Procedure &currProc = program.procedure(i);
242  if (currProc.name() == "_exit" || currProc.name() == "__exit") {
243  exitPoints.insert(currProc.firstInstruction().address().location());
245  }
246  }
247 
248  const int delaySlots = machine.controlUnit()->delaySlots();
249  // check instructions of entry procedure if they are "ra ->jump.1"
250  for (int i = 0; i < entryProc->instructionCount(); ++i) {
251 
252  const Instruction& currInstr = entryProc->instructionAtIndex(i);
253 
254  // check if the instruction has a return move
255  for (int m = 0; m < currInstr.moveCount(); ++m) {
256 
257  const Move& currMove = currInstr.move(m);
258 
259  if (currMove.isReturn()) {
260  // set an exit point at the return + delay slots to allow
261  // executing the delay slot code of the final return
262  unsigned exitDelay = static_cast<unsigned>(
263  i + machine.controlUnit()->delaySlots());
264  if (exitDelay <= entryProc->endAddress().location()) {
265  exitPoints.insert(
266  entryProc->instructionAtIndex(i + delaySlots).
267  address().location());
268 
270  }
271  break; // check the next instruction
272  }
273  }
274  }
275 
276  /* In case the last instruction of the first procedure is *not*
277  a jump and it's the last procedure in the program, set it as an exit
278  point too (after executing the instruction we should stop simulation
279  because there's nothing sensible to execute next). This is to allow
280  simulating some obscure assembler programs that do not loop
281  forever but just fall through the first procedure after done.
282 
283  The detection in that case is done by comparing the PC+1 to
284  firstIllegalInstructionIndex_. */
285 
286  if (program.procedureCount() == 1) {
287  // such assembly programs are usually stored in one procedure
289  }
291  program.lastInstruction().address().location() + 1;
292 
293  return exitPoints;
294 }

References __func__, TTAProgram::Instruction::address(), automaticFinishImpossible_, TTAMachine::Machine::controlUnit(), TTAMachine::ControlUnit::delaySlots(), TTAProgram::CodeSnippet::endAddress(), firstIllegalInstructionIndex_, TTAProgram::CodeSnippet::firstInstruction(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::Move::isReturn(), TTAProgram::Address::location(), machine, TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), TTAProgram::Procedure::name(), program, and TTAProgram::CodeSnippet::startAddress().

Referenced by CompiledSimulation::CompiledSimulation(), SimulationController::findExitPoints(), CompiledSimCodeGenerator::generateSimulationCode(), and RemoteController::RemoteController().

Here is the call graph for this function:

◆ frontend()

SimulatorFrontend & TTASimulationController::frontend ( )
virtual

Returns the simulator frontend.

Returns
A reference to the simulator frontend.

Definition at line 181 of file TTASimulationController.cc.

181  {
182  return frontend_;
183 }

References frontend_.

Referenced by ExecutionTracker::ExecutionTracker(), memorySystem(), SimulationController::SimulationController(), and ExecutionTracker::~ExecutionTracker().

◆ FUPortValue()

virtual SimValue TTASimulationController::FUPortValue ( const std::string &  fuName,
const std::string &  portName 
)
pure virtual

◆ immediateUnitRegisterValue()

virtual SimValue TTASimulationController::immediateUnitRegisterValue ( const std::string &  iuName,
int  index = -1 
)
pure virtual

◆ lastExecutedInstruction()

InstructionAddress TTASimulationController::lastExecutedInstruction ( int  coreId = -1) const
virtual

Returns the address of the last executed instruction.

Returns
Address of the last executed instruction.

Definition at line 147 of file TTASimulationController.cc.

147  {
148  if (coreId == -1) {
150  } else {
151  return lastExecutedInstruction_[coreId];
152  }
153 }

References frontend_, lastExecutedInstruction_, and SimulatorFrontend::selectedCore().

Referenced by ExecutionTracker::handleEvent(), and SimulatorFrontend::lastExecutedInstruction().

Here is the call graph for this function:

◆ memorySystem()

MemorySystem & TTASimulationController::memorySystem ( int  coreId = -1)
virtual

Returns a reference to the memory system.

Returns
A reference to the memory system.

Definition at line 171 of file TTASimulationController.cc.

171  {
172  return frontend().memorySystem(coreId);
173 }

References frontend(), and SimulatorFrontend::memorySystem().

Referenced by OTASimulationController::advanceMachineCycle(), SimulatorFrontend::initializeDataMemories(), CompiledSimController::reset(), and SimulationController::simulateCycle().

Here is the call graph for this function:

◆ next()

virtual void TTASimulationController::next ( int  count = 1)
pure virtual

◆ operator=()

TTASimulationController& TTASimulationController::operator= ( const TTASimulationController )
protected

Assignment not allowed.

◆ prepareToStop()

void TTASimulationController::prepareToStop ( StopReason  reason)
virtual

Get ready to return control to the client.

Functions name is has "prepare" in its name even though it always is able to stop the simulation. The reason for this is that it does not stop the simulation in the middle of simulating a clock cycle, but after the current clock cycle is simulated.

Parameters
reasonThe reason why simulation should be stopped.

Reimplemented in CompiledSimController.

Definition at line 90 of file TTASimulationController.cc.

90  {
91  stopRequested_ = true;
92  stopReasons_.insert(reason);
93 }

References stopReasons_, and stopRequested_.

Referenced by StopPointManager::handleEvent(), SimulationController::next(), CompiledSimController::prepareToStop(), SimulatorFrontend::prepareToStop(), SimulationController::runUntil(), OTASimulationController::simulateCycle(), SimulationController::simulateCycle(), and SimulationController::step().

◆ programCounter()

virtual InstructionAddress TTASimulationController::programCounter ( ) const
pure virtual

◆ registerFileValue()

virtual std::string TTASimulationController::registerFileValue ( const std::string &  rfName,
int  registerIndex = -1 
)
pure virtual

◆ reset()

virtual void TTASimulationController::reset ( )
pure virtual

◆ run()

virtual void TTASimulationController::run ( )
pure virtual

◆ runUntil()

virtual void TTASimulationController::runUntil ( UIntWord  address)
pure virtual

◆ state()

TTASimulationController::SimulationStatus TTASimulationController::state ( ) const
virtual

Returns the state of the simulation.

Returns
The state of the simulation.

Definition at line 137 of file TTASimulationController.cc.

137  {
138  return state_;
139 }

References state_.

Referenced by SimulatorFrontend::hasSimulationEnded(), SimulatorFrontend::isSimulationInitialized(), SimulatorFrontend::isSimulationRunning(), and SimulatorFrontend::isSimulationStopped().

◆ step()

virtual void TTASimulationController::step ( double  count = 1)
pure virtual

◆ stopReason()

StopReason TTASimulationController::stopReason ( unsigned int  index) const
virtual

Returns the stop reason with the given index.

Parameters
indexThe wanted index.
Returns
The stop reason at the given index.
Exceptions
OutOfRangeIf the given index is out of range.

Definition at line 113 of file TTASimulationController.cc.

113  {
114  if (index >= stopReasonCount()) {
115  throw OutOfRange(
116  __FILE__, __LINE__, __func__, "Stop reason index out of range.");
117  }
118  StopReasonContainer::const_iterator i = stopReasons_.begin();
119  unsigned int count = 0;
120  while (i != stopReasons_.end()) {
121  if (index == count) {
122  return (*i);
123  }
124  ++count;
125  ++i;
126  }
127  // dummy to stop compiler from warning
128  throw 0;
129 }

References __func__, stopReasonCount(), and stopReasons_.

Referenced by SimulatorFrontend::stopReason().

Here is the call graph for this function:

◆ stopReasonCount()

unsigned int TTASimulationController::stopReasonCount ( ) const
virtual

Returns the count of stop reasons.

Returns
The count of stop reasons.

Definition at line 101 of file TTASimulationController.cc.

101  {
102  return stopReasons_.size();
103 }

References stopReasons_.

Referenced by stopReason(), and SimulatorFrontend::stopReasonCount().

Member Data Documentation

◆ automaticFinishImpossible_

bool TTASimulationController::automaticFinishImpossible_
mutableprotected

If this is true, simulation cannot be finished automatically.

Definition at line 155 of file TTASimulationController.hh.

Referenced by automaticFinishImpossible(), and findProgramExitPoints().

◆ clockCount_

ClockCycleCount TTASimulationController::clockCount_
protected

◆ firstIllegalInstructionIndex_

InstructionAddress TTASimulationController::firstIllegalInstructionIndex_
mutableprotected

The index of the first illegal instruction in the instruction sequence.

Definition at line 158 of file TTASimulationController.hh.

Referenced by findProgramExitPoints(), OTASimulationController::simulateCycle(), and SimulationController::simulateCycle().

◆ frontend_

SimulatorFrontend& TTASimulationController::frontend_
protected

◆ initialPC_

InstructionAddress TTASimulationController::initialPC_
protected

The address of the first executed instruction.

Definition at line 153 of file TTASimulationController.hh.

Referenced by SimulationController::reset().

◆ lastExecutedInstruction_

std::vector<InstructionAddress> TTASimulationController::lastExecutedInstruction_
protected

The address of the last executed instruction.

Definition at line 151 of file TTASimulationController.hh.

Referenced by lastExecutedInstruction(), OTASimulationController::simulateCycle(), and SimulationController::simulateCycle().

◆ program_

const TTAProgram::Program& TTASimulationController::program_
protected

Program object model of the simulated program.

Definition at line 139 of file TTASimulationController.hh.

Referenced by RemoteController::loadIMemImage(), SimulationController::next(), CompiledSimController::program(), and CompiledSimController::reset().

◆ sourceMachine_

const TTAMachine::Machine& TTASimulationController::sourceMachine_
protected

◆ state_

SimulationStatus TTASimulationController::state_
protected

◆ stopReasons_

StopReasonContainer TTASimulationController::stopReasons_
protected

◆ stopRequested_

bool TTASimulationController::stopRequested_
protected

The documentation for this class was generated from the following files:
TTAProgram::CodeSnippet::firstInstruction
virtual Instruction & firstInstruction() const
Definition: CodeSnippet.cc:216
TTASimulationController::STA_STOPPED
@ STA_STOPPED
Simulation stopped for some reason.
Definition: TTASimulationController.hh:76
TTAProgram::Instruction::move
Move & move(int i) const
Definition: Instruction.cc:193
TTASimulationController::stopReasons_
StopReasonContainer stopReasons_
The set of reasons the simulation was stopped.
Definition: TTASimulationController.hh:144
TTAProgram::Address
Definition: Address.hh:51
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
TTAProgram::Move::isReturn
bool isReturn() const
Definition: Move.cc:259
TTAProgram::Instruction
Definition: Instruction.hh:57
OutOfRange
Definition: Exception.hh:320
TTAProgram::CodeSnippet::startAddress
virtual Address startAddress() const
Definition: CodeSnippet.cc:780
TTASimulationController::stopReasonCount
virtual unsigned int stopReasonCount() const
Definition: TTASimulationController.cc:101
TTASimulationController::automaticFinishImpossible_
bool automaticFinishImpossible_
If this is true, simulation cannot be finished automatically.
Definition: TTASimulationController.hh:155
TTASimulationController::initialPC_
InstructionAddress initialPC_
The address of the first executed instruction.
Definition: TTASimulationController.hh:153
SimulatorFrontend::selectedCore
int selectedCore() const
Definition: SimulatorFrontend.hh:257
TTASimulationController::STA_RUNNING
@ STA_RUNNING
A run command (run, stepi, until...) given.
Definition: TTASimulationController.hh:75
TTASimulationController::state_
SimulationStatus state_
The current state of the simulation.
Definition: TTASimulationController.hh:147
TTASimulationController::frontend_
SimulatorFrontend & frontend_
Reference to the simulator frontend.
Definition: TTASimulationController.hh:135
TTAMachine::Machine::controlUnit
virtual ControlUnit * controlUnit() const
Definition: Machine.cc:345
TTAProgram::CodeSnippet::instructionCount
virtual int instructionCount() const
Definition: CodeSnippet.cc:205
TTASimulationController::STA_INITIALIZED
@ STA_INITIALIZED
Simulation initialized and ready to run.
Definition: TTASimulationController.hh:74
TTASimulationController::STA_FINISHED
@ STA_FINISHED
Simulation ended after executing the last instruction.
Definition: TTASimulationController.hh:77
IllegalProgram
Definition: Exception.hh:895
TTASimulationController::sourceMachine_
const TTAMachine::Machine & sourceMachine_
The simulated Machine Object Model.
Definition: TTASimulationController.hh:137
__func__
#define __func__
Definition: Application.hh:67
TTASimulationController::lastExecutedInstruction_
std::vector< InstructionAddress > lastExecutedInstruction_
The address of the last executed instruction.
Definition: TTASimulationController.hh:151
TTASimulationController::stopRequested_
bool stopRequested_
Flag indicating that simulation should stop.
Definition: TTASimulationController.hh:142
TTAProgram::Address::location
InstructionAddress location() const
TTAProgram::Move
Definition: Move.hh:55
TTAMachine::ControlUnit::delaySlots
int delaySlots() const
TTASimulationController::STA_INITIALIZING
@ STA_INITIALIZING
Simulation is being initialized.
Definition: TTASimulationController.hh:73
TTASimulationController::frontend
virtual SimulatorFrontend & frontend()
Definition: TTASimulationController.cc:181
TTASimulationController::clockCount_
ClockCycleCount clockCount_
How many clock cycles have been simulated.
Definition: TTASimulationController.hh:149
TTASimulationController::firstIllegalInstructionIndex_
InstructionAddress firstIllegalInstructionIndex_
The index of the first illegal instruction in the instruction sequence.
Definition: TTASimulationController.hh:158
SimulatorFrontend::memorySystem
MemorySystem & memorySystem(int coreId=-1)
Definition: SimulatorFrontend.cc:2121
TTAProgram::Procedure::name
TCEString name() const
Definition: Procedure.hh:66
TTAProgram::CodeSnippet::endAddress
virtual Address endAddress() const
Definition: CodeSnippet.cc:788
TTAProgram::CodeSnippet::instructionAtIndex
virtual Instruction & instructionAtIndex(int index) const
Definition: CodeSnippet.cc:285
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
TTASimulationController::program_
const TTAProgram::Program & program_
Program object model of the simulated program.
Definition: TTASimulationController.hh:139
TTAProgram::Procedure
Definition: Procedure.hh:55
TTAProgram::Instruction::moveCount
int moveCount() const
Definition: Instruction.cc:176
TTAProgram::Instruction::address
Address address() const
Definition: Instruction.cc:327