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

#include <OperationBehaviorProxy.hh>

Inheritance diagram for OperationBehaviorProxy:
Inheritance graph
Collaboration diagram for OperationBehaviorProxy:
Collaboration graph

Public Member Functions

 OperationBehaviorProxy (Operation &targetOperation, OperationBehaviorLoader &loader, bool alwaysReloadBehavior=false)
 
virtual ~OperationBehaviorProxy ()
 
virtual bool simulateTrigger (SimValue **io, OperationContext &context) const
 
virtual bool canBeSimulated () const
 
virtual void createState (OperationContext &context) const
 
virtual void deleteState (OperationContext &context) const
 
virtual void setAlwaysReloadBehavior (bool f)
 
void uninitializeBehavior () const
 
- Public Member Functions inherited from OperationBehavior
virtual bool areValid (const InputOperandVector &inputs, const OperationContext &context) const
 
virtual const char * stateName () const
 
virtual void writeOutput (const char *text) const
 
 OperationBehavior ()
 
 OperationBehavior (const Operation &parent)
 
virtual ~OperationBehavior ()
 

Private Member Functions

 OperationBehaviorProxy (const OperationBehaviorProxy &)
 Copying not allowed. More...
 
OperationBehaviorProxyoperator= (const OperationBehaviorProxy &)
 Assignment not allowed. More...
 
void initializeBehavior () const
 

Private Attributes

Operationtarget_
 Operation that owns this proxy;. More...
 
OperationBehaviorLoaderloader_
 Used to load behavior model for operation. More...
 
bool initialized_
 Flag indicating whether proxy is initialized or not. More...
 
std::set< OperationDAGBehavior * > cleanUs_
 Clean up list for created OperationDAGBehaviors. More...
 
bool alwaysReloadBehavior_
 If this is true, the behavior is always (re)loaded from the dynamic library or the DAG instead of loading it once and reusing in the future calls. More...
 
bool alreadyCreatingState_
 Helpers variable to catch infinite recursive function call due to missing or undefined operation behavior. More...
 

Additional Inherited Members

- Public Types inherited from OperationBehavior
typedef std::vector< SimValueInputOperandVector
 Input operand type for areValid() More...
 
- Protected Attributes inherited from OperationBehavior
const Operationparent_
 

Detailed Description

This class is used to create a behavior model of an operation.

A first time operation calls simulateTrigger() proxy creates the appropriate operation behavior model for the operation. Proxy replaces itself in the operation with the newly created behavior model. That new model then executes all simulation functions.

Definition at line 58 of file OperationBehaviorProxy.hh.

Constructor & Destructor Documentation

◆ OperationBehaviorProxy() [1/2]

OperationBehaviorProxy::OperationBehaviorProxy ( Operation targetOperation,
OperationBehaviorLoader loader,
bool  alwaysReloadBehavior = false 
)

Constructor.

Registers the operation for which this proxy represents the behavior model. Registers the operation behavior loader that is used to find the appropriate behavior model of the operation.

Parameters
targetOperationTarget operation for proxy.
loaderOperation behavior loader for the proxy.

Definition at line 56 of file OperationBehaviorProxy.cc.

59  :
60  OperationBehavior(), target_(&targetOperation), loader_(&loader),
61  initialized_(false), alwaysReloadBehavior_(alwaysReloadBehavior),
62  alreadyCreatingState_(false) {
63 }

◆ ~OperationBehaviorProxy()

OperationBehaviorProxy::~OperationBehaviorProxy ( )
virtual

Destructor.

Operation behavior loader frees all loaded operation behavior models.

Definition at line 70 of file OperationBehaviorProxy.cc.

70  {
71  while (!cleanUs_.empty()) {
72  delete *(cleanUs_.begin());
73  cleanUs_.erase(cleanUs_.begin());
74  }
75 }

References cleanUs_.

◆ OperationBehaviorProxy() [2/2]

OperationBehaviorProxy::OperationBehaviorProxy ( const OperationBehaviorProxy )
private

Copying not allowed.

Member Function Documentation

◆ canBeSimulated()

bool OperationBehaviorProxy::canBeSimulated ( ) const
virtual

Imports operation behavior model for the operation that owns this proxy and then delegates the work to that imported model.

After initializing the operation with imported operation behavior model proxy has done its job.

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

Reimplemented from OperationBehavior.

Definition at line 162 of file OperationBehaviorProxy.cc.

162  {
163  try {
165  } catch (Exception&) {
167  return false;
168  }
169  // if initialization was not success
170  if (&target_->behavior() == this) {
172  return false;
173  } else {
174  bool retVal = target_->canBeSimulated();
176  return retVal;
177  }
178 }

References alwaysReloadBehavior_, Operation::behavior(), Operation::canBeSimulated(), initializeBehavior(), target_, and uninitializeBehavior().

Here is the call graph for this function:

◆ createState()

void OperationBehaviorProxy::createState ( OperationContext context) const
virtual

Imports operation behavior model for the operation that owns this proxy and then delegates the work to that imported model.

After initializing the operation with imported operation behavior model proxy has done its job.

Parameters
contextThe operation context to add the state in.

Reimplemented from OperationBehavior.

Definition at line 111 of file OperationBehaviorProxy.cc.

111  {
113 
114  // If operation does not have operation behavior defined or behavior file
115  // is missing it causes infinite recursive call between
116  // Operation::createState() and this function. Catch such event and break
117  // out of it.
118  if (alreadyCreatingState_) {
119  throw IllegalOperationBehavior(__FILE__, __LINE__, __func__,
120  std::string("Error while loading operation behavior for "
121  "operation \"")
122  + target_->name()
123  + "\". Operation behavior is undefined or missing.");
124  }
125  alreadyCreatingState_ = true;
126 
127  target_->createState(context);
128 
129  if (alwaysReloadBehavior_) {
131  }
132  alreadyCreatingState_ = true;
133 }

References __func__, alreadyCreatingState_, alwaysReloadBehavior_, Operation::createState(), initializeBehavior(), Operation::name(), target_, and uninitializeBehavior().

Here is the call graph for this function:

◆ deleteState()

void OperationBehaviorProxy::deleteState ( OperationContext context) const
virtual

Imports operation behavior model for the operation that owns this proxy and then delegates the work to that imported model.

After initializing the operation with imported operation behavior model proxy has done its job.

Parameters
contextThe operation context to delete the state from.

Reimplemented from OperationBehavior.

Definition at line 145 of file OperationBehaviorProxy.cc.

145  {
147  target_->deleteState(context);
149 }

References alwaysReloadBehavior_, Operation::deleteState(), initializeBehavior(), target_, and uninitializeBehavior().

Here is the call graph for this function:

◆ initializeBehavior()

void OperationBehaviorProxy::initializeBehavior ( ) const
private

Initializes the operation that owns this proxy with an operation behavior model.

Proxy replaces itself with the imported operation behavior model. After that proxy methods are never called.

This method is executed only once. After that, this function does nothing. This function may abort the program, if error condition occurs while operation behavior model is imported.

Exceptions
DynamicLibraryExceptionLeaked from importBehavior in case behavior file was invalid.

Definition at line 195 of file OperationBehaviorProxy.cc.

195  {
196 
197  if (initialized_) {
198  return;
199  }
200 
201  try {
203  target_->setBehavior(ob);
204  return;
205  } catch (FileNotFound&) {
206  } catch (SymbolNotFound& e) {
207  // try loading behavior from DAG
208  if (target_->dagCount() == 0) {
209  throw e;
210  }
211  } catch (Exception& e) {
212  throw e;
213  }
214 
215  // no compiled behavior in .opb found
216 
217  // if there is DAG to create behavior model...
218  if (target_->dagCount() == 0) {
219  initialized_ = true;
220  return;
221  }
222 
223  // there was not behavior plugin so let's use dag for simulation
224  OperationDAGBehavior* behavior =
226  target_->dag(0),
227  target_->numberOfInputs() +
229  *target_);
230  target_->setBehavior(*behavior);
231 
232  // add for cleanup
233  cleanUs_.insert(behavior);
234 
235  initialized_ = true;
236 }

References cleanUs_, Operation::dag(), Operation::dagCount(), OperationBehaviorLoader::importBehavior(), initialized_, loader_, Operation::numberOfInputs(), Operation::numberOfOutputs(), Operation::setBehavior(), and target_.

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

Here is the call graph for this function:

◆ operator=()

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

Assignment not allowed.

◆ setAlwaysReloadBehavior()

virtual void OperationBehaviorProxy::setAlwaysReloadBehavior ( bool  f)
inlinevirtual

Definition at line 76 of file OperationBehaviorProxy.hh.

76 { alwaysReloadBehavior_ = f; }

References alwaysReloadBehavior_.

Referenced by SimulateDialog::~SimulateDialog().

◆ simulateTrigger()

bool OperationBehaviorProxy::simulateTrigger ( SimValue **  io,
OperationContext context 
) const
virtual

Imports operation behavior model for the operation that owns this proxy and then delegates the work to that imported model.

After initializing the operation with imported operation behavior model proxy has done its job.

Parameters
ioThe input and output operands.
contextThe operation context.
Returns
True if all values could be computed, false otherwise.
Exceptions
IllegalOperationBehaviorIf trigger command lacks return statement.

Implements OperationBehavior.

Definition at line 91 of file OperationBehaviorProxy.cc.

93  {
94 
96  bool retVal = target_->simulateTrigger(io, context);
98  return retVal;
99 }

References alwaysReloadBehavior_, initializeBehavior(), Operation::simulateTrigger(), target_, and uninitializeBehavior().

Here is the call graph for this function:

◆ uninitializeBehavior()

void OperationBehaviorProxy::uninitializeBehavior ( ) const

Uninitializes the behavior description from the operation so it will be reloaded again when a behavior method is called the next time.

Definition at line 244 of file OperationBehaviorProxy.cc.

244  {
245  while (!cleanUs_.empty()) {
246  OperationBehavior* behavior = *cleanUs_.begin();
247  delete behavior;
248  cleanUs_.erase(cleanUs_.begin());
249  }
250  target_->setBehavior(const_cast<OperationBehaviorProxy&>(*this));
252  initialized_ = false;
253 }

References cleanUs_, OperationBehaviorLoader::freeBehavior(), initialized_, loader_, Operation::setBehavior(), and target_.

Referenced by canBeSimulated(), createState(), deleteState(), simulateTrigger(), and SimulateDialog::~SimulateDialog().

Here is the call graph for this function:

Member Data Documentation

◆ alreadyCreatingState_

bool OperationBehaviorProxy::alreadyCreatingState_
mutableprivate

Helpers variable to catch infinite recursive function call due to missing or undefined operation behavior.

Definition at line 101 of file OperationBehaviorProxy.hh.

Referenced by createState().

◆ alwaysReloadBehavior_

bool OperationBehaviorProxy::alwaysReloadBehavior_
private

If this is true, the behavior is always (re)loaded from the dynamic library or the DAG instead of loading it once and reusing in the future calls.

Definition at line 98 of file OperationBehaviorProxy.hh.

Referenced by canBeSimulated(), createState(), deleteState(), setAlwaysReloadBehavior(), and simulateTrigger().

◆ cleanUs_

std::set<OperationDAGBehavior*> OperationBehaviorProxy::cleanUs_
mutableprivate

Clean up list for created OperationDAGBehaviors.

Definition at line 94 of file OperationBehaviorProxy.hh.

Referenced by initializeBehavior(), uninitializeBehavior(), and ~OperationBehaviorProxy().

◆ initialized_

bool OperationBehaviorProxy::initialized_
mutableprivate

Flag indicating whether proxy is initialized or not.

Definition at line 92 of file OperationBehaviorProxy.hh.

Referenced by initializeBehavior(), and uninitializeBehavior().

◆ loader_

OperationBehaviorLoader* OperationBehaviorProxy::loader_
private

Used to load behavior model for operation.

Definition at line 90 of file OperationBehaviorProxy.hh.

Referenced by initializeBehavior(), and uninitializeBehavior().

◆ target_

Operation* OperationBehaviorProxy::target_
private

The documentation for this class was generated from the following files:
OperationBehaviorLoader::importBehavior
OperationBehavior & importBehavior(const Operation &parent)
Definition: OperationBehaviorLoader.cc:91
OperationBehaviorProxy::alwaysReloadBehavior_
bool alwaysReloadBehavior_
If this is true, the behavior is always (re)loaded from the dynamic library or the DAG instead of loa...
Definition: OperationBehaviorProxy.hh:98
FileNotFound
Definition: Exception.hh:224
OperationDAGBehavior
Definition: OperationDAGBehavior.hh:54
Operation::numberOfInputs
virtual int numberOfInputs() const
Definition: Operation.cc:192
Operation::canBeSimulated
virtual bool canBeSimulated() const
Definition: Operation.cc:612
IllegalOperationBehavior
Definition: Exception.hh:844
Operation::name
virtual TCEString name() const
Definition: Operation.cc:93
OperationBehaviorProxy::target_
Operation * target_
Operation that owns this proxy;.
Definition: OperationBehaviorProxy.hh:88
OperationBehaviorProxy::initialized_
bool initialized_
Flag indicating whether proxy is initialized or not.
Definition: OperationBehaviorProxy.hh:92
Operation::setBehavior
virtual void setBehavior(OperationBehavior &behavior)
Definition: Operation.cc:378
OperationBehavior::OperationBehavior
OperationBehavior()
Definition: OperationBehavior.cc:52
SymbolNotFound
Definition: Exception.hh:623
OperationBehaviorProxy
Definition: OperationBehaviorProxy.hh:58
OperationBehaviorProxy::initializeBehavior
void initializeBehavior() const
Definition: OperationBehaviorProxy.cc:195
__func__
#define __func__
Definition: Application.hh:67
Exception
Definition: Exception.hh:54
Operation::deleteState
virtual void deleteState(OperationContext &context) const
Definition: Operation.cc:601
OperationBehaviorProxy::uninitializeBehavior
void uninitializeBehavior() const
Definition: OperationBehaviorProxy.cc:244
Operation::createState
virtual void createState(OperationContext &context) const
Definition: Operation.cc:590
Operation::dagCount
virtual int dagCount() const
Definition: Operation.cc:134
OperationBehavior
Definition: OperationBehavior.hh:53
OperationBehaviorLoader::freeBehavior
void freeBehavior()
Definition: OperationBehaviorLoader.cc:136
Operation::simulateTrigger
virtual bool simulateTrigger(SimValue **, OperationContext &context) const
Definition: Operation.cc:555
Operation::behavior
virtual OperationBehavior & behavior() const
Definition: Operation.cc:388
OperationBehaviorProxy::alreadyCreatingState_
bool alreadyCreatingState_
Helpers variable to catch infinite recursive function call due to missing or undefined operation beha...
Definition: OperationBehaviorProxy.hh:101
OperationBehaviorProxy::cleanUs_
std::set< OperationDAGBehavior * > cleanUs_
Clean up list for created OperationDAGBehaviors.
Definition: OperationBehaviorProxy.hh:94
Operation::numberOfOutputs
virtual int numberOfOutputs() const
Definition: Operation.cc:202
OperationBehaviorProxy::loader_
OperationBehaviorLoader * loader_
Used to load behavior model for operation.
Definition: OperationBehaviorProxy.hh:90
Operation::dag
virtual OperationDAG & dag(int index) const
Definition: Operation.cc:148