OpenASIP 2.2
Loading...
Searching...
No Matches
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.
 
static const std::string MEM_HALF_WORD = "halfword"
 Name for half word memory access.
 
static const std::string MEM_WORD = "word"
 Name for word memory access.
 
static const std::string MEM_DOUBLE_WORD = "double"
 Name for double word memory access.
 

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 ||
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}
#define assert(condition)
unsigned long ULongWord
Definition BaseType.hh:51
double DoubleWord
Definition BaseType.hh:166
static const std::string MEM_DOUBLE_WORD
Name for double word memory access.
Definition TestOsal.hh:178
static const std::string MEM_WORD
Name for word memory access.
Definition TestOsal.hh:176
static const std::string MEM_HALF_WORD
Name for half word memory access.
Definition TestOsal.hh:174
static const std::string MEM_BYTE
Name for byte memory access.
Definition TestOsal.hh:172
static const std::string OUTPUT_FORMAT_LONG_SIGNED
Definition TestOsal.hh:119
static const std::string OUTPUT_FORMAT_LONG_UNSIGNED
Definition TestOsal.hh:120
static std::string toString(const T &source)
static int toInt(const T &source)
InterpreterContext * context() const
ScriptInterpreter * interpreter() const
virtual void setString(std::string value)
virtual void readBE(ULongWord address, int size, ULongWord &data)
Definition Memory.cc:640
virtual Memory::MAU read(ULongWord address)=0
Definition Memory.cc:160
virtual void setResult(DataObject *result)
virtual InterpreterContext & context() const

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: