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

#include <InstructionFormat.hh>

Inheritance diagram for InstructionFormat:
Inheritance graph
Collaboration diagram for InstructionFormat:
Collaboration graph

Public Member Functions

 InstructionFormat (const std::string &name, BinaryEncoding &parent)
 
 InstructionFormat (const ObjectState *state, BinaryEncoding &parent)
 
 ~InstructionFormat ()
 
InstructionFieldparent () const
 
std::string name () const
 
void setName (const std::string &name)
 
void addEncoding (OperationTriggeredEncoding &encoding)
 
void addOperation (std::string op, int encoding)
 
std::map< std::string, int > operations () const
 
bool hasOperation (const std::string &op) const
 
int encoding (const std::string &op) const
 
virtual int childFieldCount () const
 
virtual int width () const
 
virtual void loadState (const ObjectState *state)
 
virtual ObjectStatesaveState () const
 
- Public Member Functions inherited from Serializable
virtual ~Serializable ()
 

Static Public Attributes

static const std::string OSNAME_INSTRUCTION_FORMAT = "ota-format"
 
static const std::string OSKEY_INSTRUCTION_FORMAT_NAME = "name"
 
static const std::string OSKEY_OTA_OPERATION_NAME
 
static const std::string OSKEY_OPERATION_NAME = "name"
 
static const std::string OSKEY_OPERATION_ENCODING_NAME
 

Private Attributes

std::string name_
 
BinaryEncodingparent_
 
std::vector< OperationTriggeredEncoding * > encodings_
 
std::map< std::string, int > operations_
 

Detailed Description

Definition at line 46 of file InstructionFormat.hh.

Constructor & Destructor Documentation

◆ InstructionFormat() [1/2]

InstructionFormat::InstructionFormat ( const std::string &  name,
BinaryEncoding parent 
)

The constructor.

Adds the instruction format to the parent binary encoding automatically.

Parameters
nameName of the instruction format.
parentThe parent BinaryEncoding.

Definition at line 60 of file InstructionFormat.cc.

62  : name_(name), parent_(NULL) {
63  parent.addInstructionFormat(*this);
64  parent_ = &parent;
65 }

References parent(), and parent_.

Here is the call graph for this function:

◆ InstructionFormat() [2/2]

InstructionFormat::InstructionFormat ( const ObjectState state,
BinaryEncoding parent 
)

The constructor.

Loads the state of the instruction format 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 78 of file InstructionFormat.cc.

80  : parent_(NULL) {
81  parent.addInstructionFormat(*this);
82  parent_ = &parent;
83  loadState(state);
84 }

References loadState(), parent(), and parent_.

Here is the call graph for this function:

◆ ~InstructionFormat()

InstructionFormat::~InstructionFormat ( )

The destructor

Definition at line 91 of file InstructionFormat.cc.

91  {
92  /*
93  for (unsigned int i = 0; i < encodings_.size(); i++) {
94  delete encodings_.at(i);
95  }*/
96 }

Member Function Documentation

◆ addEncoding()

void InstructionFormat::addEncoding ( OperationTriggeredEncoding encoding)

Adds an operation triggered move slot to the instruction format

Parameters
encodingThe operation triggered move slot to be addeed
Exceptions
ObjectAlreadyExistsIf the slot has already been added to the instruction format.

Definition at line 139 of file InstructionFormat.cc.

139  {
141  encodings_.push_back(&encoding);
142  } else {
143  const std::string procName = "InstructionFormat::addEncoding";
144  throw ObjectAlreadyExists(__FILE__, __LINE__, procName);
145  }
146 }

References VectorTools::containsValue(), encoding(), and encodings_.

Referenced by OperationTriggeredEncoding::OperationTriggeredEncoding().

Here is the call graph for this function:

◆ addOperation()

void InstructionFormat::addOperation ( std::string  op,
int  encoding 
)

Adds an operation to the instruction format

Parameters
opOperation name
encodingEncoding of the operation
Exceptions
ObjectAlreadyExistsIf the slot has already been added to the instruction format.

Definition at line 158 of file InstructionFormat.cc.

158  {
160  operations_.insert({op, encoding});
161  } else {
162  const std::string procName = "InstructionFormat::addOperation";
163  throw ObjectAlreadyExists(__FILE__, __LINE__, procName);
164  }
165 }

References MapTools::containsKey(), encoding(), and operations_.

Referenced by BEMGenerator::addRiscvFormat(), and loadState().

Here is the call graph for this function:

◆ childFieldCount()

int InstructionFormat::childFieldCount ( ) const
virtual

Returns the number of operation triggered encodings.

Returns
The number of child fields.

Definition at line 174 of file InstructionFormat.cc.

174  {
175  return encodings_.size();
176 }

References encodings_.

◆ encoding()

int InstructionFormat::encoding ( const std::string &  op) const

Definition at line 200 of file InstructionFormat.cc.

200  {
202  return operations_.at(op);
203 }

References assert, MapTools::containsKey(), and operations_.

Referenced by addEncoding(), addOperation(), and llvm::LLVMTCERISCVIntrinsicsLowering::constructEncoding().

Here is the call graph for this function:

◆ hasOperation()

bool InstructionFormat::hasOperation ( const std::string &  op) const

Definition at line 104 of file InstructionFormat.cc.

104  {
106 }

References MapTools::containsKey(), and operations_.

Referenced by llvm::LLVMTCERISCVIntrinsicsLowering::findOperationName().

Here is the call graph for this function:

◆ loadState()

void InstructionFormat::loadState ( const ObjectState state)
virtual

Loads the state of the instruction format from the given ObjectState tree.

Parameters
stateThe ObjectState tree.
Exceptions
ObjectStateLoadingExceptionIf an error occurs while loading the state.

Implements Serializable.

Definition at line 214 of file InstructionFormat.cc.

214  {
215  ObjectState* newState = new ObjectState(*state);
216  try {
218  for (int i = 0; i < newState->childCount(); i++) {
219  ObjectState* child = newState->child(i);
220  if (child->name() ==
222  new OperationTriggeredEncoding(child, *this);
223  } else if (child->name() == OSKEY_OTA_OPERATION_NAME) {
224  addOperation(
227  }
228  }
229  } catch (const Exception& exception) {
230  const std::string procName = "InstructionFormat::loadState";
232  __FILE__, __LINE__, procName, exception.errorMessage());
233  }
234 }

References addOperation(), ObjectState::child(), ObjectState::childCount(), Exception::errorMessage(), ObjectState::intAttribute(), ObjectState::name(), OSKEY_INSTRUCTION_FORMAT_NAME, OSKEY_OPERATION_ENCODING_NAME, OSKEY_OPERATION_NAME, OSKEY_OTA_OPERATION_NAME, OperationTriggeredEncoding::OSNAME_OTA_ENCODING, setName(), and ObjectState::stringAttribute().

Referenced by InstructionFormat().

Here is the call graph for this function:

◆ name()

std::string InstructionFormat::name ( ) const

Returns the name of the instruction format.

Returns
The name of the instruction format

Definition at line 115 of file InstructionFormat.cc.

115  {
116  return name_;
117 }

References name_.

Referenced by BinaryEncoding::addInstructionFormat(), llvm::LLVMTCERISCVIntrinsicsLowering::findRFormat(), ProGe::RV32MicroCodeGenerator::initializeOperations(), and setName().

◆ operations()

std::map< std::string, int > InstructionFormat::operations ( ) const

Definition at line 195 of file InstructionFormat.cc.

195  {
196  return operations_;
197 }

References operations_.

Referenced by ProGe::RV32MicroCodeGenerator::initializeOperations().

◆ parent()

InstructionField * InstructionFormat::parent ( ) const

Definition at line 99 of file InstructionFormat.cc.

99  {
100  return static_cast<InstructionField*>(parent_);
101 }

References parent_.

Referenced by BinaryEncoding::addInstructionFormat(), InstructionFormat(), and BinaryEncoding::removeInstructionFormat().

◆ saveState()

ObjectState * InstructionFormat::saveState ( ) const
virtual

Saves the state of the instruction format to an ObjectState tree.

Returns
The newly created ObjectState tree.

Implements Serializable.

Definition at line 243 of file InstructionFormat.cc.

243  {
246  for (unsigned int i = 0; i < encodings_.size(); i++) {
248  ObjectState* obj = it->saveState();
249  state->addChild(obj);
250  }
251  for (auto const& val : operations_) {
253  obj->setAttribute(OSKEY_OPERATION_NAME, val.first);
255  state->addChild(obj);
256  }
257  return state;
258 }

References ObjectState::addChild(), encodings_, name_, operations_, OSKEY_INSTRUCTION_FORMAT_NAME, OSKEY_OPERATION_ENCODING_NAME, OSKEY_OPERATION_NAME, OSKEY_OTA_OPERATION_NAME, OSNAME_INSTRUCTION_FORMAT, OperationTriggeredEncoding::saveState(), and ObjectState::setAttribute().

Here is the call graph for this function:

◆ setName()

void InstructionFormat::setName ( const std::string &  name)

Sets the name of the instruction format.

Parameters
nameThe name of the instruction format.

Definition at line 126 of file InstructionFormat.cc.

126  {
127  name_ = name;
128 }

References name(), and name_.

Referenced by loadState().

Here is the call graph for this function:

◆ width()

int InstructionFormat::width ( ) const
virtual

Returns the bit width of the instruction format.

Returns
Bit width of the instruction format.

Definition at line 185 of file InstructionFormat.cc.

185  {
186  int width = 0;
187  for (unsigned int i = 0; i < encodings_.size(); i++) {
189  width += slot->width();
190  }
191  return width;
192 }

References encodings_, and OperationTriggeredEncoding::width().

Here is the call graph for this function:

Member Data Documentation

◆ encodings_

std::vector<OperationTriggeredEncoding*> InstructionFormat::encodings_
private

Definition at line 89 of file InstructionFormat.hh.

Referenced by addEncoding(), childFieldCount(), saveState(), and width().

◆ name_

std::string InstructionFormat::name_
private

Definition at line 86 of file InstructionFormat.hh.

Referenced by name(), saveState(), and setName().

◆ operations_

std::map<std::string, int> InstructionFormat::operations_
private

Definition at line 90 of file InstructionFormat.hh.

Referenced by addOperation(), encoding(), hasOperation(), operations(), and saveState().

◆ OSKEY_INSTRUCTION_FORMAT_NAME

const std::string InstructionFormat::OSKEY_INSTRUCTION_FORMAT_NAME = "name"
static

Definition at line 78 of file InstructionFormat.hh.

Referenced by loadState(), and saveState().

◆ OSKEY_OPERATION_ENCODING_NAME

const std::string InstructionFormat::OSKEY_OPERATION_ENCODING_NAME
static
Initial value:
=
"encoding"

Definition at line 81 of file InstructionFormat.hh.

Referenced by loadState(), and saveState().

◆ OSKEY_OPERATION_NAME

const std::string InstructionFormat::OSKEY_OPERATION_NAME = "name"
static

Definition at line 80 of file InstructionFormat.hh.

Referenced by loadState(), and saveState().

◆ OSKEY_OTA_OPERATION_NAME

const std::string InstructionFormat::OSKEY_OTA_OPERATION_NAME
static
Initial value:
=
"ota-operation"

Definition at line 79 of file InstructionFormat.hh.

Referenced by loadState(), and saveState().

◆ OSNAME_INSTRUCTION_FORMAT

const std::string InstructionFormat::OSNAME_INSTRUCTION_FORMAT = "ota-format"
static

Definition at line 77 of file InstructionFormat.hh.

Referenced by BEMSerializer::convertToFileFormat(), and saveState().

◆ parent_

BinaryEncoding* InstructionFormat::parent_
private

Definition at line 87 of file InstructionFormat.hh.

Referenced by InstructionFormat(), and parent().


The documentation for this class was generated from the following files:
InstructionFormat::name
std::string name() const
Definition: InstructionFormat.cc:115
OperationTriggeredEncoding::OSNAME_OTA_ENCODING
static const std::string OSNAME_OTA_ENCODING
Definition: OperationTriggeredEncoding.hh:68
InstructionFormat::OSKEY_OTA_OPERATION_NAME
static const std::string OSKEY_OTA_OPERATION_NAME
Definition: InstructionFormat.hh:79
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
InstructionFormat::addOperation
void addOperation(std::string op, int encoding)
Definition: InstructionFormat.cc:158
ObjectStateLoadingException
Definition: Exception.hh:551
InstructionFormat::setName
void setName(const std::string &name)
Definition: InstructionFormat.cc:126
InstructionFormat::operations_
std::map< std::string, int > operations_
Definition: InstructionFormat.hh:90
ObjectState
Definition: ObjectState.hh:59
InstructionFormat::parent
InstructionField * parent() const
Definition: InstructionFormat.cc:99
InstructionField
Definition: InstructionField.hh:43
InstructionFormat::OSKEY_INSTRUCTION_FORMAT_NAME
static const std::string OSKEY_INSTRUCTION_FORMAT_NAME
Definition: InstructionFormat.hh:78
assert
#define assert(condition)
Definition: Application.hh:86
InstructionFormat::width
virtual int width() const
Definition: InstructionFormat.cc:185
InstructionFormat::encodings_
std::vector< OperationTriggeredEncoding * > encodings_
Definition: InstructionFormat.hh:89
InstructionFormat::OSKEY_OPERATION_ENCODING_NAME
static const std::string OSKEY_OPERATION_ENCODING_NAME
Definition: InstructionFormat.hh:81
ObjectState::child
ObjectState * child(int index) const
Definition: ObjectState.cc:471
ObjectState::addChild
void addChild(ObjectState *child)
Definition: ObjectState.cc:376
OperationTriggeredEncoding
Definition: OperationTriggeredEncoding.hh:44
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
MapTools::containsKey
static bool containsKey(const MapType &aMap, const KeyType &aKey)
InstructionFormat::parent_
BinaryEncoding * parent_
Definition: InstructionFormat.hh:87
OperationTriggeredEncoding::saveState
virtual ObjectState * saveState() const
Definition: OperationTriggeredEncoding.cc:177
ObjectAlreadyExists
Definition: Exception.hh:1002
VectorTools::containsValue
static bool containsValue(const ContainerType &aVec, const ValueType &aValue)
InstructionFormat::encoding
int encoding(const std::string &op) const
Definition: InstructionFormat.cc:200
ObjectState::intAttribute
int intAttribute(const std::string &name) const
Definition: ObjectState.cc:276
InstructionFormat::name_
std::string name_
Definition: InstructionFormat.hh:86
InstructionFormat::loadState
virtual void loadState(const ObjectState *state)
Definition: InstructionFormat.cc:214
InstructionFormat::OSKEY_OPERATION_NAME
static const std::string OSKEY_OPERATION_NAME
Definition: InstructionFormat.hh:80
OperationTriggeredEncoding::width
virtual int width() const
Definition: OperationTriggeredEncoding.cc:128
InstructionFormat::OSNAME_INSTRUCTION_FORMAT
static const std::string OSNAME_INSTRUCTION_FORMAT
Definition: InstructionFormat.hh:77
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100