OpenASIP 2.2
Loading...
Searching...
No Matches
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.
 
OperationPimploperator= (const OperationPimpl &)
 Assignment not allowed.
 
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.
 
std::string name_
 Name of the Operation.
 
std::string description_
 Description of the Operation.
 
DAGContainer dags_
 Table of DAGs and their source codes of an operation.
 
int inputs_
 The number of inputs of the Operation.
 
int outputs_
 The number of outputs of the Operation.
 
bool readsMemory_
 Flag indicating if Operation reads from memory.
 
bool writesMemory_
 Flag indicating if Operation writes to memory.
 
bool canTrap_
 Flag indicating if Operation can trap.
 
bool hasSideEffects_
 Flag indicating if Operation has side effects.
 
bool isClocked_
 Flag indicating if Operation is clocked and needs AdvanceClock.
 
bool controlFlowOperation_
 Flag indicating if the Operation can change program flow.
 
std::set< std::string > affects_
 Operations that affects this Operation.
 
std::set< std::string > affectedBy_
 Operations that are affected by this Operation.
 
std::vector< Operand * > inputOperands_
 Input Operands of the Operation.
 
std::vector< Operand * > outputOperands_
 Output Operands of the Operation.
 
bool isCall_
 Flag indicating if Operation is call.
 
bool isBranch_
 Flag indicating if Operation is branch changing control flow.
 

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}
OperationBehavior * behavior_
The behavior of the Operation.
std::string name_
Name of the Operation.
std::string description_
Description of the Operation.
bool writesMemory_
Flag indicating if Operation writes to memory.
int inputs_
The number of inputs of the Operation.
bool controlFlowOperation_
Flag indicating if the Operation can change program flow.
TCEString name() const
bool hasSideEffects_
Flag indicating if Operation has side effects.
int outputs_
The number of outputs of the Operation.
bool isCall_
Flag indicating if Operation is call.
bool readsMemory_
Flag indicating if Operation reads from memory.
OperationBehavior & behavior() const
bool canTrap_
Flag indicating if Operation can trap.
bool isClocked_
Flag indicating if Operation is clocked and needs AdvanceClock.
bool isBranch_
Flag indicating if Operation is branch changing control flow.
static std::string stringToUpper(const std::string &source)

◆ 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}
static OperationDAG null
DAGContainer dags_
Table of DAGs and their source codes of an operation.

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}
std::vector< Operand * > inputOperands_
Input Operands of the Operation.
Operand & operand(int id) const

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}
std::vector< Operand * > outputOperands_
Output Operands of the Operation.

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}
std::set< std::string > affectedBy_
Operations that are affected by this Operation.

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}
std::set< std::string > affects_
Operations that affects this Operation.

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}
virtual bool canBeSimulated() const

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}
static NullOperand & instance()
virtual bool canSwap(const Operand &op) const
Definition Operand.cc:372
Operand & fetchOperand(int id, const std::vector< Operand * > &ops) const

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}
bool isNull() const
int dagCount() const
OperationDAG & dag(int index) const
static void deleteAllItems(SequenceType &aSequence)

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}
virtual void createState(OperationContext &context) const

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}
std::string errorMessage() const
Definition Exception.cc:123
static OperationDAG * createDAG(const OperationPimpl &operation, std::string sourceCode)

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

Referenced by clear(), Operation::dag(), 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}
virtual void deleteState(OperationContext &context) const

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}
virtual TCEString name() const
Definition Operation.cc:93

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}
std::string llvmOperandType(Operand::OperandType type)
static std::string toString(const T &source)
virtual OperandType type() const
Definition Operand.cc:165
int numberOfOutputs() const
int numberOfInputs() const

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}
#define assert(condition)

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}
virtual int index() const
Definition Operand.cc:135

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 {
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}
ObjectState * child(int index) const
std::string stringAttribute(const std::string &name) const
bool boolAttribute(const std::string &name) const
int intAttribute(const std::string &name) const
std::string stringValue() const
std::string name() const
int childCount() const
@ SINT_WORD
Definition Operand.hh:59
virtual void loadState(const ObjectState *state)
Definition Operand.cc:383
void insertOperand(Operand *operand, std::vector< Operand * > &ops)
TCEString affectedBy(unsigned int i) const
TCEString affects(unsigned int i) const
void addDag(const TCEString &code)
static const char * OPRN_CONTROL_FLOW
Object state name for control flow property.
Definition Operation.hh:81
static const char * OPRN_ISBRANCH
Object state name for branch property.
Definition Operation.hh:99
static const char * OPRN_DESCRIPTION
Object state name for description.
Definition Operation.hh:69
static const char * OPRN_IN
Object state name for input operand.
Definition Operation.hh:91
static const char * OPRN_CLOCKED
Object state name for clockedness.
Definition Operation.hh:79
static const char * OPRN_TRAP
Object state name for trap.
Definition Operation.hh:75
static const char * OPRN_AFFECTED_BY
Object state name for affected by.
Definition Operation.hh:89
static const char * OPRN_TRIGGER
Object state name for trigger semantics.
Definition Operation.hh:95
static const char * OPRN_ISCALL
Object state name for call property.
Definition Operation.hh:97
static const char * OPRN_SIDE_EFFECTS
Object state name for side effects.
Definition Operation.hh:77
static const char * OPRN_READS_MEMORY
Object state name for reads memory.
Definition Operation.hh:83
static const char * OPRN_OUT
Object state name for output operand.
Definition Operation.hh:93
static const char * OPRN_OUTPUTS
Object state name for outputs.
Definition Operation.hh:73
static const char * OPRN_NAME
Object state name for name.
Definition Operation.hh:67
static const char * OPRN_INPUTS
Object state name for inputs.
Definition Operation.hh:71
static const char * OPRN_AFFECTS
Object state name for affects.
Definition Operation.hh:87
static const char * OPRN_WRITES_MEMORY
Object state name for writes memory.
Definition Operation.hh:85

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

◆ 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++) {
600 operand->setName(Operation::OPRN_IN);
601 root->addChild(operand);
602 }
603
604 for (unsigned int i = 0; i < outputOperands_.size(); i++) {
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}
void setAttribute(const std::string &name, const std::string &value)
void setValue(const std::string &value)
void addChild(ObjectState *child)
virtual ObjectState * saveState() const
Definition Operand.cc:490
TCEString dagCode(int index) const
static const char * OPRN_OPERATION
Object state name for operation.
Definition Operation.hh:65

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_, Operand::saveState(), 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 {
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}
virtual bool simulateTrigger(SimValue **io, OperationContext &context) const =0

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 Symbol 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: