OpenASIP  2.0
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
TTAMachine::OperationTriggeredFormat Class Reference

#include <OperationTriggeredFormat.hh>

Inheritance diagram for TTAMachine::OperationTriggeredFormat:
Inheritance graph
Collaboration diagram for TTAMachine::OperationTriggeredFormat:
Collaboration graph

Public Member Functions

 OperationTriggeredFormat (const std::string &name, Machine &owner)
 
 OperationTriggeredFormat (const ObjectState *state, Machine &owner)
 
virtual ~OperationTriggeredFormat ()
 
void addOperation (const std::string &op)
 
void removeOperation (const std::string &op)
 
std::vector< std::string > operations () const
 
int operationCount () const
 
std::string operation (int index) const
 
bool hasOperation (const std::string &opName) const
 
void addOperand (OperationTriggeredOperand &operand)
 
std::vector< OperationTriggeredOperand * > operands () const
 
virtual void setMachine (Machine &machine)
 
virtual void unsetMachine ()
 
virtual void loadState (const ObjectState *state)
 
virtual ObjectStatesaveState () const
 
- Public Member Functions inherited from TTAMachine::Component
virtual ~Component ()
 
virtual TCEString name () const
 
virtual void setName (const std::string &name)
 
virtual Machinemachine () const
 
virtual void ensureRegistration (const Component &component) const
 
virtual bool isRegistered () const
 
- Public Member Functions inherited from Serializable
virtual ~Serializable ()
 

Static Public Attributes

static const std::string OSNAME_FORMAT = "ota-format"
 
static const std::string OSKEY_OPERATION = "ota-operation"
 
- Static Public Attributes inherited from TTAMachine::Component
static const std::string OSNAME_COMPONENT = "component"
 ObjectState name for component. More...
 
static const std::string OSKEY_NAME = "name"
 ObjectState attribute key for the name of the component. More...
 

Private Attributes

std::vector< std::string > operations_
 
std::vector< OperationTriggeredOperand * > operands_
 

Additional Inherited Members

- Protected Member Functions inherited from TTAMachine::Component
 Component (const std::string &name)
 
 Component (const ObjectState *state)
 
void internalSetMachine (Machine &machine)
 
void internalUnsetMachine ()
 
- Protected Member Functions inherited from TTAMachine::MachinePart
 MachinePart ()
 
virtual ~MachinePart ()
 

Detailed Description

Definition at line 44 of file OperationTriggeredFormat.hh.

Constructor & Destructor Documentation

◆ OperationTriggeredFormat() [1/2]

TTAMachine::OperationTriggeredFormat::OperationTriggeredFormat ( const std::string &  name,
Machine owner 
)

The constructor.

Registers the operation code encoding to the parent binary encoding automatically.

Parameters
parentThe parent OperationTriggeredFormat.

Definition at line 56 of file OperationTriggeredFormat.cc.

58  : Component(name) {
59  setMachine(owner);
60 }

References setMachine().

Here is the call graph for this function:

◆ OperationTriggeredFormat() [2/2]

TTAMachine::OperationTriggeredFormat::OperationTriggeredFormat ( const ObjectState state,
Machine owner 
)

The constructor

Loads the state of the operation code encoding from the given ObjectState tree

Parameters
stateThe ObjectState tree
parentThe parent binary encoding map
Exceptions
ObjectStateLoadingExceptionIf an error occurs while loading the state.

Definition at line 74 of file OperationTriggeredFormat.cc.

76  : Component(state) {
77  const std::string procName =
78  "OperationTriggeredFormat::OperationTriggeredFormat";
79  try {
80  setMachine(owner);
81  } catch (const ComponentAlreadyExists&) {
82  MOMTextGenerator textGenerator;
83  boost::format errorMsg =
85  errorMsg % name();
87  __FILE__, __LINE__, procName, errorMsg.str());
88  }
89  try {
90  loadState(state);
91  } catch (const ObjectStateLoadingException&) {
92  unsetMachine();
93  throw;
94  }
95 }

References loadState(), TTAMachine::Component::name(), setMachine(), Texts::TextGenerator::text(), MOMTextGenerator::TXT_IT_EXISTS_BY_NAME, and unsetMachine().

Here is the call graph for this function:

◆ ~OperationTriggeredFormat()

TTAMachine::OperationTriggeredFormat::~OperationTriggeredFormat ( )
virtual

Destructor.

Definition at line 100 of file OperationTriggeredFormat.cc.

100  {
101  for (unsigned int i = 0; i < operands_.size(); i++) {
102  delete operands_.at(i);
103  }
104  unsetMachine();
105 }

References operands_, and unsetMachine().

Here is the call graph for this function:

Member Function Documentation

◆ addOperand()

void TTAMachine::OperationTriggeredFormat::addOperand ( OperationTriggeredOperand operand)

Definition at line 156 of file OperationTriggeredFormat.cc.

156  {
157  operands_.push_back(&op);
158 }

References operands_.

Referenced by TTAMachine::OperationTriggeredOperand::OperationTriggeredOperand().

◆ addOperation()

void TTAMachine::OperationTriggeredFormat::addOperation ( const std::string &  op)

Definition at line 113 of file OperationTriggeredFormat.cc.

113  {
114  operations_.push_back(op);
115 }

References operations_.

◆ hasOperation()

bool TTAMachine::OperationTriggeredFormat::hasOperation ( const std::string &  opName) const

Definition at line 141 of file OperationTriggeredFormat.cc.

141  {
142  for (const std::string& op : operations_) {
143  if (op == opName) {
144  return true;
145  }
146  }
147  return false;
148 }

References operations_.

◆ loadState()

void TTAMachine::OperationTriggeredFormat::loadState ( const ObjectState state)
virtual

Loads the name of the component from the given ObjectState instance.

Parameters
stateThe ObjectState instance.
Exceptions
ObjectStateLoadingExceptionIf the machine already contains same type of component with the same name.

Reimplemented from TTAMachine::Component.

Definition at line 190 of file OperationTriggeredFormat.cc.

190  {
191  operations_.clear();
192  operands_.clear();
193  const std::string procName = "OperationTriggeredOperand::loadState";
194 
195  ObjectState* newState = new ObjectState(*state);
196 
197  if (newState->name() != OSNAME_FORMAT) {
198  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
199  }
200  Component::loadState(newState);
201  try {
202  for (int i = 0; i < newState->childCount(); i++) {
203  ObjectState* child = newState->child(i);
205  new OperationTriggeredOperand(child, *this);
206  } else if (
208  operations_.push_back(child->stringValue());
209  }
210  }
211  } catch (const Exception& exception) {
213  __FILE__, __LINE__, procName, exception.errorMessage());
214  }
215  delete newState;
216 }

References ObjectState::child(), ObjectState::childCount(), Exception::errorMessage(), TTAMachine::Component::loadState(), ObjectState::name(), operands_, operations_, OSKEY_OPERATION, OSNAME_FORMAT, TTAMachine::OperationTriggeredOperand::OSNAME_OPERAND, and ObjectState::stringValue().

Referenced by OperationTriggeredFormat().

Here is the call graph for this function:

◆ operands()

std::vector< OperationTriggeredOperand * > TTAMachine::OperationTriggeredFormat::operands ( ) const

Definition at line 151 of file OperationTriggeredFormat.cc.

151  {
152  return operands_;
153 }

References operands_.

◆ operation()

std::string TTAMachine::OperationTriggeredFormat::operation ( int  index) const

Definition at line 132 of file OperationTriggeredFormat.cc.

132  {
133  if (index > operationCount() - 1) {
134  const std::string msg = "Operation index out of range.";
135  throw OutOfRange(__FILE__, __LINE__, __func__, msg);
136  }
137  return operations_.at(index);
138 }

References __func__, operationCount(), and operations_.

Referenced by OTAFormatListDialog::updateOperationList().

Here is the call graph for this function:

◆ operationCount()

int TTAMachine::OperationTriggeredFormat::operationCount ( ) const

Definition at line 127 of file OperationTriggeredFormat.cc.

127  {
128  return operations_.size();
129 }

References operations_.

Referenced by operation(), and OTAFormatListDialog::updateOperationList().

◆ operations()

std::vector< std::string > TTAMachine::OperationTriggeredFormat::operations ( ) const

Definition at line 108 of file OperationTriggeredFormat.cc.

108  {
109  return operations_;
110 }

References operations_.

Referenced by BEMGenerator::addRiscvFormat().

◆ removeOperation()

void TTAMachine::OperationTriggeredFormat::removeOperation ( const std::string &  op)

Definition at line 118 of file OperationTriggeredFormat.cc.

118  {
119  for (unsigned int i = 0; i < operations_.size(); i++) {
120  if (operations_.at(i) == op) {
121  operations_.erase(operations_.begin() + i);
122  }
123  }
124 }

References operations_.

◆ saveState()

ObjectState * TTAMachine::OperationTriggeredFormat::saveState ( ) const
virtual

Saves the state of the operation code encoding to an ObjectState tree.

Returns
The newly created ObjectState tree.

Reimplemented from TTAMachine::Component.

Definition at line 226 of file OperationTriggeredFormat.cc.

226  {
228  state->setName(OSNAME_FORMAT);
229  for (unsigned int i = 0; i < operands_.size(); i++) {
230  ObjectState* operandObject = operands_.at(i)->saveState();
231  state->addChild(operandObject);
232  }
233  for (unsigned int i = 0; i < operations_.size(); i++) {
234  ObjectState* operationObject = new ObjectState(OSKEY_OPERATION);
235  operationObject->setValue(operations_.at(i));
236  state->addChild(operationObject);
237  }
238 
239  return state;
240 }

References ObjectState::addChild(), operands_, operations_, OSKEY_OPERATION, OSNAME_FORMAT, TTAMachine::Component::saveState(), ObjectState::setName(), and ObjectState::setValue().

Here is the call graph for this function:

◆ setMachine()

void TTAMachine::OperationTriggeredFormat::setMachine ( Machine machine)
virtual

Adds the OperationTriggeredFormat to the given machine.

Parameters
machineMachine to which the OperationTriggeredFormat Format is added.
Exceptions
ComponentAlreadyExistsIf there already is another OperationTriggeredFormat Format by the same name or another empty OperationTriggeredFormat Format in the given machine.

Implements TTAMachine::Component.

Definition at line 170 of file OperationTriggeredFormat.cc.

170  {
173 }

References TTAMachine::Machine::addOperationTriggeredFormat(), TTAMachine::Component::internalSetMachine(), and TTAMachine::Component::machine().

Referenced by OperationTriggeredFormat().

Here is the call graph for this function:

◆ unsetMachine()

void TTAMachine::OperationTriggeredFormat::unsetMachine ( )
virtual

Removes the OperationTriggeredFormat Format from its machine.

The OperationTriggeredFormat Format is also deleted because it cannot be alone. It must be registered to a machine.

Implements TTAMachine::Component.

Definition at line 182 of file OperationTriggeredFormat.cc.

182  {
183  Machine* mach = machine();
184  assert(mach != NULL);
186  mach->deleteOperationTriggeredFormat(*this);
187 }

References assert, TTAMachine::Machine::deleteOperationTriggeredFormat(), TTAMachine::Component::internalUnsetMachine(), and TTAMachine::Component::machine().

Referenced by OperationTriggeredFormat(), and ~OperationTriggeredFormat().

Here is the call graph for this function:

Member Data Documentation

◆ operands_

std::vector<OperationTriggeredOperand*> TTAMachine::OperationTriggeredFormat::operands_
private

◆ operations_

std::vector<std::string> TTAMachine::OperationTriggeredFormat::operations_
private

◆ OSKEY_OPERATION

const std::string TTAMachine::OperationTriggeredFormat::OSKEY_OPERATION = "ota-operation"
static

Definition at line 73 of file OperationTriggeredFormat.hh.

Referenced by loadState(), and saveState().

◆ OSNAME_FORMAT

const std::string TTAMachine::OperationTriggeredFormat::OSNAME_FORMAT = "ota-format"
static

The documentation for this class was generated from the following files:
TTAMachine::Component::internalUnsetMachine
void internalUnsetMachine()
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
ObjectStateLoadingException
Definition: Exception.hh:551
OutOfRange
Definition: Exception.hh:320
TTAMachine::Component::saveState
virtual ObjectState * saveState() const
Definition: MachinePart.cc:189
ObjectState
Definition: ObjectState.hh:59
TTAMachine::Machine::addOperationTriggeredFormat
virtual void addOperationTriggeredFormat(OperationTriggeredFormat &format)
Definition: Machine.cc:287
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
ObjectState::setName
void setName(const std::string &name)
TTAMachine::OperationTriggeredOperand::OSNAME_OPERAND
static const std::string OSNAME_OPERAND
Definition: OperationTriggeredOperand.hh:68
TTAMachine::OperationTriggeredFormat::OSKEY_OPERATION
static const std::string OSKEY_OPERATION
Definition: OperationTriggeredFormat.hh:73
TTAMachine::Component::internalSetMachine
void internalSetMachine(Machine &machine)
MOMTextGenerator::TXT_IT_EXISTS_BY_NAME
@ TXT_IT_EXISTS_BY_NAME
Definition: MOMTextGenerator.hh:69
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::Component::Component
Component(const std::string &name)
Definition: MachinePart.cc:82
TTAMachine::OperationTriggeredFormat::operands_
std::vector< OperationTriggeredOperand * > operands_
Definition: OperationTriggeredFormat.hh:79
TTAMachine::OperationTriggeredFormat::setMachine
virtual void setMachine(Machine &machine)
Definition: OperationTriggeredFormat.cc:170
TTAMachine::OperationTriggeredFormat::operationCount
int operationCount() const
Definition: OperationTriggeredFormat.cc:127
TTAMachine::Component::loadState
virtual void loadState(const ObjectState *state)
Definition: MachinePart.cc:205
TTAMachine::OperationTriggeredFormat::operations_
std::vector< std::string > operations_
Definition: OperationTriggeredFormat.hh:78
__func__
#define __func__
Definition: Application.hh:67
TTAMachine::OperationTriggeredFormat::OSNAME_FORMAT
static const std::string OSNAME_FORMAT
Definition: OperationTriggeredFormat.hh:72
ObjectState::child
ObjectState * child(int index) const
Definition: ObjectState.cc:471
ObjectState::addChild
void addChild(ObjectState *child)
Definition: ObjectState.cc:376
ObjectState::childCount
int childCount() const
Exception
Definition: Exception.hh:54
ObjectState::name
std::string name() const
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
TTAMachine::OperationTriggeredFormat::loadState
virtual void loadState(const ObjectState *state)
Definition: OperationTriggeredFormat.cc:190
TTAMachine::Component::machine
virtual Machine * machine() const
MOMTextGenerator
Definition: MOMTextGenerator.hh:40
ComponentAlreadyExists
Definition: Exception.hh:510
ObjectState::stringValue
std::string stringValue() const
TTAMachine::OperationTriggeredFormat::unsetMachine
virtual void unsetMachine()
Definition: OperationTriggeredFormat.cc:182
ObjectState::setValue
void setValue(const std::string &value)