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

#include <TestOsal.hh>

Inheritance diagram for CmdTrigger:
Inheritance graph
Collaboration diagram for CmdTrigger:
Collaboration graph

Public Member Functions

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

Custom command that executes the trigger command of last loaded operation.

Definition at line 58 of file TestOsal.hh.

Constructor & Destructor Documentation

◆ CmdTrigger() [1/2]

CmdTrigger::CmdTrigger ( )

Constructor.

Definition at line 67 of file TestOsal.cc.

67  : CustomCommand("trigger") {
68 }

◆ CmdTrigger() [2/2]

CmdTrigger::CmdTrigger ( const CmdTrigger cmd)
explicit

Copy constructor.

Definition at line 73 of file TestOsal.cc.

73  : CustomCommand(cmd) {
74 }

◆ ~CmdTrigger()

CmdTrigger::~CmdTrigger ( )
virtual

Destructor.

Definition at line 79 of file TestOsal.cc.

79  {
80 }

Member Function Documentation

◆ execute()

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

Executes the trigger command of an operation.

Parameters
argumentsThe arguments for the command.
Returns
True if the command is executed succesfully, otherwise false.
Exceptions
NumberFormatExceptionIf data object conversion fails.

Implements CustomCommand.

Definition at line 90 of file TestOsal.cc.

90  {
91  ScriptInterpreter* scriptInterp = interpreter();
92  OsalInterpreter* interp = dynamic_cast<OsalInterpreter*>(scriptInterp);
93  assert(interp != NULL);
94  DataObject* obj = new DataObject();
95 
96  if (arguments.size() < 2) {
97  obj->setString("too few arguments");
98  interp->setResult(obj);
99  return false;
100  }
101 
102  string opName = arguments[1].stringValue();
103 
104  Operation* op = NULL;
105  try {
106  op = &interp->operation(opName);
107  } catch (const IllegalOperationBehavior& e) {
108  // Catch error due to undefined or missing operation behavior.
109  obj->setString(e.errorMessage());
110  interp->setResult(obj);
111  return false;
112  }
113 
114  if (op == &NullOperation::instance()) {
115  obj->setString("unknown operation \"" + opName + "\"");
116  interp->setResult(obj);
117  return false;
118  }
119 
120  // remove "trigger" and operation name.
121  vector<DataObject> inputs;
122  for (size_t i = 2; i < arguments.size(); i++) {
123  inputs.push_back(arguments[i]);
124  }
125 
126  vector<SimValue*> args;
127  TesterContext& context = *dynamic_cast<TesterContext*>(&interp->context());
128  OperationContext& opContext = context.operationContext();
129 
130  string result = "";
131 
133  InstructionAddress oldPC = opContext.programCounter();
134 
135  if (!simulator.simulateTrigger(*op, inputs, args, opContext, result)) {
136  for (unsigned int i = 0; i < args.size(); i++) {
137  delete args[i];
138  }
139  obj->setString(result);
140  interp->setResult(obj);
141  return false;
142  } else {
143 
144  for (int i = 0; i < op->numberOfOutputs(); i++) {
145 
146  SimValue* current = args[op->numberOfInputs() + i];
147  string output = context.toOutputFormat(current);
148  result += output;
149 
150  // put blank everywhere else but after the last output
151  if (i < op->numberOfOutputs() - 1) {
152  result += " ";
153  }
154  }
155  }
156 
157  for (unsigned int i = 0; i < args.size(); i++) {
158  delete args[i];
159  }
160 
161  if (opContext.saveReturnAddress()) {
162  opContext.returnAddress() = oldPC;
163  }
164  obj->setString(result);
165  interp->setResult(obj);
166  return true;
167 }

References assert, CustomCommand::context(), SimpleScriptInterpreter::context(), Exception::errorMessage(), OperationSimulator::instance(), NullOperation::instance(), CustomCommand::interpreter(), Operation::numberOfInputs(), Operation::numberOfOutputs(), OsalInterpreter::operation(), OperationContext::programCounter(), OperationContext::returnAddress(), OperationContext::saveReturnAddress(), ScriptInterpreter::setResult(), DataObject::setString(), and OperationSimulator::simulateTrigger().

Here is the call graph for this function:

◆ helpText()

string CmdTrigger::helpText ( ) const
virtual

Returns the help text of trigger command.

Returns
The help text.

Implements CustomCommand.

Definition at line 175 of file TestOsal.cc.

175  {
176  return "trigger <operation> <operand>...";
177 }

The documentation for this class was generated from the following files:
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
OperationSimulator
Definition: OperationSimulator.hh:48
DataObject
Definition: DataObject.hh:50
OperationContext
Definition: OperationContext.hh:56
SimpleScriptInterpreter::context
virtual InterpreterContext & context() const
Definition: SimpleScriptInterpreter.cc:185
Operation::numberOfInputs
virtual int numberOfInputs() const
Definition: Operation.cc:192
CustomCommand::context
InterpreterContext * context() const
OperationContext::saveReturnAddress
bool saveReturnAddress()
Definition: OperationContext.cc:194
IllegalOperationBehavior
Definition: Exception.hh:844
NullOperation::instance
static NullOperation & instance()
SimValue
Definition: SimValue.hh:96
assert
#define assert(condition)
Definition: Application.hh:86
OsalInterpreter::operation
Operation & operation(const std::string &name)
Definition: TestOsal.cc:388
CustomCommand::CustomCommand
CustomCommand(std::string name)
Definition: CustomCommand.cc:48
TesterContext
Definition: TestOsal.hh:212
OperationSimulator::simulateTrigger
bool simulateTrigger(Operation &op, std::vector< DataObject > inputs, std::vector< SimValue * > &outputs, OperationContext &context, std::string &result)
Definition: OperationSimulator.cc:83
Operation
Definition: Operation.hh:59
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
OsalInterpreter
Definition: TestOsal.hh:249
OperationContext::programCounter
InstructionAddress & programCounter()
Definition: OperationContext.cc:152
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130
ScriptInterpreter
Definition: ScriptInterpreter.hh:55
Operation::numberOfOutputs
virtual int numberOfOutputs() const
Definition: Operation.cc:202
OperationContext::returnAddress
SimValue & returnAddress()
Definition: OperationContext.cc:207
OperationSimulator::instance
static OperationSimulator & instance()
Definition: OperationSimulator.cc:65