OpenASIP  2.0
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
OperationPimpl Class Reference

#include <OperationPimpl.hh>

Collaboration diagram for OperationPimpl:
Collaboration graph

Classes

struct  OperationDAGInfo
 

Public Member Functions

 ~OperationPimpl ()
 
int numberOfInputs () const
 
int numberOfOutputs () const
 
TCEString name () const
 
void setCall (bool setting)
 
void setBranch (bool setting)
 
void setControlFlowOperation (bool setting)
 
Operandoperand (int id) const
 

Private Types

typedef std::vector< OperationDAGInfoDAGContainer
 

Private Member Functions

 OperationPimpl (const TCEString &name, OperationBehavior &behavior)
 
 OperationPimpl ()
 
 OperationPimpl (const OperationPimpl &)
 Copying not allowed. More...
 
OperationPimploperator= (const OperationPimpl &)
 Assignment not allowed. More...
 
TCEString description () const
 
void addDag (const TCEString &code)
 
void removeDag (int index)
 
int dagCount () const
 
OperationDAGdag (int index) const
 
TCEString dagCode (int index) const
 
void setDagCode (int index, const TCEString &code)
 
TCEString dagError (int index) const
 
bool usesMemory () const
 
bool readsMemory () const
 
bool writesMemory () const
 
bool canTrap () const
 
bool hasSideEffects () const
 
bool isClocked () const
 
bool isControlFlowOperation () const
 
bool isCall () const
 
bool isBranch () const
 
bool dependsOn (const Operation &op) const
 
void setReadsMemory (bool setting)
 
void setWritesMemory (bool setting)
 
int affectsCount () const
 
int affectedByCount () const
 
TCEString affects (unsigned int i) const
 
TCEString affectedBy (unsigned int i) const
 
bool canSwap (int id1, int id2) const
 
Operandinput (int index) const
 
void addInput (Operand *operand)
 
Operandoutput (int index) const
 
void addOutput (Operand *operand)
 
void setBehavior (OperationBehavior &behavior)
 
OperationBehaviorbehavior () const
 
void loadState (const ObjectState *state)
 
ObjectStatesaveState () const
 
bool simulateTrigger (SimValue **, OperationContext &context) const
 
void createState (OperationContext &context) const
 
void deleteState (OperationContext &context) const
 
bool canBeSimulated () const
 
bool isNull () const
 
TCEString emulationFunctionName () const
 
void clear ()
 
OperandfetchOperand (int id, const std::vector< Operand * > &ops) const
 
OperandfetchOperand (int id) const
 
void insertOperand (Operand *operand, std::vector< Operand * > &ops)
 

Private Attributes

OperationBehaviorbehavior_
 The behavior of the Operation. More...
 
std::string name_
 Name of the Operation. More...
 
std::string description_
 Description of the Operation. More...
 
DAGContainer dags_
 Table of DAGs and their source codes of an operation. More...
 
int inputs_
 The number of inputs of the Operation. More...
 
int outputs_
 The number of outputs of the Operation. More...
 
bool readsMemory_
 Flag indicating if Operation reads from memory. More...
 
bool writesMemory_
 Flag indicating if Operation writes to memory. More...
 
bool canTrap_
 Flag indicating if Operation can trap. More...
 
bool hasSideEffects_
 Flag indicating if Operation has side effects. More...
 
bool isClocked_
 Flag indicating if Operation is clocked and needs AdvanceClock. More...
 
bool controlFlowOperation_
 Flag indicating if the Operation can change program flow. More...
 
std::set< std::string > affects_
 Operations that affects this Operation. More...
 
std::set< std::string > affectedBy_
 Operations that are affected by this Operation. More...
 
std::vector< Operand * > inputOperands_
 Input Operands of the Operation. More...
 
std::vector< Operand * > outputOperands_
 Output Operands of the Operation. More...
 
bool isCall_
 Flag indicating if Operation is call. More...
 
bool isBranch_
 Flag indicating if Operation is branch changing control flow. More...
 

Friends

class Operation
 

Detailed Description

A private implementation class for Operation

Definition at line 54 of file OperationPimpl.hh.

Member Typedef Documentation

◆ DAGContainer

typedef std::vector<OperationDAGInfo> OperationPimpl::DAGContainer
private

Definition at line 146 of file OperationPimpl.hh.

Constructor & Destructor Documentation

◆ ~OperationPimpl()

OperationPimpl::~OperationPimpl ( )

Destructor.

Operands are destroyed.

Definition at line 80 of file OperationPimpl.cc.

80  {
81  clear();
82 }

References clear().

Here is the call graph for this function:

◆ OperationPimpl() [1/3]

OperationPimpl::OperationPimpl ( const TCEString name,
OperationBehavior behavior 
)
private

Constructor.

Parameters
nameThe name of the Operation.
behaviorThe behavior of the Operation.

Definition at line 65 of file OperationPimpl.cc.

67  :
69  description_(""),
70  inputs_(0), outputs_(0), readsMemory_(false), writesMemory_(false),
71  canTrap_(false), hasSideEffects_(false), isClocked_(false),
72  controlFlowOperation_(false), isCall_(false), isBranch_(false) {
73 }

◆ OperationPimpl() [2/3]

OperationPimpl::OperationPimpl ( )
private

◆ OperationPimpl() [3/3]

OperationPimpl::OperationPimpl ( const OperationPimpl )
private

Copying not allowed.

Member Function Documentation

◆ addDag()

void OperationPimpl::addDag ( const TCEString code)
private

Creates new DAG and adds it's code for operation.

Parameters
codeSource code written in DAG language.

Definition at line 140 of file OperationPimpl.cc.

140  {
141  OperationDAGInfo newDag;
142  newDag.code = code;
143  newDag.dag = &OperationDAG::null;
144  newDag.compilationFailed = false;
145  dags_.push_back(newDag);
146 }

References OperationPimpl::OperationDAGInfo::code, OperationPimpl::OperationDAGInfo::compilationFailed, OperationPimpl::OperationDAGInfo::dag, dags_, and OperationDAG::null.

Referenced by Operation::addDag(), and loadState().

◆ addInput()

void OperationPimpl::addInput ( Operand operand)
private

Definition at line 620 of file OperationPimpl.cc.

620  {
621  inputOperands_.push_back(operand);
622  inputs_ = inputOperands_.size();
623 }

References inputOperands_, inputs_, and operand().

Referenced by Operation::addInput().

Here is the call graph for this function:

◆ addOutput()

void OperationPimpl::addOutput ( Operand operand)
private

Definition at line 626 of file OperationPimpl.cc.

626  {
627  outputOperands_.push_back(operand);
628  outputs_ = outputOperands_.size();
629 }

References operand(), outputOperands_, and outputs_.

Referenced by Operation::addOutput().

Here is the call graph for this function:

◆ affectedBy()

TCEString OperationPimpl::affectedBy ( unsigned int  i) const
private

Returns the name of the operation that is affected by this operation.

Parameters
iThe index of the operation.
Exceptions
OutOfRangeIf index is illegal.
Returns
The name of the operation.

Definition at line 389 of file OperationPimpl.cc.

389  {
390 
391  if (i >= affectedBy_.size()) {
392  string method = "OperationPimpl::affectedBy()";
393  string msg = "Index out of range.";
394  throw OutOfRange(__FILE__, __LINE__, method, msg);
395  }
396 
397  set<string>::const_iterator it = affectedBy_.begin();
398  unsigned int count = 0;
399  while (count < i) {
400  it++;
401  count++;
402  }
403  return *it;
404 }

References affectedBy_.

Referenced by Operation::affectedBy(), loadState(), and saveState().

◆ affectedByCount()

int OperationPimpl::affectedByCount ( ) const
private

Returns the number of operations affected by this operation.

Returns
The number of operations affected by this operation.

Definition at line 353 of file OperationPimpl.cc.

353  {
354  return affectedBy_.size();
355 }

References affectedBy_.

Referenced by Operation::affectedByCount().

◆ affects()

TCEString OperationPimpl::affects ( unsigned int  i) const
private

Returns the name of the operation this operation affects.

Parameters
iThe index of the operation.
Returns
The name of the operation.

Definition at line 364 of file OperationPimpl.cc.

364  {
365 
366  if (i >= affects_.size()) {
367  string method = "OperationPimpl::affects()";
368  string msg = "Index out of range.";
369  throw OutOfRange(__FILE__, __LINE__, method, msg);
370  }
371 
372  set<string>::const_iterator it = affects_.begin();
373  unsigned int count = 0;
374  while (count < i) {
375  it++;
376  count++;
377  }
378  return *it;
379 }

References affects_.

Referenced by Operation::affects(), loadState(), and saveState().

◆ affectsCount()

int OperationPimpl::affectsCount ( ) const
private

Returns the number of operations that affect this operation.

Returns
The number of operations that affect this operation.

Definition at line 343 of file OperationPimpl.cc.

343  {
344  return affects_.size();
345 }

References affects_.

Referenced by Operation::affectsCount().

◆ behavior()

OperationBehavior & OperationPimpl::behavior ( ) const
private

Returns the behavior of Operation.

Returns
The behavior of Operation.

Definition at line 333 of file OperationPimpl.cc.

333  {
334  return *behavior_;
335 }

References behavior_.

Referenced by Operation::areValid(), Operation::behavior(), and setBehavior().

◆ canBeSimulated()

bool OperationPimpl::canBeSimulated ( ) const
private

Returns true if this operation has behavior, or dag which is simulateable (doesn't contain infinite recursion loop).

Returns
True if this operation has behavior, or dag which is

Definition at line 786 of file OperationPimpl.cc.

786  {
787  return behavior_->canBeSimulated();
788 }

References behavior_, and OperationBehavior::canBeSimulated().

Referenced by Operation::canBeSimulated().

Here is the call graph for this function:

◆ canSwap()

bool OperationPimpl::canSwap ( int  id1,
int  id2 
) const
private

Returns true if Operands can be swapped.

Parameters
id1Id of the first Operand.
id2Id of the second Operand.
Returns
True, if Operands can be swapped, false otherwise.

Definition at line 435 of file OperationPimpl.cc.

435  {
436 
437  Operand& op1 = fetchOperand(id1);
438  Operand& op2 = fetchOperand(id2);
439 
440  if (&op1 == &NullOperand::instance() ||
441  &op2 == &NullOperand::instance()) {
442  return false;
443  }
444  return op1.canSwap(op2);
445 }

References Operand::canSwap(), fetchOperand(), and NullOperand::instance().

Referenced by Operation::canSwap().

Here is the call graph for this function:

◆ canTrap()

bool OperationPimpl::canTrap ( ) const
private

Returns true if Operation can trap.

Returns
True if Operation can trap, false otherwise.

Definition at line 258 of file OperationPimpl.cc.

258  {
259  return canTrap_;
260 }

References canTrap_.

Referenced by Operation::canTrap().

◆ clear()

void OperationPimpl::clear ( )
private

Clears the operation.

Definition at line 88 of file OperationPimpl.cc.

88  {
89 
90  for (int i = 0; i < dagCount(); i++) {
91  if (!dags_[i].dag->isNull()) {
92  delete dags_[i].dag;
93  }
94  }
95  dags_.clear();
96 
99  inputOperands_.clear();
100  outputOperands_.clear();
101  affects_.clear();
102  affectedBy_.clear();
103  name_ = "";
104  inputs_ = 0;
105  outputs_ = 0;
106  readsMemory_ = false;
107  writesMemory_ = false;
108  canTrap_ = false;
109  hasSideEffects_ = false;
110  controlFlowOperation_ = false;
111  isBranch_ = false;
112  isCall_ = false;
113 }

References affectedBy_, affects_, canTrap_, controlFlowOperation_, dag(), dagCount(), dags_, SequenceTools::deleteAllItems(), hasSideEffects_, inputOperands_, inputs_, isBranch_, isCall_, OperationDAG::isNull(), name_, outputOperands_, outputs_, readsMemory_, and writesMemory_.

Referenced by loadState(), and ~OperationPimpl().

Here is the call graph for this function:

◆ createState()

void OperationPimpl::createState ( OperationContext context) const
private

Creates an instance of operation state for this operation and adds it to the operation context.

Parameters
contextThe operation context to add the state in.

Definition at line 764 of file OperationPimpl.cc.

764  {
765  behavior_->createState(context);
766 }

References behavior_, and OperationBehavior::createState().

Referenced by Operation::createState().

Here is the call graph for this function:

◆ dag()

OperationDAG & OperationPimpl::dag ( int  index) const
private

Returns an operation DAG for operation.

Compiles DAG from code to object if necessary.

Parameters
indexIndex of returned DAG.
Returns
Requested operation DAG or OperationDAG::null if DAG is not valid.

Definition at line 186 of file OperationPimpl.cc.

186  {
187 
188  // if dag is not up to date, try to compile it, if compilation failed and
189  // dag code has not been changed don't try to compile again
190  if (dags_[index].dag->isNull() && !dags_[index].compilationFailed) {
191 
192  try {
193  dags_[index].dag =
194  OperationDAGConverter::createDAG(*this, dags_[index].code);
195  dags_[index].compilationFailed = false;
196  dags_[index].error = "";
197 
198  } catch (const IllegalParameters &e) {
199  dags_[index].dag = &OperationDAG::null;
200  dags_[index].error = e.errorMessage();
201  dags_[index].compilationFailed = true;
202 
203  } catch (const Exception &e) {
204  dags_[index].dag = &OperationDAG::null;
205  dags_[index].error = "UNEXPECTED ERROR: " + e.errorMessage();
206  dags_[index].compilationFailed = true;
207  }
208  }
209 
210  return *dags_[index].dag;
211 }

References OperationDAGConverter::createDAG(), dags_, Exception::errorMessage(), OperationDAG::isNull(), and OperationDAG::null.

Referenced by clear(), Operation::dag(), and setDagCode().

Here is the call graph for this function:

◆ dagCode()

TCEString OperationPimpl::dagCode ( int  index) const
private

Returns source code of DAG.

Parameters
indexIndex of DAG whose source code is requested.
Returns
The source code set for DAG.

Definition at line 220 of file OperationPimpl.cc.

220  {
221  return dags_[index].code;
222 }

References dags_.

Referenced by Operation::dagCode(), and saveState().

◆ dagCount()

int OperationPimpl::dagCount ( ) const
private

Returns number of DAGs stored for operation.

Returns
Number of DAGs stored for operation.

Definition at line 172 of file OperationPimpl.cc.

172  {
173  return dags_.size();
174 }

References dags_.

Referenced by clear(), Operation::dagCount(), and saveState().

◆ dagError()

TCEString OperationPimpl::dagError ( int  index) const
private

Error message if DAG source code could not be compiled.

Parameters
indexIndex of DAG whose error is returned.
Returns
Error message, empty string if DAG was compiles successfully.

Definition at line 248 of file OperationPimpl.cc.

248  {
249  return dags_[index].error;
250 }

References dags_.

Referenced by Operation::dagError().

◆ deleteState()

void OperationPimpl::deleteState ( OperationContext context) const
private

Deletes an instance of operation state for this operation from the operation context.

Parameters
contextThe operation context to delete the state from.

Definition at line 775 of file OperationPimpl.cc.

775  {
776  behavior_->deleteState(context);
777 }

References behavior_, and OperationBehavior::deleteState().

Referenced by Operation::deleteState().

Here is the call graph for this function:

◆ dependsOn()

bool OperationPimpl::dependsOn ( const Operation op) const
private

Returns true if Operation depends on the given operation.

Parameters
opThe Operation being investigated.
Returns
True if Operation depends on the given operation, false otherwise.

Definition at line 413 of file OperationPimpl.cc.

413  {
414  set<string>::const_iterator it = affects_.find(op.name());
415  if (it != affects_.end()) {
416  return true;
417  } else {
418  it = affectedBy_.find(op.name());
419  if (it != affectedBy_.end()) {
420  return true;
421  }
422  }
423 
424  return false;
425 }

References affectedBy_, affects_, and Operation::name().

Referenced by Operation::dependsOn().

Here is the call graph for this function:

◆ description()

TCEString OperationPimpl::description ( ) const
private

Returns the description of the Operation.

Returns
The description of the Operation.

Definition at line 131 of file OperationPimpl.cc.

131  {
132  return description_;
133 }

References description_.

Referenced by Operation::description().

◆ emulationFunctionName()

TCEString OperationPimpl::emulationFunctionName ( ) const
private

Name of emulation function which is called if the operation is emulated in program.

Returns
Name of emulation function of the instruction.

Definition at line 819 of file OperationPimpl.cc.

819  {
820  std::string functionName;
821 
822  functionName = "__emulate_" + std::string(name()) +
825 
826  for (int i = 1; i <= numberOfInputs(); i++) {
827  Operand& oper = operand(i);
828  functionName += "_" + llvmOperandType(oper.type());
829  }
830 
831  for (int i = 1; i <= numberOfOutputs(); i++) {
832  Operand& oper = operand(numberOfInputs() + i);
833  functionName += "_" + llvmOperandType(oper.type());
834  }
835 
836  return functionName;
837 }

References llvmOperandType(), name(), numberOfInputs(), numberOfOutputs(), operand(), Conversion::toString(), and Operand::type().

Referenced by Operation::emulationFunctionName().

Here is the call graph for this function:

◆ fetchOperand() [1/2]

Operand & OperationPimpl::fetchOperand ( int  id) const
private

Returns an operand with a certain id if it exists.

If operand is not found, NullOperand is returned.

Parameters
idId of the operand.
Returns
Operand with a certain id.

Definition at line 696 of file OperationPimpl.cc.

696  {
697  assert(id != 0);
698 
699  for (unsigned int i = 0; i < inputOperands_.size(); i++) {
700  if (inputOperands_[i]->index() == id) {
701  return *inputOperands_[i];
702  }
703  }
704 
705  for (unsigned int i = 0; i < outputOperands_.size(); i++) {
706  if (outputOperands_[i]->index() == id) {
707  return *outputOperands_[i];
708  }
709  }
710 
711  return NullOperand::instance();
712 }

References assert, inputOperands_, NullOperand::instance(), and outputOperands_.

Here is the call graph for this function:

◆ fetchOperand() [2/2]

Operand & OperationPimpl::fetchOperand ( int  id,
const std::vector< Operand * > &  ops 
) const
private

Returns an operand with a certain id if it exists.

If operand is not found, a null operand is returned.

Parameters
idThe id of an operand.
opsVector where operand is searched.
Returns
Operand with a certain id.

Definition at line 674 of file OperationPimpl.cc.

674  {
675  assert(id != 0);
676 
677  for (std::vector<Operand*>::const_iterator i = ops.begin(); i != ops.end();
678  ++i) {
679  if ((*i)->index() == id) {
680  return **i;
681  }
682  }
683 
684  return NullOperand::instance();
685 }

References assert, and NullOperand::instance().

Referenced by canSwap(), and operand().

Here is the call graph for this function:

◆ hasSideEffects()

bool OperationPimpl::hasSideEffects ( ) const
private

Return true if operation has side effects.

Returns
True if Operation has side effects, false otherwise.

Definition at line 268 of file OperationPimpl.cc.

268  {
269  return hasSideEffects_;
270 }

References hasSideEffects_.

Referenced by Operation::hasSideEffects().

◆ input()

Operand& OperationPimpl::input ( int  index) const
inlineprivate

Referenced by Operation::input().

◆ insertOperand()

void OperationPimpl::insertOperand ( Operand operand,
std::vector< Operand * > &  ops 
)
private

Inserts operand to the right place.

Operands are inserted according to their indexes.

Parameters
operandOperand to be inserted.
opsVector in which operand is inserted.

Definition at line 723 of file OperationPimpl.cc.

723  {
724 
725  vector<Operand*>::iterator it = ops.begin();
726  bool inserted = false;
727  while (it != ops.end()) {
728  if ((*it)->index() > operand->index()) {
729  inserted = true;
730  ops.insert(it, operand);
731  break;
732  }
733  it++;
734  }
735  if (!inserted) {
736  ops.push_back(operand);
737  }
738 }

References Operand::index(), and operand().

Referenced by loadState().

Here is the call graph for this function:

◆ isBranch()

bool OperationPimpl::isBranch ( ) const
private

Return true if the operation is branch.

Branches of different type have this property set.

Returns
True if Operation is a branch operation.

Definition at line 313 of file OperationPimpl.cc.

313  {
314  return isBranch_;
315 }

References isBranch_.

Referenced by Operation::isBranch().

◆ isCall()

bool OperationPimpl::isCall ( ) const
private

Return true if the operation is call.

Calls of different type have this property set.

Returns
True if Operation is a call operation.

Definition at line 302 of file OperationPimpl.cc.

302  {
303  return isCall_;
304 }

References isCall_.

Referenced by Operation::isCall().

◆ isClocked()

bool OperationPimpl::isClocked ( ) const
private

Returns true if the operation is clocked.

Returns
True if the operation is clocked.

Definition at line 278 of file OperationPimpl.cc.

278  {
279  return isClocked_;
280 }

References isClocked_.

Referenced by Operation::isClocked().

◆ isControlFlowOperation()

bool OperationPimpl::isControlFlowOperation ( ) const
private

Return true if the operation can change control flow.

Branches and calls of different type have this property set.

Returns
True if Operation is a control flow operation.

Definition at line 290 of file OperationPimpl.cc.

290  {
291  return controlFlowOperation_;
292 }

References controlFlowOperation_.

Referenced by Operation::isControlFlowOperation().

◆ isNull()

bool OperationPimpl::isNull ( ) const
private

◆ loadState()

void OperationPimpl::loadState ( const ObjectState state)
private

Loads the Operation from ObjectState object.

Parameters
stateThe state of the Operation.

Definition at line 453 of file OperationPimpl.cc.

453  {
454 
455  clear();
456 
457  string method = "OperationPimpl::loadState()";
458 
459  try {
462 
464 
467 
476 
477  for (int i = 0; i < state->childCount(); i++) {
478  ObjectState* child = state->child(i);
479 
480  if (child->name() == Operation::OPRN_IN) {
481  Operand* operand = new Operand(true);
482  operand->loadState(child);
483  if (operand->index() < 1 || operand->index() > inputs_) {
484  string msg = "Input operand index illegal";
485  throw Exception(__FILE__, __LINE__, method, msg);
486  }
488 
489  } else if (child->name() == Operation::OPRN_OUT) {
490  Operand* operand = new Operand(false);
491  operand->loadState(child);
492  if (operand->index() <= inputs_ ||
493  operand->index() > inputs_ + outputs_) {
494  string msg = "Output operand index illegal";
495  throw Exception(__FILE__, __LINE__, method, msg);
496  }
498 
499  } else if (child->name() == Operation::OPRN_AFFECTS) {
500  for (int j = 0; j < child->childCount(); j++) {
501  ObjectState* affects = child->child(j);
502  affects_.insert(
504  affects->stringAttribute(Operation::OPRN_NAME)));
505  }
506 
507  } else if (child->name() == Operation::OPRN_AFFECTED_BY) {
508  for (int j = 0; j < child->childCount(); j++) {
509  ObjectState* affectedBy = child->child(j);
510  affectedBy_.insert(
512  affectedBy->stringAttribute(Operation::OPRN_NAME)));
513  }
514 
515  } else if (child->name() == Operation::OPRN_TRIGGER) {
516  addDag(child->stringValue());
517 
518  } else {
519  // no other childs should be possible
520  string msg = "Unknown child: " + child->name();
521  throw Exception(__FILE__, __LINE__, method, msg);
522  }
523  }
524 
525  // TODO: check can-swap operands and verify that they are created
526  // properly
527 
528  // add operands that are not defined in XML nor can-swap..
529  for (int i = 1; i <= inputs_; ++i) {
530  if (&operand(i) == &NullOperand::instance()) {
531  Operand* operand = new Operand(true, i, Operand::SINT_WORD);
533  }
534  }
535 
536  for (int i = 1 + inputs_; i <= inputs_ + outputs_; ++i) {
537  if (&operand(i) == &NullOperand::instance()) {
538  Operand* operand = new Operand(true, i, Operand::SINT_WORD);
540  }
541  }
542 
543  } catch (const Exception& e) {
544  string msg = "Problems loading Operation: " + e.errorMessage();
545  ObjectStateLoadingException error(__FILE__, __LINE__, method, msg);
546  error.setCause(e);
547  throw error;
548  }
549 }

References addDag(), affectedBy(), affectedBy_, affects(), affects_, ObjectState::boolAttribute(), canTrap_, ObjectState::child(), ObjectState::childCount(), clear(), controlFlowOperation_, description_, Exception::errorMessage(), hasSideEffects_, Operand::index(), inputOperands_, inputs_, insertOperand(), NullOperand::instance(), ObjectState::intAttribute(), isBranch_, isCall_, isClocked_, Operand::loadState(), ObjectState::name(), name_, operand(), Operation::OPRN_AFFECTED_BY, Operation::OPRN_AFFECTS, Operation::OPRN_CLOCKED, Operation::OPRN_CONTROL_FLOW, Operation::OPRN_DESCRIPTION, Operation::OPRN_IN, Operation::OPRN_INPUTS, Operation::OPRN_ISBRANCH, Operation::OPRN_ISCALL, Operation::OPRN_NAME, Operation::OPRN_OUT, Operation::OPRN_OUTPUTS, Operation::OPRN_READS_MEMORY, Operation::OPRN_SIDE_EFFECTS, Operation::OPRN_TRAP, Operation::OPRN_TRIGGER, Operation::OPRN_WRITES_MEMORY, outputOperands_, outputs_, readsMemory_, Exception::setCause(), Operand::SINT_WORD, ObjectState::stringAttribute(), StringTools::stringToUpper(), ObjectState::stringValue(), and writesMemory_.

Referenced by Operation::loadState().

Here is the call graph for this function:

◆ name()

TCEString OperationPimpl::name ( ) const

Returns the name of the Operation.

Returns
The name of the Operation.

Definition at line 121 of file OperationPimpl.cc.

121  {
122  return name_;
123 }

References name_.

Referenced by OperationDAGBuilder::connectOperandToNode(), FUGen::constantName(), FUGen::DAGNodeOperandWidth(), emulationFunctionName(), OperationDAGBuilder::finalize(), Operation::name(), and FUGen::subOpConnection().

◆ numberOfInputs()

int OperationPimpl::numberOfInputs ( ) const
inline

◆ numberOfOutputs()

int OperationPimpl::numberOfOutputs ( ) const
inline

◆ operand()

Operand & OperationPimpl::operand ( int  id) const

Returns the Operand with the given id if found, otherwise null Operand.

Note
This method is used to fetch operands with their 'id', the number which identifies it to the programmer. That is, output ids start from the last input id + 1, etc.
Parameters
idThe id of Operand.
Returns
Operand if found, null Operand otherwise.

Definition at line 655 of file OperationPimpl.cc.

655  {
656  assert(id != 0);
658  if (&op == &NullOperand::instance()) {
659  return fetchOperand(id, outputOperands_);
660  }
661  return op;
662 }

References assert, fetchOperand(), inputOperands_, NullOperand::instance(), and outputOperands_.

Referenced by addInput(), addOutput(), emulationFunctionName(), insertOperand(), loadState(), Operation::operand(), saveState(), and OperationDAGConverter::writeNode().

Here is the call graph for this function:

◆ operator=()

OperationPimpl& OperationPimpl::operator= ( const OperationPimpl )
private

Assignment not allowed.

◆ output()

Operand & OperationPimpl::output ( int  index) const
private

Returns the output Operand with the given index.

This method can be used to traverse the list of output operands (the max index is numberOfOutput() - 1).

Parameters
indexThe index of Operand.

Definition at line 640 of file OperationPimpl.cc.

640  {
641  return *outputOperands_.at(index);
642 }

References outputOperands_.

Referenced by Operation::output().

◆ readsMemory()

bool OperationPimpl::readsMemory ( ) const
inlineprivate

Referenced by Operation::readsMemory().

◆ removeDag()

void OperationPimpl::removeDag ( int  index)
private

Removes DAG of given index from operation.

Parameters
indexIndex of dag to delete.

Definition at line 154 of file OperationPimpl.cc.

154  {
155  DAGContainer::iterator i = dags_.begin() + index;
156 
157  if (!i->dag->isNull()) {
158  delete i->dag;
159  i->dag = &OperationDAG::null;
160  }
161 
162  dags_.erase(i);
163 }

References dags_, and OperationDAG::null.

Referenced by Operation::removeDag().

◆ saveState()

ObjectState * OperationPimpl::saveState ( ) const
private

Saves the state of the Operation in ObjectState object.

Returns
The state of the Operation.

Definition at line 557 of file OperationPimpl.cc.

557  {
558 
564 
573 
574  if (affectedBy_.size() > 0) {
576  set<string>::const_iterator it = affectedBy_.begin();
577  while (it != affectedBy_.end()) {
578  ObjectState* affectedByChild = new ObjectState(Operation::OPRN_OPERATION);
579  affectedByChild->setAttribute(Operation::OPRN_NAME, *it);
580  affectedBy->addChild(affectedByChild);
581  it++;
582  }
583  root->addChild(affectedBy);
584  }
585 
586  if (affects_.size() > 0) {
588  set<string>::const_iterator it = affects_.begin();
589  while (it != affects_.end()) {
591  affectsChild->setAttribute(Operation::OPRN_NAME, *it);
592  affects->addChild(affectsChild);
593  it++;
594  }
595  root->addChild(affects);
596  }
597 
598  for (unsigned int i = 0; i < inputOperands_.size(); i++) {
599  ObjectState* operand = inputOperands_[i]->saveState();
600  operand->setName(Operation::OPRN_IN);
601  root->addChild(operand);
602  }
603 
604  for (unsigned int i = 0; i < outputOperands_.size(); i++) {
605  ObjectState* operand = outputOperands_[i]->saveState();
606  operand->setName(Operation::OPRN_OUT);
607  root->addChild(operand);
608  }
609 
610  for (int i = 0; i < dagCount(); i++) {
612  trigger->setValue(dagCode(i));
613  root->addChild(trigger);
614  }
615 
616  return root;
617 }

References ObjectState::addChild(), affectedBy(), affectedBy_, affects(), affects_, canTrap_, controlFlowOperation_, dagCode(), dagCount(), description_, hasSideEffects_, inputOperands_, inputs_, isBranch_, isCall_, isClocked_, name_, operand(), Operation::OPRN_AFFECTED_BY, Operation::OPRN_AFFECTS, Operation::OPRN_CLOCKED, Operation::OPRN_CONTROL_FLOW, Operation::OPRN_DESCRIPTION, Operation::OPRN_IN, Operation::OPRN_INPUTS, Operation::OPRN_ISBRANCH, Operation::OPRN_ISCALL, Operation::OPRN_NAME, Operation::OPRN_OPERATION, Operation::OPRN_OUT, Operation::OPRN_OUTPUTS, Operation::OPRN_READS_MEMORY, Operation::OPRN_SIDE_EFFECTS, Operation::OPRN_TRAP, Operation::OPRN_TRIGGER, Operation::OPRN_WRITES_MEMORY, outputOperands_, outputs_, readsMemory_, ObjectState::setAttribute(), ObjectState::setValue(), and writesMemory_.

Referenced by Operation::saveState().

Here is the call graph for this function:

◆ setBehavior()

void OperationPimpl::setBehavior ( OperationBehavior behavior)
private

Sets the behavior for operation.

Parameters
behaviorBehavior for an operation.

Definition at line 323 of file OperationPimpl.cc.

323  {
324  behavior_ = &behavior;
325 }

References behavior(), and behavior_.

Referenced by Operation::setBehavior().

Here is the call graph for this function:

◆ setBranch()

void OperationPimpl::setBranch ( bool  setting)

Sets property of operation indicating that the operation is branch changing control flow.

Definition at line 861 of file OperationPimpl.cc.

861  {
862  isBranch_ = setting;
863 }

References isBranch_.

Referenced by Operation::setBranch().

◆ setCall()

void OperationPimpl::setCall ( bool  setting)

Sets property of operation indicating that the operation is function call.

Definition at line 852 of file OperationPimpl.cc.

852  {
853  isCall_ = setting;
854 }

References isCall_.

Referenced by Operation::setCall().

◆ setControlFlowOperation()

void OperationPimpl::setControlFlowOperation ( bool  setting)

Sets property of operation indicating that the operation is changing control flow.

Definition at line 844 of file OperationPimpl.cc.

844  {
845  controlFlowOperation_ = setting;
846 }

References controlFlowOperation_.

Referenced by Operation::setControlFlowOperation().

◆ setDagCode()

void OperationPimpl::setDagCode ( int  index,
const TCEString code 
)
private

Set new source code for DAG and automatically tries to compile latest version to object.

Parameters
indexIndex of DAG whose source code is updated.
codeNew source code in DAG Osal Language.

Definition at line 232 of file OperationPimpl.cc.

232  {
233  dags_[index].code = code;
234  if (!dags_[index].dag->isNull()) {
235  delete dags_[index].dag;
236  dags_[index].dag = &OperationDAG::null;
237  }
238  dags_[index].compilationFailed = false;
239 }

References dag(), dags_, OperationDAG::isNull(), and OperationDAG::null.

Referenced by Operation::setDagCode().

Here is the call graph for this function:

◆ setReadsMemory()

void OperationPimpl::setReadsMemory ( bool  setting)
private

Specifies if operation reads memory.

Definition at line 869 of file OperationPimpl.cc.

869  {
870  readsMemory_ = setting;
871 }

References readsMemory_.

Referenced by Operation::setReadsMemory().

◆ setWritesMemory()

void OperationPimpl::setWritesMemory ( bool  setting)
private

Specifies if operation writes memory.

Definition at line 877 of file OperationPimpl.cc.

877  {
878  writesMemory_ = setting;
879 }

References writesMemory_.

Referenced by Operation::setWritesMemory().

◆ simulateTrigger()

bool OperationPimpl::simulateTrigger ( SimValue **  io,
OperationContext context 
) const
private

Simulates the process of starting execution of an operation.

Parameters
ioThe input and output operands.
contextThe operation context.
Returns
True, if all values could be computed, false otherwise.
Exceptions
ExceptionDepends on the operation behavior.

Definition at line 750 of file OperationPimpl.cc.

752  {
753 
754  return behavior_->simulateTrigger(io, context);
755 }

References behavior_, and OperationBehavior::simulateTrigger().

Referenced by Operation::simulateTrigger().

Here is the call graph for this function:

◆ usesMemory()

bool OperationPimpl::usesMemory ( ) const
inlineprivate

Referenced by Operation::usesMemory().

◆ writesMemory()

bool OperationPimpl::writesMemory ( ) const
inlineprivate

Referenced by Operation::writesMemory().

Friends And Related Function Documentation

◆ Operation

friend class Operation
friend

Definition at line 56 of file OperationPimpl.hh.

Member Data Documentation

◆ affectedBy_

std::set<std::string> OperationPimpl::affectedBy_
private

Operations that are affected by this Operation.

Definition at line 182 of file OperationPimpl.hh.

Referenced by affectedBy(), affectedByCount(), clear(), dependsOn(), loadState(), and saveState().

◆ affects_

std::set<std::string> OperationPimpl::affects_
private

Operations that affects this Operation.

Definition at line 180 of file OperationPimpl.hh.

Referenced by affects(), affectsCount(), clear(), dependsOn(), loadState(), and saveState().

◆ behavior_

OperationBehavior* OperationPimpl::behavior_
private

The behavior of the Operation.

Definition at line 155 of file OperationPimpl.hh.

Referenced by behavior(), canBeSimulated(), createState(), deleteState(), setBehavior(), and simulateTrigger().

◆ canTrap_

bool OperationPimpl::canTrap_
private

Flag indicating if Operation can trap.

Definition at line 172 of file OperationPimpl.hh.

Referenced by canTrap(), clear(), loadState(), and saveState().

◆ controlFlowOperation_

bool OperationPimpl::controlFlowOperation_
private

Flag indicating if the Operation can change program flow.

Definition at line 178 of file OperationPimpl.hh.

Referenced by clear(), isControlFlowOperation(), loadState(), saveState(), and setControlFlowOperation().

◆ dags_

DAGContainer OperationPimpl::dags_
mutableprivate

Table of DAGs and their source codes of an operation.

Definition at line 161 of file OperationPimpl.hh.

Referenced by addDag(), clear(), dag(), dagCode(), dagCount(), dagError(), removeDag(), and setDagCode().

◆ description_

std::string OperationPimpl::description_
private

Description of the Operation.

Definition at line 159 of file OperationPimpl.hh.

Referenced by description(), loadState(), and saveState().

◆ hasSideEffects_

bool OperationPimpl::hasSideEffects_
private

Flag indicating if Operation has side effects.

Definition at line 174 of file OperationPimpl.hh.

Referenced by clear(), hasSideEffects(), loadState(), and saveState().

◆ inputOperands_

std::vector<Operand*> OperationPimpl::inputOperands_
private

Input Operands of the Operation.

Definition at line 184 of file OperationPimpl.hh.

Referenced by addInput(), clear(), fetchOperand(), loadState(), operand(), and saveState().

◆ inputs_

int OperationPimpl::inputs_
private

The number of inputs of the Operation.

Definition at line 164 of file OperationPimpl.hh.

Referenced by addInput(), clear(), loadState(), and saveState().

◆ isBranch_

bool OperationPimpl::isBranch_
private

Flag indicating if Operation is branch changing control flow.

Definition at line 190 of file OperationPimpl.hh.

Referenced by clear(), isBranch(), loadState(), saveState(), and setBranch().

◆ isCall_

bool OperationPimpl::isCall_
private

Flag indicating if Operation is call.

Definition at line 188 of file OperationPimpl.hh.

Referenced by clear(), isCall(), loadState(), saveState(), and setCall().

◆ isClocked_

bool OperationPimpl::isClocked_
private

Flag indicating if Operation is clocked and needs AdvanceClock.

Definition at line 176 of file OperationPimpl.hh.

Referenced by isClocked(), loadState(), and saveState().

◆ name_

std::string OperationPimpl::name_
private

Name of the Operation.

Definition at line 157 of file OperationPimpl.hh.

Referenced by clear(), loadState(), name(), and saveState().

◆ outputOperands_

std::vector<Operand*> OperationPimpl::outputOperands_
private

Output Operands of the Operation.

Definition at line 186 of file OperationPimpl.hh.

Referenced by addOutput(), clear(), fetchOperand(), loadState(), operand(), output(), and saveState().

◆ outputs_

int OperationPimpl::outputs_
private

The number of outputs of the Operation.

Definition at line 166 of file OperationPimpl.hh.

Referenced by addOutput(), clear(), loadState(), and saveState().

◆ readsMemory_

bool OperationPimpl::readsMemory_
private

Flag indicating if Operation reads from memory.

Definition at line 168 of file OperationPimpl.hh.

Referenced by clear(), loadState(), saveState(), and setReadsMemory().

◆ writesMemory_

bool OperationPimpl::writesMemory_
private

Flag indicating if Operation writes to memory.

Definition at line 170 of file OperationPimpl.hh.

Referenced by clear(), loadState(), saveState(), and setWritesMemory().


The documentation for this class was generated from the following files:
Operand
Definition: Operand.hh:52
OperationPimpl::affects_
std::set< std::string > affects_
Operations that affects this Operation.
Definition: OperationPimpl.hh:180
OperationBehavior::canBeSimulated
virtual bool canBeSimulated() const
Definition: OperationBehavior.cc:162
OperationPimpl::name
TCEString name() const
Definition: OperationPimpl.cc:121
OperationDAG::isNull
bool isNull() const
Definition: OperationDAG.hh:48
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
OperationPimpl::clear
void clear()
Definition: OperationPimpl.cc:88
ObjectStateLoadingException
Definition: Exception.hh:551
Operation::OPRN_IN
static const char * OPRN_IN
Object state name for input operand.
Definition: Operation.hh:91
OutOfRange
Definition: Exception.hh:320
OperationPimpl::inputs_
int inputs_
The number of inputs of the Operation.
Definition: OperationPimpl.hh:164
Operation::OPRN_NAME
static const char * OPRN_NAME
Object state name for name.
Definition: Operation.hh:67
ObjectState
Definition: ObjectState.hh:59
NullOperand::instance
static NullOperand & instance()
Operation::OPRN_AFFECTS
static const char * OPRN_AFFECTS
Object state name for affects.
Definition: Operation.hh:87
OperationDAG::null
static OperationDAG null
Definition: OperationDAG.hh:47
OperationPimpl::affectedBy_
std::set< std::string > affectedBy_
Operations that are affected by this Operation.
Definition: OperationPimpl.hh:182
Operation::name
virtual TCEString name() const
Definition: Operation.cc:93
OperationPimpl::canTrap_
bool canTrap_
Flag indicating if Operation can trap.
Definition: OperationPimpl.hh:172
Operation::OPRN_AFFECTED_BY
static const char * OPRN_AFFECTED_BY
Object state name for affected by.
Definition: Operation.hh:89
Conversion::toString
static std::string toString(const T &source)
OperationBehavior::createState
virtual void createState(OperationContext &context) const
Definition: OperationBehavior.cc:127
OperationPimpl::outputs_
int outputs_
The number of outputs of the Operation.
Definition: OperationPimpl.hh:166
OperationPimpl::name_
std::string name_
Name of the Operation.
Definition: OperationPimpl.hh:157
OperationPimpl::dagCode
TCEString dagCode(int index) const
Definition: OperationPimpl.cc:220
OperationBehavior::simulateTrigger
virtual bool simulateTrigger(SimValue **io, OperationContext &context) const =0
Definition: OperationBehavior.cc:83
StringTools::stringToUpper
static std::string stringToUpper(const std::string &source)
Definition: StringTools.cc:143
OperationPimpl::dagCount
int dagCount() const
Definition: OperationPimpl.cc:172
OperationPimpl::outputOperands_
std::vector< Operand * > outputOperands_
Output Operands of the Operation.
Definition: OperationPimpl.hh:186
OperationPimpl::numberOfOutputs
int numberOfOutputs() const
assert
#define assert(condition)
Definition: Application.hh:86
Operation::OPRN_CONTROL_FLOW
static const char * OPRN_CONTROL_FLOW
Object state name for control flow property.
Definition: Operation.hh:81
SequenceTools::deleteAllItems
static void deleteAllItems(SequenceType &aSequence)
OperationPimpl::isClocked_
bool isClocked_
Flag indicating if Operation is clocked and needs AdvanceClock.
Definition: OperationPimpl.hh:176
Operation::OPRN_DESCRIPTION
static const char * OPRN_DESCRIPTION
Object state name for description.
Definition: Operation.hh:69
IllegalParameters
Definition: Exception.hh:113
Operation::OPRN_TRAP
static const char * OPRN_TRAP
Object state name for trap.
Definition: Operation.hh:75
Operation::OPRN_TRIGGER
static const char * OPRN_TRIGGER
Object state name for trigger semantics.
Definition: Operation.hh:95
Operand::canSwap
virtual bool canSwap(const Operand &op) const
Definition: Operand.cc:372
Operation::OPRN_OPERATION
static const char * OPRN_OPERATION
Object state name for operation.
Definition: Operation.hh:65
Operation::OPRN_CLOCKED
static const char * OPRN_CLOCKED
Object state name for clockedness.
Definition: Operation.hh:79
Operation::OPRN_ISCALL
static const char * OPRN_ISCALL
Object state name for call property.
Definition: Operation.hh:97
Operand::index
virtual int index() const
Definition: Operand.cc:135
llvmOperandType
std::string llvmOperandType(Operand::OperandType type)
Definition: OperationPimpl.cc:792
OperationPimpl::writesMemory_
bool writesMemory_
Flag indicating if Operation writes to memory.
Definition: OperationPimpl.hh:170
ObjectState::child
ObjectState * child(int index) const
Definition: ObjectState.cc:471
ObjectState::addChild
void addChild(ObjectState *child)
Definition: ObjectState.cc:376
OperationPimpl::affects
TCEString affects(unsigned int i) const
Definition: OperationPimpl.cc:364
Operation::OPRN_WRITES_MEMORY
static const char * OPRN_WRITES_MEMORY
Object state name for writes memory.
Definition: Operation.hh:85
ObjectState::childCount
int childCount() const
OperationPimpl::operand
Operand & operand(int id) const
Definition: OperationPimpl.cc:655
Operand::SINT_WORD
@ SINT_WORD
Definition: Operand.hh:59
Operation::OPRN_READS_MEMORY
static const char * OPRN_READS_MEMORY
Object state name for reads memory.
Definition: Operation.hh:83
Exception
Definition: Exception.hh:54
ObjectState::name
std::string name() const
OperationPimpl::behavior
OperationBehavior & behavior() const
Definition: OperationPimpl.cc:333
Operation::OPRN_OUT
static const char * OPRN_OUT
Object state name for output operand.
Definition: Operation.hh:93
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
Operation::OPRN_INPUTS
static const char * OPRN_INPUTS
Object state name for inputs.
Definition: Operation.hh:71
OperationPimpl::dags_
DAGContainer dags_
Table of DAGs and their source codes of an operation.
Definition: OperationPimpl.hh:161
OperationPimpl::insertOperand
void insertOperand(Operand *operand, std::vector< Operand * > &ops)
Definition: OperationPimpl.cc:723
Operation::OPRN_SIDE_EFFECTS
static const char * OPRN_SIDE_EFFECTS
Object state name for side effects.
Definition: Operation.hh:77
Operand::type
virtual OperandType type() const
Definition: Operand.cc:165
OperationBehavior::deleteState
virtual void deleteState(OperationContext &context) const
Definition: OperationBehavior.cc:141
ObjectState::boolAttribute
bool boolAttribute(const std::string &name) const
Definition: ObjectState.cc:338
OperationPimpl::fetchOperand
Operand & fetchOperand(int id, const std::vector< Operand * > &ops) const
Definition: OperationPimpl.cc:674
OperationPimpl::behavior_
OperationBehavior * behavior_
The behavior of the Operation.
Definition: OperationPimpl.hh:155
OperationPimpl::isBranch_
bool isBranch_
Flag indicating if Operation is branch changing control flow.
Definition: OperationPimpl.hh:190
ObjectState::stringValue
std::string stringValue() const
OperationPimpl::inputOperands_
std::vector< Operand * > inputOperands_
Input Operands of the Operation.
Definition: OperationPimpl.hh:184
ObjectState::intAttribute
int intAttribute(const std::string &name) const
Definition: ObjectState.cc:276
OperationPimpl::dag
OperationDAG & dag(int index) const
Definition: OperationPimpl.cc:186
OperationPimpl::affectedBy
TCEString affectedBy(unsigned int i) const
Definition: OperationPimpl.cc:389
OperationPimpl::readsMemory_
bool readsMemory_
Flag indicating if Operation reads from memory.
Definition: OperationPimpl.hh:168
OperationPimpl::description_
std::string description_
Description of the Operation.
Definition: OperationPimpl.hh:159
OperationPimpl::hasSideEffects_
bool hasSideEffects_
Flag indicating if Operation has side effects.
Definition: OperationPimpl.hh:174
OperationPimpl::addDag
void addDag(const TCEString &code)
Definition: OperationPimpl.cc:140
ObjectState::setValue
void setValue(const std::string &value)
Operation::OPRN_ISBRANCH
static const char * OPRN_ISBRANCH
Object state name for branch property.
Definition: Operation.hh:99
Operation::OPRN_OUTPUTS
static const char * OPRN_OUTPUTS
Object state name for outputs.
Definition: Operation.hh:73
OperationPimpl::controlFlowOperation_
bool controlFlowOperation_
Flag indicating if the Operation can change program flow.
Definition: OperationPimpl.hh:178
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100
OperationDAGConverter::createDAG
static OperationDAG * createDAG(const OperationPimpl &operation, std::string sourceCode)
Definition: OperationDAGConverter.cc:61
Operand::loadState
virtual void loadState(const ObjectState *state)
Definition: Operand.cc:383
OperationPimpl::isCall_
bool isCall_
Flag indicating if Operation is call.
Definition: OperationPimpl.hh:188
OperationPimpl::numberOfInputs
int numberOfInputs() const