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

#include <MemWriteCommand.hh>

Inheritance diagram for MemWriteCommand:
Inheritance graph
Collaboration diagram for MemWriteCommand:
Collaboration graph

Public Member Functions

 MemWriteCommand ()
 
virtual ~MemWriteCommand ()
 
virtual bool execute (const std::vector< DataObject > &arguments)
 
virtual std::string helpText () const
 
- Public Member Functions inherited from SimControlLanguageCommand
 SimControlLanguageCommand (const std::string &name)
 
virtual ~SimControlLanguageCommand ()
 
SimulatorFrontendsimulatorFrontend ()
 
const SimulatorFrontendsimulatorFrontendConst ()
 
virtual void printNextInstruction ()
 
virtual void printStopInformation ()
 
virtual void printStopReasons ()
 
virtual bool printBreakpointInfo (unsigned int breakpointHandle)
 
virtual void printSimulationTime ()
 
virtual std::ostream & outputStream ()
 
bool checkSimulationInitialized ()
 
bool checkSimulationNotAlreadyRunning ()
 
bool checkSimulationStopped ()
 
bool checkSimulationEnded ()
 
bool checkProgramLoaded ()
 
bool checkMachineLoaded ()
 
InstructionAddress parseInstructionAddressExpression (const std::string &expression)
 
TTAProgram::Address parseDataAddressExpression (const std::string &expression)
 
bool parseBreakpoint (const std::vector< DataObject > &arguments, Breakpoint &target)
 
bool askConditionFromUser (TclConditionScript &target)
 
bool askExpressionFromUser (ExpressionScript &target)
 
bool verifyBreakpointHandles (const std::vector< DataObject > &arguments, std::size_t startIndex=1)
 
void setErrorMessage (const TCEString &errorMsg)
 
- 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)
 

Additional Inherited Members

- Protected Member Functions inherited from SimControlLanguageCommand
bool setMemoryAddress (const std::string &addressString, std::string &addressSpaceName, std::size_t &memoryAddress)
 
bool setMemoryPointer (MemorySystem::MemoryPtr &memory, const std::string &addressSpaceName)
 

Detailed Description

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

Definition at line 48 of file MemWriteCommand.hh.

Constructor & Destructor Documentation

◆ MemWriteCommand()

MemWriteCommand::MemWriteCommand ( )

Definition at line 49 of file MemWriteCommand.cc.

49  :
50  SimControlLanguageCommand("load_data") {
51 }

◆ ~MemWriteCommand()

MemWriteCommand::~MemWriteCommand ( )
virtual

Definition at line 54 of file MemWriteCommand.cc.

54  {
55 }

Member Function Documentation

◆ execute()

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

Executes the "load_data" command.

This low-level command reads binary data from file and loads it to memory starting at specified address.

Parameters
argumentsMemory address to be written, file to read from, read size.
Returns
True in case simulation is initialized and arguments are ok.
Exceptions
NumberFormatExceptionIs never thrown by this command.

Implements CustomCommand.

Definition at line 68 of file MemWriteCommand.cc.

68  {
69  const int argumentCount = arguments.size() - 1;
70  if (!checkArgumentCount(argumentCount, 2, 5)) {
71  return false;
72  }
73 
74  if (!checkProgramLoaded()) {
75  return false;
76  }
77 
78  size_t nextArg = 1;
79  size_t writeAddress;
80  std::string addressSpaceName = "";
81 
82  if (StringTools::ciEqual(arguments.at(nextArg).stringValue(), "/a")) {
83  addressSpaceName = arguments.at(2).stringValue();
84  nextArg = 3;
85  }
86 
87  const std::string addressString = arguments.at(nextArg).stringValue();
88  if (!setMemoryAddress(addressString, addressSpaceName, writeAddress)) {
89  return false;
90  }
91 
92  std::string fileName = arguments.at(nextArg + 1).stringValue();
93  if (!FileSystem::fileExists(fileName) ||
94  !FileSystem::fileIsReadable(fileName)) {
95  interpreter()->setResult("Error reading input file.");
96  interpreter()->setError(true);
97  return false;
98  }
99 
100  size_t readSize = FileSystem::sizeInBytes(fileName);
101  if (argumentCount == 3 || argumentCount == 5) {
102  readSize = arguments.at(nextArg + 2).integerValue();
103  }
104 
106  if (!setMemoryPointer(memory, addressSpaceName)) {
107  return false;
108  }
109 
110  std::ifstream inputFile(fileName.c_str(), std::ios::binary);
111  char dataByte;
112 
113  while (inputFile.get(dataByte) && readSize > 0) {
114  try {
115  memory->write(writeAddress, 1, (UIntWord)dataByte);
116  } catch (const OutOfRange&) {
120  interpreter()->setError(true);
121  return false;
122  }
123  writeAddress++;
124  readSize--;
125  }
126  memory->advanceClock();
127  inputFile.close();
128 
129  return true;
130 }

References CustomCommand::checkArgumentCount(), SimControlLanguageCommand::checkProgramLoaded(), StringTools::ciEqual(), FileSystem::fileExists(), FileSystem::fileIsReadable(), CustomCommand::interpreter(), ScriptInterpreter::setError(), SimControlLanguageCommand::setMemoryAddress(), SimControlLanguageCommand::setMemoryPointer(), ScriptInterpreter::setResult(), FileSystem::sizeInBytes(), SimulatorToolbox::textGenerator(), and Texts::TXT_ADDRESS_OUT_OF_RANGE.

Here is the call graph for this function:

◆ helpText()

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

Implements CustomCommand.

Definition at line 133 of file MemWriteCommand.cc.

133  {
136 }

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

Here is the call graph for this function:

The documentation for this class was generated from the following files:
UIntWord
Word UIntWord
Definition: BaseType.hh:144
CustomCommand::checkArgumentCount
bool checkArgumentCount(int argumentCount, int minimum, int maximum)
Definition: CustomCommand.cc:82
SimControlLanguageCommand::setMemoryPointer
bool setMemoryPointer(MemorySystem::MemoryPtr &memory, const std::string &addressSpaceName)
Definition: SimControlLanguageCommand.cc:780
OutOfRange
Definition: Exception.hh:320
Texts::TXT_ADDRESS_OUT_OF_RANGE
@ TXT_ADDRESS_OUT_OF_RANGE
Definition: SimulatorTextGenerator.hh:192
SimControlLanguageCommand::checkProgramLoaded
bool checkProgramLoaded()
Definition: SimControlLanguageCommand.cc:180
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
SimControlLanguageCommand::setMemoryAddress
bool setMemoryAddress(const std::string &addressString, std::string &addressSpaceName, std::size_t &memoryAddress)
Definition: SimControlLanguageCommand.cc:753
MemorySystem::MemoryPtr
boost::shared_ptr< Memory > MemoryPtr
Definition: MemorySystem.hh:57
SimControlLanguageCommand::SimControlLanguageCommand
SimControlLanguageCommand(const std::string &name)
Definition: SimControlLanguageCommand.cc:67
SimulatorToolbox::textGenerator
static SimulatorTextGenerator & textGenerator()
Definition: SimulatorToolbox.cc:75
StringTools::ciEqual
static bool ciEqual(const std::string &a, const std::string &b)
Definition: StringTools.cc:240
FileSystem::sizeInBytes
static uintmax_t sizeInBytes(const std::string &filePath)
Definition: FileSystem.cc:376
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
FileSystem::fileExists
static bool fileExists(const std::string fileName)
Texts::TXT_INTERP_HELP_LOADDATA
@ TXT_INTERP_HELP_LOADDATA
Help text for command "load_data" of the CLI.
Definition: SimulatorTextGenerator.hh:107
ScriptInterpreter::setError
virtual void setError(bool state)
Definition: ScriptInterpreter.cc:205
FileSystem::fileIsReadable
static bool fileIsReadable(const std::string fileName)