OpenASIP  2.0
Public Member Functions | Private Attributes | List of all members
ProcedureTransferTracker Class Reference

#include <ProcedureTransferTracker.hh>

Inheritance diagram for ProcedureTransferTracker:
Inheritance graph
Collaboration diagram for ProcedureTransferTracker:
Collaboration graph

Public Member Functions

 ProcedureTransferTracker (SimulatorFrontend &subject, ExecutionTrace &traceDB)
 
 ProcedureTransferTracker (SimulatorFrontend &subject)
 
virtual ~ProcedureTransferTracker ()
 
virtual void handleEvent ()
 
virtual void addProcedureTransfer (ClockCycleCount cycle, InstructionAddress address, InstructionAddress sourceAddress, bool isEntry)
 
- Public Member Functions inherited from Listener
 Listener ()
 
virtual ~Listener ()
 
virtual void handleEvent (int event)
 

Private Attributes

SimulatorFrontendsubject_
 the tracked SimulatorFrontend instance More...
 
ExecutionTracetraceDB_
 the trace database to store the trace to More...
 
const TTAProgram::InstructionpreviousInstruction_
 the previously executed instruction More...
 

Detailed Description

Tracks procedure transfers in the simulated program.

Stores data of the transfer in trace database.

Definition at line 51 of file ProcedureTransferTracker.hh.

Constructor & Destructor Documentation

◆ ProcedureTransferTracker() [1/2]

ProcedureTransferTracker::ProcedureTransferTracker ( SimulatorFrontend subject,
ExecutionTrace traceDB 
)

Constructor for the default implementation of storing the transfers to a TraceDB.

Parameters
subjectThe SimulationController which is observed.
traceDBThe Execution Trace Database instance in which the trace is stored. Expects that the database is open for writing.

Definition at line 59 of file ProcedureTransferTracker.cc.

61  :
62  Listener(), subject_(subject), traceDB_(&traceDB),
63  previousInstruction_(NULL) {
66 }

References SimulatorFrontend::eventHandler(), Informer::registerListener(), and SimulationEventHandler::SE_CYCLE_END.

Here is the call graph for this function:

◆ ProcedureTransferTracker() [2/2]

ProcedureTransferTracker::ProcedureTransferTracker ( SimulatorFrontend subject)

Constructors for the derived implementations.

The implementation should override the addProcedureTransfer() to record the transfers as wished.

Definition at line 74 of file ProcedureTransferTracker.cc.

75  :
76  Listener(), subject_(subject), traceDB_(NULL),
77  previousInstruction_(NULL) {
80 }

References SimulatorFrontend::eventHandler(), Informer::registerListener(), and SimulationEventHandler::SE_CYCLE_END.

Here is the call graph for this function:

◆ ~ProcedureTransferTracker()

ProcedureTransferTracker::~ProcedureTransferTracker ( )
virtual

Destructor.

Definition at line 85 of file ProcedureTransferTracker.cc.

References SimulatorFrontend::eventHandler(), SimulationEventHandler::SE_CYCLE_END, subject_, and Informer::unregisterListener().

Here is the call graph for this function:

Member Function Documentation

◆ addProcedureTransfer()

void ProcedureTransferTracker::addProcedureTransfer ( ClockCycleCount  cycle,
InstructionAddress  address,
InstructionAddress  sourceAddress,
bool  isEntry 
)
virtual

This function is called to record a procedure transfer (call or return).

The default implementation stores the transfer to a TraceDB.

Reimplemented in CallPathTracker.

Definition at line 161 of file ProcedureTransferTracker.cc.

165  {
166 
167  if (traceDB_ == NULL)
168  return;
169 
170  try {
172  cycle, address, sourceAddress,
174  } catch (const Exception& e) {
175  debugLog("Error while writing TraceDB: " + e.errorMessage());
176  }
177 }

References ExecutionTrace::addProcedureTransfer(), debugLog, Exception::errorMessage(), ExecutionTrace::PT_ENTRY, ExecutionTrace::PT_EXIT, and traceDB_.

Referenced by handleEvent().

Here is the call graph for this function:

◆ handleEvent()

void ProcedureTransferTracker::handleEvent ( )
virtual

Stored procedure transfer data to execution database.

Last executed instruction is saved and its procedure is compared to the procedure of the current instruction. If they differ, a procedure transfer has happened and data of it is stored in trace database.

Reimplemented from Listener.

Definition at line 98 of file ProcedureTransferTracker.cc.

98  {
99 
100  InstructionAddress lastExecutedInstrAddr =
102  // the instruction that WAS executed in the current cycle (this handles
103  // clock cycle *end* events)
104  const TTAProgram::Instruction& currentInstruction =
105  subject_.program().instructionAt(lastExecutedInstrAddr);
106 
107  if (!currentInstruction.isInProcedure() ||
108  (previousInstruction_ != NULL && &(currentInstruction.parent()) ==
109  &(previousInstruction_->parent()))) {
110  // the instrution is not in a procedure (probably hand coded
111  // assembly program without procedure info), or there was no
112  // procedure transfer
113  previousInstruction_ = &currentInstruction;
114  return;
115  }
116 
117  bool entry = true;
118  // the address of the call or the return
119  InstructionAddress lastControlFlowInstructionAddress = 0;
120  // in case this is the first instruction, consider this a procedure
121  // entry (to the first procedure)
122  if (previousInstruction_ != NULL) {
123  // find the instruction which is responsible for the procedure
124  // change: it should be the instruction at the last executed
125  // instruction at the source procedure minus the count of delay
126  // slots
127  lastControlFlowInstructionAddress =
130  const TTAProgram::Instruction& lastControlFlowInstruction =
132  lastControlFlowInstructionAddress);
133 
134  // check if the instruction contains a move to gcu.jump.
135  // if there's no such a move, we'll assume it's a call
136  for (int i = 0; i < lastControlFlowInstruction.moveCount(); ++i) {
137 
138  TTAProgram::Move& lastMove = lastControlFlowInstruction.move(i);
139  if (dynamic_cast<TTAProgram::TerminalFUPort*>(
140  &lastMove.destination()) == 0) {
141  continue;
142  }
143  if (lastMove.destination().isOpcodeSetting() && lastMove.isJump()) {
144  entry = false;
145  break;
146  }
147  }
148  }
149  previousInstruction_ = &currentInstruction;
151  subject_.cycleCount(), lastExecutedInstrAddr,
152  lastControlFlowInstructionAddress, entry);
153 }

References addProcedureTransfer(), TTAProgram::Instruction::address(), TTAMachine::Machine::controlUnit(), SimulatorFrontend::cycleCount(), TTAMachine::ControlUnit::delaySlots(), TTAProgram::Move::destination(), TTAProgram::Program::instructionAt(), TTAProgram::Instruction::isInProcedure(), TTAProgram::Move::isJump(), TTAProgram::Terminal::isOpcodeSetting(), SimulatorFrontend::lastExecutedInstruction(), TTAProgram::Address::location(), SimulatorFrontend::machine(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), TTAProgram::Instruction::parent(), previousInstruction_, SimulatorFrontend::program(), and subject_.

Here is the call graph for this function:

Member Data Documentation

◆ previousInstruction_

const TTAProgram::Instruction* ProcedureTransferTracker::previousInstruction_
private

the previously executed instruction

Definition at line 75 of file ProcedureTransferTracker.hh.

Referenced by handleEvent().

◆ subject_

SimulatorFrontend& ProcedureTransferTracker::subject_
private

the tracked SimulatorFrontend instance

Definition at line 71 of file ProcedureTransferTracker.hh.

Referenced by handleEvent(), and ~ProcedureTransferTracker().

◆ traceDB_

ExecutionTrace* ProcedureTransferTracker::traceDB_
private

the trace database to store the trace to

Definition at line 73 of file ProcedureTransferTracker.hh.

Referenced by addProcedureTransfer().


The documentation for this class was generated from the following files:
ProcedureTransferTracker::previousInstruction_
const TTAProgram::Instruction * previousInstruction_
the previously executed instruction
Definition: ProcedureTransferTracker.hh:75
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
SimulatorFrontend::program
const TTAProgram::Program & program() const
Definition: SimulatorFrontend.cc:276
TTAProgram::Instruction::move
Move & move(int i) const
Definition: Instruction.cc:193
ProcedureTransferTracker::subject_
SimulatorFrontend & subject_
the tracked SimulatorFrontend instance
Definition: ProcedureTransferTracker.hh:71
ExecutionTrace::PT_EXIT
@ PT_EXIT
procedure exit
Definition: ExecutionTrace.hh:98
SimulatorFrontend::machine
const TTAMachine::Machine & machine() const
Definition: SimulatorFrontend.cc:263
TTAProgram::Instruction
Definition: Instruction.hh:57
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
ExecutionTrace::PT_ENTRY
@ PT_ENTRY
procedure entry
Definition: ExecutionTrace.hh:97
TTAProgram::Program::instructionAt
Instruction & instructionAt(InstructionAddress address) const
Definition: Program.cc:374
TTAMachine::Machine::controlUnit
virtual ControlUnit * controlUnit() const
Definition: Machine.cc:345
Informer::unregisterListener
virtual bool unregisterListener(int event, Listener *listener)
Definition: Informer.cc:104
SimulationEventHandler::SE_CYCLE_END
@ SE_CYCLE_END
Generated before advancing the simulator clock at the end of a simulation cycle.
Definition: SimulationEventHandler.hh:50
TTAProgram::Instruction::parent
CodeSnippet & parent() const
Definition: Instruction.cc:109
Informer::registerListener
virtual bool registerListener(int event, Listener *listener)
Definition: Informer.cc:87
TTAProgram::Address::location
InstructionAddress location() const
TTAProgram::Move
Definition: Move.hh:55
TTAMachine::ControlUnit::delaySlots
int delaySlots() const
Exception
Definition: Exception.hh:54
SimulatorFrontend::lastExecutedInstruction
virtual InstructionAddress lastExecutedInstruction(int coreId=-1) const
Definition: SimulatorFrontend.cc:1182
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
TTAProgram::Terminal::isOpcodeSetting
virtual bool isOpcodeSetting() const
Definition: Terminal.cc:285
TTAProgram::TerminalFUPort
Definition: TerminalFUPort.hh:56
TTAProgram::Instruction::isInProcedure
bool isInProcedure() const
Definition: Instruction.cc:135
SimulatorFrontend::cycleCount
ClockCycleCount cycleCount() const
Definition: SimulatorFrontend.cc:1194
SimulatorFrontend::eventHandler
SimulationEventHandler & eventHandler()
Definition: SimulatorFrontend.cc:2260
Listener::Listener
Listener()
Definition: Listener.cc:40
ExecutionTrace::addProcedureTransfer
void addProcedureTransfer(ClockCycleCount cycle, InstructionAddress address, InstructionAddress sourceAddress, ProcedureEntryType type)
Definition: ExecutionTrace.cc:575
ProcedureTransferTracker::traceDB_
ExecutionTrace * traceDB_
the trace database to store the trace to
Definition: ProcedureTransferTracker.hh:73
TTAProgram::Move::isJump
bool isJump() const
Definition: Move.cc:164
debugLog
#define debugLog(text)
Definition: Application.hh:95
ProcedureTransferTracker::addProcedureTransfer
virtual void addProcedureTransfer(ClockCycleCount cycle, InstructionAddress address, InstructionAddress sourceAddress, bool isEntry)
Definition: ProcedureTransferTracker.cc:161
TTAProgram::Instruction::moveCount
int moveCount() const
Definition: Instruction.cc:176
TTAProgram::Instruction::address
Address address() const
Definition: Instruction.cc:327