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

#include <TestOsal.hh>

Inheritance diagram for CmdRegister:
Inheritance graph
Collaboration diagram for CmdRegister:
Collaboration graph

Public Member Functions

 CmdRegister ()
 
 CmdRegister (const CmdRegister &cmd)
 
virtual ~CmdRegister ()
 
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 REGISTER_PROGRAM_COUNTER = "programcounter"
 
static const std::string REGISTER_RETURN_ADDRESS = "returnaddress"
 

Detailed Description

Custom command for showing register values.

There are currently two register values which can asked: program counter and return address.

Definition at line 145 of file TestOsal.hh.

Constructor & Destructor Documentation

◆ CmdRegister() [1/2]

CmdRegister::CmdRegister ( )

Constructor.

Definition at line 616 of file TestOsal.cc.

616  : CustomCommand("register") {
617 }

◆ CmdRegister() [2/2]

CmdRegister::CmdRegister ( const CmdRegister cmd)
explicit

Copy constructor.

Parameters
cmdCommand to be copied.

Definition at line 624 of file TestOsal.cc.

624  : CustomCommand(cmd) {
625 }

◆ ~CmdRegister()

CmdRegister::~CmdRegister ( )
virtual

Destructor.

Definition at line 630 of file TestOsal.cc.

630  {
631 }

Member Function Documentation

◆ execute()

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

Executes the command.

Output is the value of given register.

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

Implements CustomCommand.

Definition at line 643 of file TestOsal.cc.

643  {
644  ScriptInterpreter* scriptInterp = interpreter();
645  OsalInterpreter* interp = dynamic_cast<OsalInterpreter*>(scriptInterp);
646  assert(interp != NULL);
647  DataObject* result = new DataObject();
648 
649  if (arguments.size() != 2) {
650  result->setString("wrong number of arguments");
651  interp->setResult(result);
652  return false;
653  }
654 
655  string registerValue = arguments[1].stringValue();
656 
658  *(dynamic_cast<TesterContext*>(&interp->context()));
659 
660  string output = "";
661 
662  if (registerValue == REGISTER_PROGRAM_COUNTER) {
663  InstructionAddress& addr = context.programCounter();
664  SimValue value(64);
665  value = addr;
666  output = context.toOutputFormat(&value);
667  } else if (registerValue == REGISTER_RETURN_ADDRESS) {
668  SimValue& addr = context.returnAddress();
669  SimValue value(64);
670  value = addr;
671  output = context.toOutputFormat(&value);
672  } else {
673  result->setString("illegal register name \"" +
674  registerValue + "\"");
675  interp->setResult(result);
676  return false;
677  }
678 
679  result->setString(output);
680  interp->setResult(result);
681  return true;
682 }

References assert, CustomCommand::context(), SimpleScriptInterpreter::context(), CustomCommand::interpreter(), REGISTER_PROGRAM_COUNTER, REGISTER_RETURN_ADDRESS, ScriptInterpreter::setResult(), and DataObject::setString().

Here is the call graph for this function:

◆ helpText()

string CmdRegister::helpText ( ) const
virtual

Returns the help text of the command.

Returns
The help text.

Implements CustomCommand.

Definition at line 690 of file TestOsal.cc.

690  {
691  return
692  "Prints the contents of the register. Register is one of the "
693  "following:\n{" +
696 }

References REGISTER_PROGRAM_COUNTER, and REGISTER_RETURN_ADDRESS.

Member Data Documentation

◆ REGISTER_PROGRAM_COUNTER

const string CmdRegister::REGISTER_PROGRAM_COUNTER = "programcounter"
static

Definition at line 148 of file TestOsal.hh.

Referenced by execute(), and helpText().

◆ REGISTER_RETURN_ADDRESS

const string CmdRegister::REGISTER_RETURN_ADDRESS = "returnaddress"
static

Definition at line 149 of file TestOsal.hh.

Referenced by execute(), and helpText().


The documentation for this class was generated from the following files:
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
DataObject
Definition: DataObject.hh:50
SimpleScriptInterpreter::context
virtual InterpreterContext & context() const
Definition: SimpleScriptInterpreter.cc:185
CustomCommand::context
InterpreterContext * context() const
SimValue
Definition: SimValue.hh:96
assert
#define assert(condition)
Definition: Application.hh:86
CustomCommand::CustomCommand
CustomCommand(std::string name)
Definition: CustomCommand.cc:48
TesterContext
Definition: TestOsal.hh:212
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
OsalInterpreter
Definition: TestOsal.hh:249
CmdRegister::REGISTER_PROGRAM_COUNTER
static const std::string REGISTER_PROGRAM_COUNTER
Definition: TestOsal.hh:148
CmdRegister::REGISTER_RETURN_ADDRESS
static const std::string REGISTER_RETURN_ADDRESS
Definition: TestOsal.hh:149
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130
ScriptInterpreter
Definition: ScriptInterpreter.hh:55