OpenASIP  2.0
Public Member Functions | List of all members
MachCommand Class Reference

#include <MachCommand.hh>

Inheritance diagram for MachCommand:
Inheritance graph
Collaboration diagram for MachCommand:
Collaboration graph

Public Member Functions

 MachCommand ()
 
virtual ~MachCommand ()
 
virtual bool execute (const std::vector< DataObject > &arguments)
 
virtual std::string helpText () const
 
- Public Member Functions inherited from CustomCommand
 CustomCommand (std::string name)
 
 CustomCommand (const CustomCommand &cmd)
 
virtual ~CustomCommand ()
 
std::string name () const
 
void setContext (InterpreterContext *context)
 
InterpreterContextcontext () const
 
void setInterpreter (ScriptInterpreter *si)
 
ScriptInterpreterinterpreter () const
 
bool checkArgumentCount (int argumentCount, int minimum, int maximum)
 
bool checkIntegerArgument (const DataObject &argument)
 
bool checkPositiveIntegerArgument (const DataObject &argument)
 
bool checkUnsignedIntegerArgument (const DataObject &argument)
 
bool checkDoubleArgument (const DataObject &argument)
 

Detailed Description

Implementation of the "mach" command of the Simulator Control Language.

Definition at line 46 of file MachCommand.hh.

Constructor & Destructor Documentation

◆ MachCommand()

MachCommand::MachCommand ( )

Constructor.

Sets the name of the command to the base class.

Definition at line 47 of file MachCommand.cc.

47  : CustomCommand("mach") {
48 }

◆ ~MachCommand()

MachCommand::~MachCommand ( )
virtual

Destructor.

Does nothing.

Definition at line 55 of file MachCommand.cc.

55  {
56 }

Member Function Documentation

◆ execute()

bool MachCommand::execute ( const std::vector< DataObject > &  arguments)
virtual

Executes the "mach" command.

Loads a new machine file using the SimulatorFrontend.

Parameters
argumentsFilename is given as argument to the command.
Returns
True if loading the program was successful.
Exceptions
NumberFormatExceptionIs never thrown by this command.

Implements CustomCommand.

Definition at line 69 of file MachCommand.cc.

69  {
70  assert(interpreter() != NULL);
71 
73  if (arguments.size() < 2) {
74  DataObject* errorMessage = new DataObject();
75  errorMessage->setString(
76  textGen.text(Texts::TXT_NO_FILENAME_DEFINED).str());
77  interpreter()->setResult(errorMessage);
78  return false;
79  }
80 
81  if (arguments.size() > 2) {
82  DataObject* errorMessage = new DataObject();
83  errorMessage->setString(
85  interpreter()->setResult(errorMessage);
86  return false;
87  }
88 
89  SimulatorInterpreterContext& interpreterContext =
90  dynamic_cast<SimulatorInterpreterContext&>(interpreter()->context());
91 
92  SimulatorFrontend& simulatorFrontend =
93  interpreterContext.simulatorFrontend();
94 
95  try {
96  const std::string fileName =
97  FileSystem::expandTilde(arguments.at(1).stringValue());
98  simulatorFrontend.loadMachine(fileName);
99  } catch (const Exception& e) {
100  DataObject* errorMessage = new DataObject();
101  errorMessage->setString(
104  interpreter()->setResult(errorMessage);
105  return false;
106  } catch (...) {
107  assert(false);
108  return false;
109  }
110  return true;
111 }

References assert, ScriptInterpreter::context(), Exception::errorMessageStack(), FileSystem::expandTilde(), CustomCommand::interpreter(), SimulatorFrontend::loadMachine(), ScriptInterpreter::setResult(), DataObject::setString(), SimulatorInterpreterContext::simulatorFrontend(), Texts::TextGenerator::text(), SimulatorToolbox::textGenerator(), Texts::TXT_NO_FILENAME_DEFINED, Texts::TXT_ONLY_ONE_FILENAME_EXPECTED, and Texts::TXT_UNABLE_TO_LOAD_MACHINE.

Here is the call graph for this function:

◆ helpText()

std::string MachCommand::helpText ( ) const
virtual

Returns the help text for this command.

Help text is searched from SimulatorTextGenerator.

Returns
The help text.
Todo:
Use SimulatorTextGenerator to get the help text.

Implements CustomCommand.

Definition at line 122 of file MachCommand.cc.

122  {
125 }

References Texts::TextGenerator::text(), SimulatorToolbox::textGenerator(), and Texts::TXT_INTERP_HELP_MACH.

Here is the call graph for this function:

The documentation for this class was generated from the following files:
SimulatorInterpreterContext
Definition: SimulatorInterpreterContext.hh:45
Texts::TXT_INTERP_HELP_MACH
@ TXT_INTERP_HELP_MACH
Help text for command "mach" of the CLI.
Definition: SimulatorTextGenerator.hh:61
DataObject
Definition: DataObject.hh:50
SimulatorInterpreterContext::simulatorFrontend
SimulatorFrontend & simulatorFrontend()
Definition: SimulatorInterpreterContext.cc:61
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
Texts::TXT_ONLY_ONE_FILENAME_EXPECTED
@ TXT_ONLY_ONE_FILENAME_EXPECTED
Definition: TextGenerator.hh:62
assert
#define assert(condition)
Definition: Application.hh:86
SimulatorFrontend::loadMachine
virtual void loadMachine(const std::string &fileName)
Definition: SimulatorFrontend.cc:534
SimulatorTextGenerator
Definition: SimulatorTextGenerator.hh:41
CustomCommand::CustomCommand
CustomCommand(std::string name)
Definition: CustomCommand.cc:48
SimulatorToolbox::textGenerator
static SimulatorTextGenerator & textGenerator()
Definition: SimulatorToolbox.cc:75
Exception::errorMessageStack
std::string errorMessageStack(bool messagesOnly=false) const
Definition: Exception.cc:138
Exception
Definition: Exception.hh:54
FileSystem::expandTilde
static std::string expandTilde(const std::string &stringWithTilde)
Definition: FileSystem.cc:217
Texts::TXT_UNABLE_TO_LOAD_MACHINE
@ TXT_UNABLE_TO_LOAD_MACHINE
Definition: SimulatorTextGenerator.hh:196
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
Texts::TXT_NO_FILENAME_DEFINED
@ TXT_NO_FILENAME_DEFINED
Definition: TextGenerator.hh:61
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130
SimulatorFrontend
Definition: SimulatorFrontend.hh:89
ScriptInterpreter::context
virtual InterpreterContext & context() const =0