OpenASIP  2.0
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 
101  delete simFront_;
102 }
103 
104 void
107  simFront_->step();
108 }
109 
110 void
112  simFront_->run();
113 }
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  */
121 void
124 }
125 
126 void
127 SimpleSimulatorFrontend::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  */
135 bool
138 }
139 
140 /**
141  * Retruns true in case the engine has been initialized and is
142  * ready to be stepped.
143  */
144 bool
146  return simFront_->isSimulationStopped();
147 }
148 
149 bool
151  return simFront_->isSimulationRunning();
152 }
153 
154 bool
156  return simFront_->hasSimulationEnded();
157 }
158 
159 bool
161  return simFront_->stopReasonCount() >= 1 &&
163 }
164 
165 const TTAMachine::Machine&
167  return simFront_->machine();
168 }
169 
170 const TTAProgram::Program&
172  return simFront_->program();
173 }
174 
177  return simFront_->memorySystem();
178 }
179 
180 /**
181  * Replaces all operation executors in the given FU with the
182  * given one.
183  */
184 void
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 
200 bool
202  return simFront_->eventHandler().registerListener(event, listener);
203 }
204 
205 bool
207  int event, Listener* listener) {
208  return simFront_->eventHandler().unregisterListener(event, listener);
209 }
210 
211 uint64_t
213  return simFront_->cycleCount();
214 }
215 
216 void
218  const TTAMachine::AddressSpace* onlyOne) {
220 }
TTAProgram::Program
Definition: Program.hh:63
Exception::procedureName
std::string procedureName() const
SimpleSimulatorFrontend::stop
void stop()
Definition: SimpleSimulatorFrontend.cc:122
Exception::lineNum
int lineNum() const
SimulatorFrontend::program
const TTAProgram::Program & program() const
Definition: SimulatorFrontend.cc:276
SimulatorFrontend::SIM_COMPILED
@ SIM_COMPILED
Compiled, faster simulation.
Definition: SimulatorFrontend.hh:103
DetailedOperationSimulator.hh
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
TTAMachine::AddressSpace
Definition: AddressSpace.hh:51
SimpleSimulatorFrontend::isInitialized
bool isInitialized() const
Definition: SimpleSimulatorFrontend.cc:136
SRE_USER_REQUESTED
@ SRE_USER_REQUESTED
User requested the simulation to stop explicitly, e.g., by pressing ctrl-c in the CLI.
Definition: SimulatorConstants.hh:66
SimulatorFrontend::machine
const TTAMachine::Machine & machine() const
Definition: SimulatorFrontend.cc:263
Listener
Definition: Listener.hh:40
SimulatorFrontend::isSimulationStopped
bool isSimulationStopped() const
Definition: SimulatorFrontend.cc:1271
SimpleSimulatorFrontend::run
void run()
Definition: SimpleSimulatorFrontend.cc:111
DetailedOperationSimulator
Definition: DetailedOperationSimulator.hh:49
SimulatorFrontend::initializeDataMemories
void initializeDataMemories(const TTAMachine::AddressSpace *onlyOne=NULL)
Definition: SimulatorFrontend.cc:440
SimulatorFrontend::run
virtual void run()
Definition: SimulatorFrontend.cc:997
SimpleSimulatorFrontend::memorySystem
MemorySystem & memorySystem()
Definition: SimpleSimulatorFrontend.cc:176
SimpleSimulatorFrontend::simFront_
SimulatorFrontend * simFront_
Definition: SimpleSimulatorFrontend.hh:99
SimulatorFrontend::stopReasonCount
unsigned int stopReasonCount() const
Definition: SimulatorFrontend.cc:1344
SimpleSimulatorFrontend.hh
Exception::fileName
std::string fileName() const
SimulatorFrontend::loadMachine
virtual void loadMachine(const std::string &fileName)
Definition: SimulatorFrontend.cc:534
SimulationEventHandler.hh
SimpleSimulatorFrontend::machine
const TTAMachine::Machine & machine() const
Definition: SimpleSimulatorFrontend.cc:166
SimpleSimulatorFrontend::cycleCount
uint64_t cycleCount() const
Definition: SimpleSimulatorFrontend.cc:212
Informer::unregisterListener
virtual bool unregisterListener(int event, Listener *listener)
Definition: Informer.cc:104
SimpleSimulatorFrontend::isFinished
bool isFinished() const
Definition: SimpleSimulatorFrontend.cc:155
Informer::registerListener
virtual bool registerListener(int event, Listener *listener)
Definition: Informer.cc:87
SimulatorFrontend::loadProgram
virtual void loadProgram(const std::string &fileName)
Definition: SimulatorFrontend.cc:299
SRE_RUNTIME_ERROR
@ SRE_RUNTIME_ERROR
A fatal runtime error occured in the simulated program.
Definition: SimulatorConstants.hh:68
SimpleSimulatorFrontend::unregisterEventListener
virtual bool unregisterEventListener(int event, Listener *listener)
Definition: SimpleSimulatorFrontend.cc:206
Exception
Definition: Exception.hh:54
MemorySystem
Definition: MemorySystem.hh:55
SimulatorFrontend.hh
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
SimpleSimulatorFrontend::registerEventListener
virtual bool registerEventListener(int event, Listener *listener)
Definition: SimpleSimulatorFrontend.cc:201
SimulatorFrontend::isSimulationRunning
bool isSimulationRunning() const
Definition: SimulatorFrontend.cc:1260
SimpleSimulatorFrontend::isStopped
bool isStopped() const
Definition: SimpleSimulatorFrontend.cc:145
SimulatorFrontend::cycleCount
ClockCycleCount cycleCount() const
Definition: SimulatorFrontend.cc:1194
SimulatorFrontend::step
virtual void step(double count=1)
Definition: SimulatorFrontend.cc:1034
SimulatorFrontend::memorySystem
MemorySystem & memorySystem(int coreId=-1)
Definition: SimulatorFrontend.cc:2121
SimulatorFrontend::eventHandler
SimulationEventHandler & eventHandler()
Definition: SimulatorFrontend.cc:2260
SimpleSimulatorFrontend::isRunning
bool isRunning() const
Definition: SimpleSimulatorFrontend.cc:150
SimulatorFrontend::machineState
MachineState & machineState(int core=-1)
Definition: SimulatorFrontend.cc:2138
MachineState::fuState
FUState & fuState(const std::string &name)
Definition: MachineState.cc:133
SimpleSimulatorFrontend::loadProgram
void loadProgram(const std::string &fileName)
Definition: SimpleSimulatorFrontend.cc:127
TCEString
Definition: TCEString.hh:53
SimulatorFrontend::setZeroFillMemoriesOnReset
void setZeroFillMemoriesOnReset(bool val)
Definition: SimulatorFrontend.hh:235
SimulatorFrontend::setDetailedSimulation
void setDetailedSimulation(bool val)
Definition: SimulatorFrontend.hh:238
MachineState.hh
SimpleSimulatorFrontend::hadRuntimeError
bool hadRuntimeError() const
Definition: SimpleSimulatorFrontend.cc:160
SimulatorFrontend::stopReason
StopReason stopReason(unsigned int index) const
Definition: SimulatorFrontend.cc:1356
SimpleSimulatorFrontend::~SimpleSimulatorFrontend
virtual ~SimpleSimulatorFrontend()
Definition: SimpleSimulatorFrontend.cc:100
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
SimulatorFrontend::hasSimulationEnded
bool hasSimulationEnded() const
Definition: SimulatorFrontend.cc:1283
SimulatorFrontend
Definition: SimulatorFrontend.hh:89
SimpleSimulatorFrontend::program
const TTAProgram::Program & program() const
Definition: SimpleSimulatorFrontend.cc:171
SimpleSimulatorFrontend::initializeDataMemories
void initializeDataMemories(const TTAMachine::AddressSpace *onlyOne=NULL)
Definition: SimpleSimulatorFrontend.cc:217
SimulatorFrontend::isSimulationInitialized
bool isSimulationInitialized() const
Definition: SimulatorFrontend.cc:1228
SimpleSimulatorFrontend::step
void step()
Definition: SimpleSimulatorFrontend.cc:105
SimpleSimulatorFrontend::SimpleSimulatorFrontend
SimpleSimulatorFrontend(TCEString machineFile, bool useCompiledSimulation=false)
Definition: SimpleSimulatorFrontend.cc:38
SimpleSimulatorFrontend::setOperationSimulator
virtual void setOperationSimulator(const TCEString &fuName, DetailedOperationSimulator &sim)
Definition: SimpleSimulatorFrontend.cc:185
TTAMachine::Machine
Definition: Machine.hh:73
SimulatorFrontend::prepareToStop
void prepareToStop(StopReason reason)
Definition: SimulatorFrontend.cc:1331
Listener.hh
SimulatorFrontend::SIM_NORMAL
@ SIM_NORMAL
Default, interpreted simulation (debugging engine).
Definition: SimulatorFrontend.hh:102