OpenASIP  2.0
Public Member Functions | Protected Attributes | List of all members
SimulatorCLI Class Reference

#include <SimulatorCLI.hh>

Inheritance diagram for SimulatorCLI:
Inheritance graph
Collaboration diagram for SimulatorCLI:
Collaboration graph

Public Member Functions

 SimulatorCLI ()=delete
 
 SimulatorCLI (SimulatorFrontend &frontend)
 
virtual ~SimulatorCLI ()
 
virtual void run ()
 
virtual void interpreteAndPrintResults (const TCEString &scriptString)
 
SimulatorInterpreterinterpreter ()
 

Protected Attributes

SimulatorFrontendsimFront_
 
SimulatorInterpreterContextcontext_
 
LineReaderreader_
 
SimulatorInterpreterinterpreter_
 
SimulatorCmdLineOptionsoptions_
 
RuntimeErrorReportererrorReporter_
 

Detailed Description

Command Line Interface for controlling the simulation engine using the simulator control scripting language (tcl).

Definition at line 48 of file SimulatorCLI.hh.

Constructor & Destructor Documentation

◆ SimulatorCLI() [1/2]

SimulatorCLI::SimulatorCLI ( )
delete

◆ SimulatorCLI() [2/2]

SimulatorCLI::SimulatorCLI ( SimulatorFrontend frontend)
Parameters
simulatorInterpreterUse the given interpreter instead of default one. Takes ownership of the object.

Catch runtime errors and print them out to the simulator console.

Definition at line 121 of file SimulatorCLI.cc.

121  :
122  simFront_(frontend),
123  context_(new SimulatorInterpreterContext(frontend)),
125 
126  assert(reader_ != NULL);
127 
130 
131  options_ = NULL;
132  if (Application::cmdLineOptions() != NULL) {
133  options_ = dynamic_cast<SimulatorCmdLineOptions*>(
135  }
136 
137  if (frontend.isCompiledSimulation()) {
138  interpreter_ =
141  *context_, *reader_);
142  } else {
143  interpreter_ =
146  *context_, *reader_);
147  }
148 
149  /// Catch runtime errors and print them out to the simulator console.
151 }

References Application::argc(), Application::argv(), assert, Application::cmdLineOptions(), context_, errorReporter_, LineReader::initialize(), interpreter_, SimulatorFrontend::isCompiledSimulation(), options_, reader_, LineReader::setInputHistoryLog(), SIM_COMMAND_PROMPT, SIM_DEFAULT_COMMAND_LOG, and simFront_.

Here is the call graph for this function:

◆ ~SimulatorCLI()

SimulatorCLI::~SimulatorCLI ( )
virtual

Definition at line 153 of file SimulatorCLI.cc.

153  {
154 
155  delete reader_;
156  reader_ = NULL;
157 
158  delete interpreter_;
159  interpreter_ = NULL;
160 
161  delete context_;
162  context_ = NULL;
163 
164  delete errorReporter_;
165  errorReporter_ = NULL;
166 }

References context_, errorReporter_, interpreter_, and reader_.

Member Function Documentation

◆ interpreteAndPrintResults()

void SimulatorCLI::interpreteAndPrintResults ( const TCEString scriptString)
virtual

Executes the given script string in the script interpreter and prints out possible results.

Parameters
interpreterInterpreter to use.
scriptStringScript string to execute.

Definition at line 176 of file SimulatorCLI.cc.

176  {
177  interpreter_->interpret(scriptString);
178  if (interpreter_->result().size() > 0)
179  std::cout << interpreter_->result() << std::endl;
180 }

References TclInterpreter::interpret(), interpreter_, and ScriptInterpreter::result().

Referenced by main().

Here is the call graph for this function:

◆ interpreter()

SimulatorInterpreter& SimulatorCLI::interpreter ( )
inline

Definition at line 58 of file SimulatorCLI.hh.

58 { return *interpreter_; }

References interpreter_.

Referenced by main().

◆ run()

void SimulatorCLI::run ( )
virtual

Runs the interpreter loop.

Inputs a line of script from the user, processes it and prints out the results.

Definition at line 189 of file SimulatorCLI.cc.

189  {
190 
191  while (!interpreter_->isQuitCommandGiven()) {
192  std::string command = "";
193  try {
194  command = reader_->readLine();
195  } catch (const EndOfFile&) {
196  // execute the actual interpreter quit command in case user
197  // pressed ctrl-d or the input file ended, to make sure
198  // all uninitialization routines are executed correctly
200  std::cout << interpreter_->result() << std::endl;
201  break;
202  }
203  command = StringTools::trim(command);
204  if (command == "") {
205  continue;
206  }
207  interpreter_->interpret(command);
208  if (interpreter_->result().size() > 0)
209  std::cout << interpreter_->result() << std::endl;
210  }
211 }

References TclInterpreter::interpret(), interpreter_, SimulatorInterpreter::isQuitCommandGiven(), reader_, LineReader::readLine(), ScriptInterpreter::result(), SIM_INTERP_QUIT_COMMAND, and StringTools::trim().

Referenced by main().

Here is the call graph for this function:

Member Data Documentation

◆ context_

SimulatorInterpreterContext* SimulatorCLI::context_
protected

Definition at line 61 of file SimulatorCLI.hh.

Referenced by SimulatorCLI(), and ~SimulatorCLI().

◆ errorReporter_

RuntimeErrorReporter* SimulatorCLI::errorReporter_
protected

Definition at line 65 of file SimulatorCLI.hh.

Referenced by SimulatorCLI(), and ~SimulatorCLI().

◆ interpreter_

SimulatorInterpreter* SimulatorCLI::interpreter_
protected

◆ options_

SimulatorCmdLineOptions* SimulatorCLI::options_
protected

Definition at line 64 of file SimulatorCLI.hh.

Referenced by SimulatorCLI().

◆ reader_

LineReader* SimulatorCLI::reader_
protected

Definition at line 62 of file SimulatorCLI.hh.

Referenced by run(), SimulatorCLI(), and ~SimulatorCLI().

◆ simFront_

SimulatorFrontend& SimulatorCLI::simFront_
protected

Definition at line 60 of file SimulatorCLI.hh.

Referenced by SimulatorCLI().


The documentation for this class was generated from the following files:
CompiledSimInterpreter
Definition: CompiledSimInterpreter.hh:42
LineReaderFactory::lineReader
static LineReader * lineReader()
Definition: LineReaderFactory.cc:54
SimulatorInterpreterContext
Definition: SimulatorInterpreterContext.hh:45
ScriptInterpreter::result
virtual std::string result()
Definition: ScriptInterpreter.cc:191
SimulatorCLI::interpreter_
SimulatorInterpreter * interpreter_
Definition: SimulatorCLI.hh:63
SimulatorCmdLineOptions
Definition: SimulatorCmdLineOptions.hh:45
LineReader::setInputHistoryLog
virtual void setInputHistoryLog(const std::string &historyFilename)
Definition: LineReader.cc:124
SimulatorInterpreter::isQuitCommandGiven
bool isQuitCommandGiven() const
Definition: SimulatorInterpreter.cc:134
SimulatorCLI::options_
SimulatorCmdLineOptions * options_
Definition: SimulatorCLI.hh:64
SimulatorCLI::simFront_
SimulatorFrontend & simFront_
Definition: SimulatorCLI.hh:60
LineReader::readLine
virtual std::string readLine(std::string prompt="")=0
SIM_COMMAND_PROMPT
#define SIM_COMMAND_PROMPT
The command prompt of the simulator interpreter.
Definition: SimulatorConstants.hh:42
assert
#define assert(condition)
Definition: Application.hh:86
Application::argc
static int argc()
Definition: Application.hh:192
SimulatorInterpreter
Definition: SimulatorInterpreter.hh:49
SIM_INTERP_QUIT_COMMAND
#define SIM_INTERP_QUIT_COMMAND
The command used to quit the command line interface.
Definition: SimulatorConstants.hh:45
Application::cmdLineOptions
static CmdLineOptions * cmdLineOptions()
Definition: Application.cc:397
TclInterpreter::interpret
virtual bool interpret(const std::string &commandLine)
Definition: TclInterpreter.cc:138
SimulatorCLI::reader_
LineReader * reader_
Definition: SimulatorCLI.hh:62
SimulatorFrontend::isCompiledSimulation
bool isCompiledSimulation() const
Definition: SimulatorFrontend.cc:1295
StringTools::trim
static std::string trim(const std::string &source)
Definition: StringTools.cc:55
SimulatorCLI::errorReporter_
RuntimeErrorReporter * errorReporter_
Definition: SimulatorCLI.hh:65
Application::argv
static char ** argv()
Definition: Application.hh:193
LineReader::initialize
virtual void initialize(std::string defPrompt="", FILE *in=stdin, FILE *out=stdout, FILE *err=stderr)=0
SimulatorCLI::context_
SimulatorInterpreterContext * context_
Definition: SimulatorCLI.hh:61
RuntimeErrorReporter
Definition: SimulatorCLI.cc:53
EndOfFile
Definition: Exception.hh:189
SIM_DEFAULT_COMMAND_LOG
#define SIM_DEFAULT_COMMAND_LOG
The default command log file name.
Definition: SimulatorConstants.hh:51