OpenASIP 2.2
Loading...
Searching...
No Matches
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)
 
int operationCount () const
 
std::string operationAtIndex (const int index) 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}
BinaryEncoding * parent_
std::string name() const
InstructionField * parent() const

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}
virtual void loadState(const ObjectState *state)

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}
int encoding(const std::string &op) const
std::vector< OperationTriggeredEncoding * > encodings_
static bool containsValue(const ContainerType &aVec, const ValueType &aValue)

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

Referenced by OperationTriggeredEncoding::OperationTriggeredEncoding(), and 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}
std::map< std::string, int > operations_
static bool containsKey(const MapType &aMap, const KeyType &aKey)

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 212 of file InstructionFormat.cc.

212 {
214 return operations_.at(op);
215}
#define assert(condition)

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

Referenced by addEncoding(), addOperation(), llvm::LLVMTCERISCVIntrinsicsLowering::constructEncoding(), RISCVTDGen::findCustomOps(), and ProGe::RV32MicroCodeGenerator::initializeOperations().

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 226 of file InstructionFormat.cc.

226 {
227 ObjectState* newState = new ObjectState(*state);
228 try {
230 for (int i = 0; i < newState->childCount(); i++) {
231 ObjectState* child = newState->child(i);
232 if (child->name() ==
234 new OperationTriggeredEncoding(child, *this);
235 } else if (child->name() == OSKEY_OTA_OPERATION_NAME) {
239 }
240 }
241 } catch (const Exception& exception) {
242 const std::string procName = "InstructionFormat::loadState";
244 __FILE__, __LINE__, procName, exception.errorMessage());
245 }
246}
std::string errorMessage() const
Definition Exception.cc:123
static const std::string OSKEY_OTA_OPERATION_NAME
void addOperation(std::string op, int encoding)
static const std::string OSKEY_OPERATION_NAME
static const std::string OSKEY_OPERATION_ENCODING_NAME
void setName(const std::string &name)
static const std::string OSKEY_INSTRUCTION_FORMAT_NAME
ObjectState * child(int index) const
std::string stringAttribute(const std::string &name) const
int intAttribute(const std::string &name) const
std::string name() const
int childCount() const
static const std::string OSNAME_OTA_ENCODING

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(), BinaryEncoding::instructionFormat(), and setName().

◆ operationAtIndex()

std::string InstructionFormat::operationAtIndex ( const int  index) const

Definition at line 200 of file InstructionFormat.cc.

200 {
201 if (index > operationCount() - 1) {
202 const std::string msg = "Operation index out of range.";
203 throw OutOfRange(__FILE__, __LINE__, __func__, msg);
204 }
205 auto it = operations_.begin();
206 std::advance(it, index);
207 return it->first;
208}
#define __func__

References __func__, operationCount(), and operations_.

Referenced by RISCVTDGen::findCustomOps(), and ProGe::RV32MicroCodeGenerator::initializeOperations().

Here is the call graph for this function:

◆ operationCount()

int InstructionFormat::operationCount ( ) const

Definition at line 195 of file InstructionFormat.cc.

195 {
196 return operations_.size();
197}

References operations_.

Referenced by RISCVTDGen::findCustomOps(), ProGe::RV32MicroCodeGenerator::initializeOperations(), and operationAtIndex().

◆ parent()

InstructionField * InstructionFormat::parent ( ) const

◆ 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 255 of file InstructionFormat.cc.

255 {
258 for (unsigned int i = 0; i < encodings_.size(); i++) {
260 ObjectState* obj = it->saveState();
261 state->addChild(obj);
262 }
263 for (auto const& val : operations_) {
265 obj->setAttribute(OSKEY_OPERATION_NAME, val.first);
267 state->addChild(obj);
268 }
269 return state;
270}
static const std::string OSNAME_INSTRUCTION_FORMAT
void setAttribute(const std::string &name, const std::string &value)
void addChild(ObjectState *child)
virtual ObjectState * saveState() const

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}
virtual int width() const

References encodings_, width(), and OperationTriggeredEncoding::width().

Referenced by width().

Here is the call graph for this function:

Member Data Documentation

◆ encodings_

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

Definition at line 90 of file InstructionFormat.hh.

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

◆ name_

std::string InstructionFormat::name_
private

Definition at line 87 of file InstructionFormat.hh.

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

◆ operations_

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

◆ OSKEY_INSTRUCTION_FORMAT_NAME

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

Definition at line 79 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 82 of file InstructionFormat.hh.

Referenced by loadState(), and saveState().

◆ OSKEY_OPERATION_NAME

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

Definition at line 81 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 80 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 78 of file InstructionFormat.hh.

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

◆ parent_

BinaryEncoding* InstructionFormat::parent_
private

Definition at line 88 of file InstructionFormat.hh.

Referenced by InstructionFormat(), InstructionFormat(), and parent().


The documentation for this class was generated from the following files: