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

#include <OperationSimulator.hh>

Collaboration diagram for OperationSimulator:
Collaboration graph

Public Member Functions

bool simulateTrigger (Operation &op, std::vector< DataObject > inputs, std::vector< SimValue * > &outputs, OperationContext &context, std::string &result)
 
bool lateResult (Operation &op, std::vector< DataObject > inputs, std::vector< SimValue * > &outputs, OperationContext &context, unsigned int bitWidth, std::string &result)
 
void advanceClock (OperationContext &context)
 
bool initializeSimValue (std::string value, SimValue *sim, std::string &result)
 

Static Public Member Functions

static OperationSimulatorinstance ()
 

Private Member Functions

 OperationSimulator ()
 
virtual ~OperationSimulator ()
 
bool initializeOutputs (Operation &op, std::vector< DataObject > inputs, std::vector< SimValue * > &outputs, std::string &result)
 

Static Private Attributes

static OperationSimulatorinstance_ = NULL
 Unique instance. More...
 

Detailed Description

Contains functionality to simulate operation behavior.

Definition at line 48 of file OperationSimulator.hh.

Constructor & Destructor Documentation

◆ OperationSimulator()

OperationSimulator::OperationSimulator ( )
private

Constructor.

Definition at line 50 of file OperationSimulator.cc.

50  {
51 }

Referenced by instance().

◆ ~OperationSimulator()

OperationSimulator::~OperationSimulator ( )
privatevirtual

Destructor.

Definition at line 56 of file OperationSimulator.cc.

56  {
57 }

Member Function Documentation

◆ advanceClock()

void OperationSimulator::advanceClock ( OperationContext context)

◆ initializeOutputs()

bool OperationSimulator::initializeOutputs ( Operation op,
std::vector< DataObject inputs,
std::vector< SimValue * > &  outputs,
std::string &  result 
)
private

Initializes the output values of the operation.

Parameters
opOperation in which outputs are initialized.
inputsInput values.
outputsOutput values to be initialized.
resultPossible error message string.
Returns
True if initialization is successful.

Definition at line 166 of file OperationSimulator.cc.

170  {
171 
172  for (size_t i = 0; i < inputs.size(); i++) {
173  SimValue* sim = new SimValue(op.input(i).width());
174 
175  string value = inputs[i].stringValue();
176 
177  if (!initializeSimValue(value, sim, result)) {
178  return false;
179  }
180 
181  outputs.push_back(sim);
182  }
183 
184  for (int i = 0; i < op.numberOfOutputs(); i++) {
185  SimValue* result = new SimValue(op.output(i).width());
186  outputs.push_back(result);
187  }
188  return true;
189 }

References initializeSimValue(), Operation::input(), Operation::numberOfOutputs(), Operation::output(), and Operand::width().

Referenced by simulateTrigger().

Here is the call graph for this function:

◆ initializeSimValue()

bool OperationSimulator::initializeSimValue ( std::string  value,
SimValue sim,
std::string &  result 
)

Initializes one SimValue.

Parameters
valueValue.
simSimValue to be initialized.
resultPossible error string.

Definition at line 122 of file OperationSimulator.cc.

125  {
126 
127  bool is_int = value.find(".") == string::npos &&
128  value.find('e') == string::npos;
129  bool is_float = !is_int &&
130  (value.find("f") != string::npos ||
131  value.find("F") != string::npos);
132  bool is_half = value.find(".") != string::npos &&
133  (value.find("h") != string::npos ||
134  value.find("H") != string::npos);
135 
136  try {
137  if (value.size() > 2 && value[0] == '0' && value[1] == 'x') {
138  (*sim).setValue(TCEString(value));
139  } else if (is_int && !is_float) {
140  *sim = Conversion::toLong(value);
141  } else if (is_float) {
142  *sim = Conversion::toFloat(value.substr(0, value.length()-1));
143  } else if (is_half) {
144  *sim = HalfFloatWord(
145  Conversion::toFloat(value.substr(0, value.length()-1)));
146  } else {
147  *sim = Conversion::toDouble(value);
148  }
149  } catch (const NumberFormatException& n) {
150  result = "illegal operand value \"" + value + "\"";
151  return false;
152  }
153  return true;
154 }

References Conversion::toDouble(), Conversion::toFloat(), and Conversion::toLong().

Referenced by initializeOutputs(), and SimulateDialog::onFormatChanged().

Here is the call graph for this function:

◆ instance()

OperationSimulator & OperationSimulator::instance ( )
static

Returns the unique instance of OperationSimulator.

Returns
The instance of OperationSimulator.

Definition at line 65 of file OperationSimulator.cc.

65  {
66  if (instance_ == NULL) {
68  }
69  return *instance_;
70 }

References instance_, and OperationSimulator().

Referenced by CmdTrigger::execute(), SimulateDialog::onFormatChanged(), and SimulateDialog::onTrigger().

Here is the call graph for this function:

◆ lateResult()

bool OperationSimulator::lateResult ( Operation op,
std::vector< DataObject inputs,
std::vector< SimValue * > &  outputs,
OperationContext context,
unsigned int  bitWidth,
std::string &  result 
)

◆ simulateTrigger()

bool OperationSimulator::simulateTrigger ( Operation op,
std::vector< DataObject inputs,
std::vector< SimValue * > &  outputs,
OperationContext context,
std::string &  result 
)

Executes the operation trigger command.

Parameters
opOperation to be simulated.
inputsThe inputs for the operation.
outputsThe outputs of the operation.
contextOperationContext used in simulation.
resultThe possible error string.
Returns
True if simulation is successful.

Definition at line 83 of file OperationSimulator.cc.

88  {
89 
90  if (static_cast<unsigned>(op.numberOfInputs()) != inputs.size()) {
91  result = "wrong number of arguments";
92  return false;
93  }
94 
95  if (!initializeOutputs(op, inputs, outputs, result)) {
96  return false;
97  }
98 
99  SimValue** io_ = new SimValue*[outputs.size()];
100  for (std::size_t i = 0; i < outputs.size(); ++i) {
101  io_[i] = outputs.at(i);
102  }
103  try {
104  bool ready = op.simulateTrigger(io_, context);
105  delete[] io_;
106  io_ = NULL;
107  return ready;
108  } catch (const Exception& e) {
109  result = e.errorMessage();
110  return false;
111  }
112 }

References Exception::errorMessage(), initializeOutputs(), Operation::numberOfInputs(), and Operation::simulateTrigger().

Referenced by CmdTrigger::execute(), and SimulateDialog::onTrigger().

Here is the call graph for this function:

Member Data Documentation

◆ instance_

OperationSimulator * OperationSimulator::instance_ = NULL
staticprivate

Unique instance.

Definition at line 85 of file OperationSimulator.hh.

Referenced by instance().


The documentation for this class was generated from the following files:
OperationSimulator::initializeSimValue
bool initializeSimValue(std::string value, SimValue *sim, std::string &result)
Definition: OperationSimulator.cc:122
NumberFormatException
Definition: Exception.hh:421
Operation::output
virtual Operand & output(int index) const
Definition: Operation.cc:526
Operand::width
virtual int width() const
Definition: Operand.cc:318
Operation::numberOfInputs
virtual int numberOfInputs() const
Definition: Operation.cc:192
HalfFloatWord
Definition: HalfFloatWord.hh:41
SimValue
Definition: SimValue.hh:96
OperationSimulator::instance_
static OperationSimulator * instance_
Unique instance.
Definition: OperationSimulator.hh:85
Conversion::toDouble
static double toDouble(const T &source)
OperationSimulator::initializeOutputs
bool initializeOutputs(Operation &op, std::vector< DataObject > inputs, std::vector< SimValue * > &outputs, std::string &result)
Definition: OperationSimulator.cc:166
Exception
Definition: Exception.hh:54
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
Operation::input
virtual Operand & input(int index) const
Definition: Operation.cc:503
TCEString
Definition: TCEString.hh:53
Operation::simulateTrigger
virtual bool simulateTrigger(SimValue **, OperationContext &context) const
Definition: Operation.cc:555
OperationSimulator::OperationSimulator
OperationSimulator()
Definition: OperationSimulator.cc:50
Conversion::toLong
static SLongWord toLong(const T &source)
Operation::numberOfOutputs
virtual int numberOfOutputs() const
Definition: Operation.cc:202
Conversion::toFloat
static float toFloat(const T &source)