OpenASIP 2.2
Loading...
Searching...
No Matches
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
 
ExecutionTracetraceDB_
 the trace database to store the trace to
 
const TTAProgram::InstructionpreviousInstruction_
 the previously executed instruction
 

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),
66}
virtual bool registerListener(int event, Listener *listener)
Definition Informer.cc:87
ExecutionTrace * traceDB_
the trace database to store the trace to
const TTAProgram::Instruction * previousInstruction_
the previously executed instruction
SimulatorFrontend & subject_
the tracked SimulatorFrontend instance
@ SE_CYCLE_END
Generated before advancing the simulator clock at the end of a simulation cycle.
SimulationEventHandler & eventHandler()

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),
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.

85 {
88}
virtual bool unregisterListener(int event, Listener *listener)
Definition Informer.cc:104

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,
173 isEntry? ExecutionTrace::PT_ENTRY : ExecutionTrace::PT_EXIT);
174 } catch (const Exception& e) {
175 debugLog("Error while writing TraceDB: " + e.errorMessage());
176 }
177}
#define debugLog(text)
std::string errorMessage() const
Definition Exception.cc:123
@ PT_ENTRY
procedure entry
void addProcedureTransfer(ClockCycleCount cycle, InstructionAddress address, InstructionAddress sourceAddress, ProcedureEntryType type)

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()) ==
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}
UInt32 InstructionAddress
Definition BaseType.hh:175
virtual void addProcedureTransfer(ClockCycleCount cycle, InstructionAddress address, InstructionAddress sourceAddress, bool isEntry)
const TTAMachine::Machine & machine() const
ClockCycleCount cycleCount() const
virtual InstructionAddress lastExecutedInstruction(int coreId=-1) const
const TTAProgram::Program & program() const
virtual ControlUnit * controlUnit() const
Definition Machine.cc:345
InstructionAddress location() const
Move & move(int i) const
Address address() const
CodeSnippet & parent() const
bool isJump() const
Definition Move.cc:164
Terminal & destination() const
Definition Move.cc:323
Instruction & instructionAt(InstructionAddress address) const
Definition Program.cc:374
virtual bool isOpcodeSetting() const
Definition Terminal.cc:285

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: