OpenASIP 2.2
Loading...
Searching...
No Matches
Classes | Functions
TTASim.cc File Reference
#include <string>
#include <iostream>
#include <boost/shared_ptr.hpp>
#include "SimulatorCmdLineOptions.hh"
#include "SimulatorFrontend.hh"
#include "FileSystem.hh"
#include "SimulatorInterpreter.hh"
#include "SimulatorCLI.hh"
#include "SimulatorToolbox.hh"
Include dependency graph for TTASim.cc:

Go to the source code of this file.

Classes

class  SigINTHandler
 
class  SigFPEHandler
 
class  SigSegvHandler
 

Functions

int main (int argc, char *argv[])
 

Detailed Description

Implementation of ttasim.

The command line version of the TTA Simulator / Debugger

Author
Pekka Jääskeläinen 2005-2012 (pjaaskel-no.spam-cs.tut.fi)
Note
rating: red

Definition in file TTASim.cc.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main function.

Parses the command line and figures out whether to start the interactive debugging mode or not.

Parameters
argcThe command line argument count.
argvThe command line arguments (passed to the interpreter).
Returns
The return status.
Todo:
: read command line options and initialize the simulator (frontend) using the given values.

Definition at line 172 of file TTASim.cc.

172 {
173
174 Application::initialize(argc, argv);
175
176 boost::shared_ptr<SimulatorFrontend> simFront;
177 /// @todo: read command line options and initialize the
178 /// simulator (frontend) using the given values.
180 try {
181 options->parse(argv, argc);
183 } catch (ParserStopRequest const&) {
184 return EXIT_SUCCESS;
185 } catch (const IllegalCommandLine& i) {
186 std::cerr << i.errorMessage() << std::endl;
187 return EXIT_FAILURE;
188 }
189
190 simFront.reset(new SimulatorFrontend(options->backendType()));
191
192 SimulatorCLI* cli = new SimulatorCLI(*simFront);
193
194 if (options->debugMode()) {
195 // handler for catching ctrl-c from the user (stops simulation)
196 SigINTHandler* ctrlcHandler = new SigINTHandler(*simFront);
197 Application::setSignalHandler(SIGINT, *ctrlcHandler);
198
199 if (simFront->isCompiledSimulation()) {
200
201 /* Catch errors caused by the simulated program
202 in compiled simulation these show up as normal
203 signals as the simulation code is native code we are
204 running in the simulation process. */
205 SigFPEHandler fpeHandler(*simFront);
206 SigSegvHandler segvHandler(*simFront);
207 Application::setSignalHandler(SIGFPE, fpeHandler);
208 Application::setSignalHandler(SIGSEGV, segvHandler);
209 }
210 }
211
212 // check if there is an initialization file in user's home dir and
213 // execute it
214 const std::string personalInitScript =
216 if (FileSystem::fileExists(personalInitScript)) {
217 cli->interpreter().processScriptFile(personalInitScript);
218 }
219
220 std::string machineToLoad = options->machineFile();
221 std::string programToLoad = options->programFile();
222 const std::string scriptString = options->scriptString();
223
224 if (options->numberOfArguments() != 0) {
226 Texts::TXT_ILLEGAL_ARGUMENTS).str() << std::endl;
227 return EXIT_FAILURE;
228 }
229
230 // check if there is an initialization file in the current dir and
231 // execute it
232 const std::string currentDirInitScript =
234 if (FileSystem::fileExists(currentDirInitScript)) {
235 cli->interpreter().processScriptFile(currentDirInitScript);
236 }
237
238 if (machineToLoad != "") {
239 cli->interpreteAndPrintResults(std::string("mach " ) + machineToLoad);
240 }
241
242 if (programToLoad != "") {
243 cli->interpreteAndPrintResults(std::string("prog " ) + programToLoad);
244 if (scriptString == "") {
245 // by default, if program is given, start simulation immediately
246 cli->interpreteAndPrintResults("run");
247 }
248 }
249
250 if (scriptString != "") {
251 cli->interpreteAndPrintResults(scriptString);
252 }
253
254
255 if (options->debugMode()) {
256 cli->run();
258 if (simFront->isCompiledSimulation()) {
261 }
262 }
263 delete cli;
264 return EXIT_SUCCESS;
265}
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
#define SIM_INIT_FILE_NAME
The initialization script file name.
static void setCmdLineOptions(CmdLineOptions *options_)
static void setSignalHandler(int signalNum, UnixSignalHandler &handler)
static void restoreSignalHandler(int signalNum)
static void initialize()
void parse(char *argv[], int argc)
virtual int numberOfArguments() const
std::string errorMessage() const
Definition Exception.cc:123
static std::string homeDirectory()
static std::string currentWorkingDir()
static bool fileExists(const std::string fileName)
virtual void run()
virtual void interpreteAndPrintResults(const TCEString &scriptString)
SimulatorInterpreter & interpreter()
static SimulatorTextGenerator & textGenerator()
virtual bool processScriptFile(const std::string &scriptFileName)
virtual boost::format text(int textId)
@ TXT_ILLEGAL_ARGUMENTS

References FileSystem::currentWorkingDir(), Exception::errorMessage(), FileSystem::fileExists(), FileSystem::homeDirectory(), Application::initialize(), SimulatorCLI::interpreteAndPrintResults(), SimulatorCLI::interpreter(), CmdLineParser::numberOfArguments(), options, CmdLineOptions::parse(), TclInterpreter::processScriptFile(), Application::restoreSignalHandler(), SimulatorCLI::run(), Application::setCmdLineOptions(), Application::setSignalHandler(), SIM_INIT_FILE_NAME, Texts::TextGenerator::text(), SimulatorToolbox::textGenerator(), and Texts::TXT_ILLEGAL_ARGUMENTS.

Here is the call graph for this function: