OpenASIP 2.2
Loading...
Searching...
No Matches
ProcedureTransferTracker.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file ProcedureTransferTracker.cc
26 *
27 * Definition of ProcedureTransferTracker class.
28 *
29 * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
34#include "ExecutionTrace.hh"
35#include "Application.hh"
36#include "SimulatorFrontend.hh"
37#include "SimulatorToolbox.hh"
39#include "Instruction.hh"
40#include "ControlUnit.hh"
41#include "Move.hh"
42#include "Terminal.hh"
43#include "TerminalFUPort.hh"
45#include "StringTools.hh"
46#include "Operation.hh"
47#include "Machine.hh"
48#include "Program.hh"
49
50/**
51 * Constructor for the default implementation of storing the transfers
52 * to a TraceDB.
53 *
54 * @param subject The SimulationController which is observed.
55 * @param traceDB The Execution Trace Database instance in which the
56 * trace is stored. Expects that the database is open
57 * for writing.
58 */
60 SimulatorFrontend& subject,
61 ExecutionTrace& traceDB) :
62 Listener(), subject_(subject), traceDB_(&traceDB),
63 previousInstruction_(NULL) {
66}
67
68/**
69 * Constructors for the derived implementations.
70 *
71 * The implementation should override the addProcedureTransfer() to
72 * record the transfers as wished.
73 */
75 SimulatorFrontend& subject) :
76 Listener(), subject_(subject), traceDB_(NULL),
77 previousInstruction_(NULL) {
80}
81
82/**
83 * Destructor.
84 */
89
90/**
91 * Stored procedure transfer data to execution database.
92 *
93 * Last executed instruction is saved and its procedure is compared to the
94 * procedure of the current instruction. If they differ, a procedure transfer
95 * has happened and data of it is stored in trace database.
96 */
97void
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}
154
155/**
156 * This function is called to record a procedure transfer (call or return).
157 *
158 * The default implementation stores the transfer to a TraceDB.
159 */
160void
162 ClockCycleCount cycle,
163 InstructionAddress address,
164 InstructionAddress sourceAddress,
165 bool isEntry) {
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}
178
#define debugLog(text)
UInt32 InstructionAddress
Definition BaseType.hh:175
CycleCount ClockCycleCount
Alias for ClockCycleCount.
std::string errorMessage() const
Definition Exception.cc:123
@ PT_EXIT
procedure exit
@ PT_ENTRY
procedure entry
void addProcedureTransfer(ClockCycleCount cycle, InstructionAddress address, InstructionAddress sourceAddress, ProcedureEntryType type)
virtual bool unregisterListener(int event, Listener *listener)
Definition Informer.cc:104
virtual bool registerListener(int event, Listener *listener)
Definition Informer.cc:87
ProcedureTransferTracker(SimulatorFrontend &subject, ExecutionTrace &traceDB)
ExecutionTrace * traceDB_
the trace database to store the trace to
virtual void addProcedureTransfer(ClockCycleCount cycle, InstructionAddress address, InstructionAddress sourceAddress, bool isEntry)
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()
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