OpenASIP  2.0
Public Member Functions | Static Public Attributes | List of all members
CmdMem Class Reference

#include <TestOsal.hh>

Inheritance diagram for CmdMem:
Inheritance graph
Collaboration diagram for CmdMem:
Collaboration graph

Public Member Functions

 CmdMem ()
 
 CmdMem (const CmdMem &cmd)
 
virtual ~CmdMem ()
 
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)
 

Static Public Attributes

static const std::string MEM_BYTE = "byte"
 Name for byte memory access. More...
 
static const std::string MEM_HALF_WORD = "halfword"
 Name for half word memory access. More...
 
static const std::string MEM_WORD = "word"
 Name for word memory access. More...
 
static const std::string MEM_DOUBLE_WORD = "double"
 Name for double word memory access. More...
 

Detailed Description

Command for viewing memory contents.

This implementation expects that MAU is 1 byte.

Definition at line 168 of file TestOsal.hh.

Constructor & Destructor Documentation

◆ CmdMem() [1/2]

CmdMem::CmdMem ( )

Constructor.

Definition at line 710 of file TestOsal.cc.

710  : CustomCommand("mem") {
711 }

◆ CmdMem() [2/2]

CmdMem::CmdMem ( const CmdMem cmd)
explicit

Copy constructor.

Parameters
cmdCommand to be copied.

Definition at line 718 of file TestOsal.cc.

718  : CustomCommand(cmd) {
719 }

◆ ~CmdMem()

CmdMem::~CmdMem ( )
virtual

Destructor.

Definition at line 724 of file TestOsal.cc.

724  {
725 }

Member Function Documentation

◆ execute()

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

Executes the command.

Parameters
argumentsArguments for the command.
Returns
True if execution is successful, false otherwise.
Exceptions
NumberFormatExceptionIf DataObject conversion fails.

Implements CustomCommand.

Definition at line 735 of file TestOsal.cc.

735  {
736  ScriptInterpreter* scriptInterp = interpreter();
737  OsalInterpreter* interp = dynamic_cast<OsalInterpreter*>(scriptInterp);
738  assert(interp != NULL);
739 
740  DataObject* result = new DataObject();
741 
742  if (arguments.size() != 3) {
743  result->setString("wrong number of arguments");
744  interp->setResult(result);
745  return false;
746  }
747 
748  string size = arguments[1].stringValue();
749 
750  if (size != MEM_BYTE &&
751  size != MEM_HALF_WORD &&
752  size != MEM_WORD &&
753  size != MEM_DOUBLE_WORD) {
754 
755  result->setString("invalid memory size: " + size);
756  interp->setResult(result);
757  return false;
758  }
759 
761  *(dynamic_cast<TesterContext*>(&interp->context()));
762 
763  Memory& memory = context.operationContext().memory();
764 
765  Word address = 0;
766  string addressString = arguments[2].stringValue();
767 
768  try {
769  address = Conversion::toInt(addressString);
770  } catch(const NumberFormatException& n) {
771  result->setString("illegal address: " + addressString);
772  interp->setResult(result);
773  return false;
774  }
775 
776  SimValue resultValue(64);
777 
778  try {
779  if (context.outputFormat() == CmdOutput::OUTPUT_FORMAT_LONG_UNSIGNED ||
780  context.outputFormat() == CmdOutput::OUTPUT_FORMAT_LONG_SIGNED) {
781  resultValue.setBitWidth(64);
782  }
783  if (size == MEM_BYTE) {
784  resultValue.setBitWidth(8);
785  ULongWord resultInt = 0;
786  memory.read(address, 1, resultInt);
787  resultValue = resultInt;
788  } else if (size == MEM_HALF_WORD) {
789  resultValue.setBitWidth(16);
790  ULongWord resultInt = 0;
791  memory.read(address, 2, resultInt);
792  resultValue = resultInt;
793  } else if (size == MEM_WORD) {
794  resultValue.setBitWidth(32);
795  ULongWord resultInt = 0;
796  memory.read(address, 4, resultInt);
797  resultValue = resultInt;
798  } else if (size == MEM_DOUBLE_WORD) {
799  resultValue.setBitWidth(64);
800 
801  DoubleWord result = 0.0;
802  // TODO: when to read in LE?
803  memory.readBE(address, result);
804  resultValue = result;
805  }
806  } catch (const OutOfRange& o) {
807  string addressString = Conversion::toString(address);
808  result->setString("address " + addressString + " out of memory bounds");
809  interp->setResult(result);
810  return false;
811  }
812  string output = context.toOutputFormat(&resultValue);
813  result->setString(output);
814  interp->setResult(result);
815  return true;
816 }

References assert, CustomCommand::context(), SimpleScriptInterpreter::context(), CustomCommand::interpreter(), MEM_BYTE, MEM_DOUBLE_WORD, MEM_HALF_WORD, MEM_WORD, CmdOutput::OUTPUT_FORMAT_LONG_SIGNED, CmdOutput::OUTPUT_FORMAT_LONG_UNSIGNED, Memory::read(), Memory::readBE(), SimValue::setBitWidth(), ScriptInterpreter::setResult(), DataObject::setString(), Conversion::toInt(), and Conversion::toString().

Here is the call graph for this function:

◆ helpText()

string CmdMem::helpText ( ) const
virtual

Returns the help text of the command.

Returns
The help text.

Implements CustomCommand.

Definition at line 824 of file TestOsal.cc.

824  {
825  return
826  "Prints the contents of the memory.\n"
827  "!mem <size> <address>\n"
828  "size is one of the following:\n{" +
829  MEM_BYTE + "|" + MEM_HALF_WORD + "|" + MEM_WORD + "|" +
830  MEM_DOUBLE_WORD + "}";
831 }

References MEM_BYTE, MEM_DOUBLE_WORD, MEM_HALF_WORD, and MEM_WORD.

Member Data Documentation

◆ MEM_BYTE

const string CmdMem::MEM_BYTE = "byte"
static

Name for byte memory access.

Definition at line 172 of file TestOsal.hh.

Referenced by execute(), and helpText().

◆ MEM_DOUBLE_WORD

const string CmdMem::MEM_DOUBLE_WORD = "double"
static

Name for double word memory access.

Definition at line 178 of file TestOsal.hh.

Referenced by execute(), and helpText().

◆ MEM_HALF_WORD

const string CmdMem::MEM_HALF_WORD = "halfword"
static

Name for half word memory access.

Definition at line 174 of file TestOsal.hh.

Referenced by execute(), and helpText().

◆ MEM_WORD

const string CmdMem::MEM_WORD = "word"
static

Name for word memory access.

Definition at line 176 of file TestOsal.hh.

Referenced by execute(), and helpText().


The documentation for this class was generated from the following files:
NumberFormatException
Definition: Exception.hh:421
DataObject
Definition: DataObject.hh:50
OutOfRange
Definition: Exception.hh:320
SimpleScriptInterpreter::context
virtual InterpreterContext & context() const
Definition: SimpleScriptInterpreter.cc:185
CustomCommand::context
InterpreterContext * context() const
CmdMem::MEM_DOUBLE_WORD
static const std::string MEM_DOUBLE_WORD
Name for double word memory access.
Definition: TestOsal.hh:178
Memory::readBE
virtual void readBE(ULongWord address, int size, ULongWord &data)
Definition: Memory.cc:640
Conversion::toString
static std::string toString(const T &source)
SimValue
Definition: SimValue.hh:96
assert
#define assert(condition)
Definition: Application.hh:86
CmdMem::MEM_BYTE
static const std::string MEM_BYTE
Name for byte memory access.
Definition: TestOsal.hh:172
CustomCommand::CustomCommand
CustomCommand(std::string name)
Definition: CustomCommand.cc:48
TesterContext
Definition: TestOsal.hh:212
DoubleWord
double DoubleWord
Definition: BaseType.hh:166
Memory::read
virtual Memory::MAU read(ULongWord address)=0
Definition: Memory.cc:160
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
OsalInterpreter
Definition: TestOsal.hh:249
CmdMem::MEM_HALF_WORD
static const std::string MEM_HALF_WORD
Name for half word memory access.
Definition: TestOsal.hh:174
CmdOutput::OUTPUT_FORMAT_LONG_SIGNED
static const std::string OUTPUT_FORMAT_LONG_SIGNED
Definition: TestOsal.hh:119
CmdOutput::OUTPUT_FORMAT_LONG_UNSIGNED
static const std::string OUTPUT_FORMAT_LONG_UNSIGNED
Definition: TestOsal.hh:120
CmdMem::MEM_WORD
static const std::string MEM_WORD
Name for word memory access.
Definition: TestOsal.hh:176
ULongWord
unsigned long ULongWord
Definition: BaseType.hh:51
Conversion::toInt
static int toInt(const T &source)
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130
ScriptInterpreter
Definition: ScriptInterpreter.hh:55
Memory
Definition: Memory.hh:74