OpenASIP  2.0
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) {
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 =
215  FileSystem::homeDirectory() + DIR_SEPARATOR + SIM_INIT_FILE_NAME;
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) {
225  std::cerr << SimulatorToolbox::textGenerator().text(
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 }

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:
SigINTHandler
Definition: TTASim.cc:51
SigSegvHandler
Definition: TTASim.cc:133
ParserStopRequest
Definition: Exception.hh:491
CmdLineParser::numberOfArguments
virtual int numberOfArguments() const
Application::restoreSignalHandler
static void restoreSignalHandler(int signalNum)
Definition: Application.cc:471
SimulatorCmdLineOptions
Definition: SimulatorCmdLineOptions.hh:45
SIM_INIT_FILE_NAME
#define SIM_INIT_FILE_NAME
The initialization script file name.
Definition: SimulatorConstants.hh:48
Application::setCmdLineOptions
static void setCmdLineOptions(CmdLineOptions *options_)
Definition: Application.cc:381
IllegalCommandLine
Definition: Exception.hh:438
Application::setSignalHandler
static void setSignalHandler(int signalNum, UnixSignalHandler &handler)
Definition: Application.cc:417
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
FileSystem::homeDirectory
static std::string homeDirectory()
SimulatorCLI::run
virtual void run()
Definition: SimulatorCLI.cc:189
SigFPEHandler
Definition: TTASim.cc:79
Texts::TXT_ILLEGAL_ARGUMENTS
@ TXT_ILLEGAL_ARGUMENTS
Definition: TextGenerator.hh:67
SimulatorToolbox::textGenerator
static SimulatorTextGenerator & textGenerator()
Definition: SimulatorToolbox.cc:75
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
CmdLineOptions::parse
void parse(char *argv[], int argc)
Definition: CmdLineOptions.cc:107
SimulatorCLI::interpreter
SimulatorInterpreter & interpreter()
Definition: SimulatorCLI.hh:58
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
FileSystem::fileExists
static bool fileExists(const std::string fileName)
Application::initialize
static void initialize()
Definition: Application.cc:99
FileSystem::currentWorkingDir
static std::string currentWorkingDir()
Definition: FileSystem.cc:142
SimulatorCLI
Definition: SimulatorCLI.hh:48
SimulatorFrontend
Definition: SimulatorFrontend.hh:89
SimulatorCLI::interpreteAndPrintResults
virtual void interpreteAndPrintResults(const TCEString &scriptString)
Definition: SimulatorCLI.cc:176
TclInterpreter::processScriptFile
virtual bool processScriptFile(const std::string &scriptFileName)
Definition: TclInterpreter.cc:250