OpenASIP 2.2
Loading...
Searching...
No Matches
SimpleSimulatorFrontend.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2012 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 SimpleSimulatorFrontend.cc
26 *
27 * Implementation of SimpleSimulatorFrontend class.
28 *
29 * @author Pekka Jääskeläinen 2010,2012 (pjaaskel-no.spam-cs.tut.fi)
30 */
32#include "SimulatorFrontend.hh"
33#include "MachineState.hh"
35#include "Listener.hh"
37
39 TCEString machineFile, bool useCompiledSimulation) {
40 simFront_ =
42 useCompiledSimulation ?
46 try {
47 simFront_->loadMachine(machineFile);
48 } catch (Exception& e) {
49 std::cerr
50 << e.errorMessage() + " in " +
51 e.fileName() + ":" +
52 e.procedureName() + ":"
53 << e.lineNum() << std::endl;
54 abort();
55 }
56}
57
59 TCEString machineFile, TCEString programFile,
60 bool useCompiledSimulation, bool useDetailedSimulation) {
61 simFront_ =
63 useCompiledSimulation ?
67 simFront_->setDetailedSimulation(useDetailedSimulation);
68 try {
69 simFront_->loadMachine(machineFile);
70 simFront_->loadProgram(programFile);
71 } catch (Exception& e) {
72 std::cerr
73 << e.errorMessage() + " in " +
74 e.fileName() + ":" +
75 e.procedureName() + ":"
76 << e.lineNum() << std::endl;
77 abort();
78 }
79}
80
86 try {
89 } catch (Exception& e) {
90 std::cerr
91 << e.errorMessage() + " in " +
92 e.fileName() + ":" +
93 e.procedureName() + ":"
94 << e.lineNum() << std::endl;
95 abort();
96 }
97
98}
99
103
104void
109
110void
114
115/**
116 * Stops the current simulation.
117 *
118 * This produces the same kind of stop as if the user pressed ctrl-c in
119 * the ttasim.
120 */
121void
125
126void
127SimpleSimulatorFrontend::loadProgram(const std::string& fileName) {
128 simFront_->loadProgram(fileName);
129}
130
131/**
132 * Returns true in case the engine has the machine and the program
133 * loaded and is ready to execute, but has not been executed yet.
134 */
135bool
139
140/**
141 * Retruns true in case the engine has been initialized and is
142 * ready to be stepped.
143 */
144bool
148
149bool
153
154bool
158
159bool
164
169
174
179
180/**
181 * Replaces all operation executors in the given FU with the
182 * given one.
183 */
184void
186 const TCEString& fuName, DetailedOperationSimulator& sim) {
187 try {
188 simFront_->machineState().fuState(fuName).
190 } catch (Exception& e) {
191 std::cerr
192 << e.errorMessage() + " in " +
193 e.fileName() + ":" +
194 e.procedureName() + ":"
195 << e.lineNum() << std::endl;
196 abort();
197 }
198}
199
200bool
202 return simFront_->eventHandler().registerListener(event, listener);
203}
204
205bool
207 int event, Listener* listener) {
208 return simFront_->eventHandler().unregisterListener(event, listener);
209}
210
211uint64_t
215
216void
TTAMachine::Machine * machine
the architecture definition of the estimated processor
find Finds info of the inner loops in the program
@ SRE_USER_REQUESTED
User requested the simulation to stop explicitly, e.g., by pressing ctrl-c in the CLI.
@ SRE_RUNTIME_ERROR
A fatal runtime error occured in the simulated program.
std::string fileName() const
std::string errorMessage() const
Definition Exception.cc:123
std::string procedureName() const
int lineNum() const
virtual bool unregisterListener(int event, Listener *listener)
Definition Informer.cc:104
virtual bool registerListener(int event, Listener *listener)
Definition Informer.cc:87
FUState & fuState(const std::string &name)
const TTAMachine::Machine & machine() const
SimpleSimulatorFrontend(TCEString machineFile, bool useCompiledSimulation=false)
virtual bool registerEventListener(int event, Listener *listener)
void loadProgram(const std::string &fileName)
const TTAProgram::Program & program() const
virtual void setOperationSimulator(const TCEString &fuName, DetailedOperationSimulator &sim)
virtual bool unregisterEventListener(int event, Listener *listener)
void initializeDataMemories(const TTAMachine::AddressSpace *onlyOne=NULL)
bool hasSimulationEnded() const
void initializeDataMemories(const TTAMachine::AddressSpace *onlyOne=NULL)
SimulationEventHandler & eventHandler()
@ SIM_COMPILED
Compiled, faster simulation.
@ SIM_NORMAL
Default, interpreted simulation (debugging engine).
virtual void loadMachine(const std::string &fileName)
const TTAMachine::Machine & machine() const
void setDetailedSimulation(bool val)
ClockCycleCount cycleCount() const
bool isSimulationInitialized() const
unsigned int stopReasonCount() const
MachineState & machineState(int core=-1)
StopReason stopReason(unsigned int index) const
bool isSimulationStopped() const
const TTAProgram::Program & program() const
void setZeroFillMemoriesOnReset(bool val)
virtual void loadProgram(const std::string &fileName)
virtual void step(double count=1)
bool isSimulationRunning() const
MemorySystem & memorySystem(int coreId=-1)
void prepareToStop(StopReason reason)