OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
LImmDstRegisterField Class Reference

#include <LImmDstRegisterField.hh>

Inheritance diagram for LImmDstRegisterField:
Inheritance graph
Collaboration diagram for LImmDstRegisterField:
Collaboration graph

Public Member Functions

 LImmDstRegisterField (int width, BinaryEncoding &parent)
 
 LImmDstRegisterField (const ObjectState *state, BinaryEncoding &parent)
 
virtual ~LImmDstRegisterField ()
 
BinaryEncodingparent () const
 
void addDestination (const std::string &instructionTemplate, const std::string &immediateUnit)
 
int instructionTemplateCount () const
 
std::string instructionTemplate (int index) const
 
bool usedByInstructionTemplate (const std::string &instructionTemplate) const
 
std::string immediateUnit (const std::string &instructionTemplate) const
 
virtual int width () const
 
virtual int childFieldCount () const
 
virtual ObjectStatesaveState () const
 
- Public Member Functions inherited from InstructionField
virtual ~InstructionField ()
 
InstructionFieldparent () const
 
virtual InstructionFieldchildField (int position) const
 
int bitPosition () const
 
int relativePosition () const
 
virtual void setRelativePosition (int position)
 
void setExtraBits (int bits)
 
int extraBits () const
 
- Public Member Functions inherited from Serializable
virtual ~Serializable ()
 

Static Public Attributes

static const std::string OSNAME_LIMM_DST_REGISTER_FIELD
 ObjectState name for long immediate destination register field.
 
static const std::string OSKEY_WIDTH = "width"
 ObjectState attribute key for the width of the field.
 
static const std::string OSNAME_IU_DESTINATION = "iu_dst"
 ObjectState name for a immediate unit destination.
 
static const std::string OSKEY_ITEMP = "itemp"
 ObjectState attribute key for the name of the instruction template.
 
static const std::string OSKEY_DST_IU = "iu"
 ObjectState attribute key for the name of the immediate unit.
 
- Static Public Attributes inherited from InstructionField
static const std::string OSNAME_INSTRUCTION_FIELD = "instr_field"
 ObjectState name for instruction field.
 
static const std::string OSKEY_EXTRA_BITS = "extra_bits"
 ObjectState attribute key for the number of extra bits.
 
static const std::string OSKEY_POSITION = "position"
 ObjectState attribute key for the relative position of the field.
 

Private Types

typedef std::map< std::string, std::string > StringMap
 Map type for strings.
 

Private Member Functions

void loadState (const ObjectState *state)
 

Private Attributes

int width_
 Width of the field.
 
StringMap destinationMap_
 Maps instruction templates to immediate units.
 

Additional Inherited Members

- Protected Member Functions inherited from InstructionField
 InstructionField (InstructionField *parent)
 
 InstructionField (const ObjectState *state, InstructionField *parent)
 
void setParent (InstructionField *parent)
 
- Static Protected Member Functions inherited from InstructionField
static void reorderSubfields (ObjectState *state)
 

Detailed Description

Represets the instruction field that contains the register index where a long immediate is going to be written.

Definition at line 47 of file LImmDstRegisterField.hh.

Member Typedef Documentation

◆ StringMap

typedef std::map<std::string, std::string> LImmDstRegisterField::StringMap
private

Map type for strings.

Definition at line 82 of file LImmDstRegisterField.hh.

Constructor & Destructor Documentation

◆ LImmDstRegisterField() [1/2]

LImmDstRegisterField::LImmDstRegisterField ( int  width,
BinaryEncoding parent 
)

The constructor.

Registers the field automatically to the given parent.

Parameters
widthWidth of the field.
parentThe parent BinaryEncoding instance.
Exceptions
OutOfRangeIf the given width is 0 or smaller.

Definition at line 59 of file LImmDstRegisterField.cc.

61 if (width < 1) {
62 throw OutOfRange(__FILE__, __LINE__, __func__);
63 }
64
65 setParent(NULL);
68}
#define __func__
void addLongImmDstRegisterField(LImmDstRegisterField &field)
void setParent(InstructionField *parent)
BinaryEncoding * parent() const
int width_
Width of the field.
virtual int width() const

References __func__, BinaryEncoding::addLongImmDstRegisterField(), parent(), InstructionField::setParent(), and width().

Here is the call graph for this function:

◆ LImmDstRegisterField() [2/2]

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

The constructor.

Loads the state of the object from the given ObjectState instance. Registers the field automatically to the given parent.

Parameters
stateThe ObjectState instance.
parentThe parent BinaryEncoding instance.
Exceptions
ObjectStateLoadingExceptionIf the given ObjectState instance is erroneous.

Definition at line 81 of file LImmDstRegisterField.cc.

83 : InstructionField(state, &parent), width_(0) {
84 loadState(state);
85 setParent(NULL);
88}
void loadState(const ObjectState *state)

References BinaryEncoding::addLongImmDstRegisterField(), loadState(), parent(), and InstructionField::setParent().

Here is the call graph for this function:

◆ ~LImmDstRegisterField()

LImmDstRegisterField::~LImmDstRegisterField ( )
virtual

The destructor.

Definition at line 93 of file LImmDstRegisterField.cc.

93 {
94 BinaryEncoding* parent = this->parent();
95 setParent(NULL);
97}
void removeLongImmDstRegisterField(LImmDstRegisterField &field)

References parent(), BinaryEncoding::removeLongImmDstRegisterField(), and InstructionField::setParent().

Here is the call graph for this function:

Member Function Documentation

◆ addDestination()

void LImmDstRegisterField::addDestination ( const std::string &  instructionTemplate,
const std::string &  immediateUnit 
)

Sets that the register index of the given immediate unit in the given instruction template is given in this field.

Parameters
instructionTemplateThe instruction template.
immediateUnitThe immediate unit.
Exceptions
NotAvailableIf index of some other immediate unit is assigned to this field in the same instruction template.

Definition at line 129 of file LImmDstRegisterField.cc.

130 {
133 != immediateUnit) {
134 throw NotAvailable(__FILE__, __LINE__, __func__);
135 } else {
136 destinationMap_.insert(
137 std::pair<string, string>(instructionTemplate, immediateUnit));
138 }
139}
std::string instructionTemplate(int index) const
StringMap destinationMap_
Maps instruction templates to immediate units.
std::string immediateUnit(const std::string &instructionTemplate) const
static KeyType keyForValue(const MapType &aMap, const ValueType &aValue)
static bool containsKey(const MapType &aMap, const KeyType &aKey)

References __func__, MapTools::containsKey(), destinationMap_, immediateUnit(), instructionTemplate(), and MapTools::keyForValue().

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

Here is the call graph for this function:

◆ childFieldCount()

int LImmDstRegisterField::childFieldCount ( ) const
virtual

Returns the number of child fields, that is always 0.

Returns
0.

Implements InstructionField.

Definition at line 224 of file LImmDstRegisterField.cc.

224 {
225 return 0;
226}

◆ immediateUnit()

std::string LImmDstRegisterField::immediateUnit ( const std::string &  instructionTemplate) const

Returns the name of the immediate unit for which the field is assigned in the given instruction template.

Parameters
instructionTemplateName of the instruction template.
Exceptions
NotAvailableIf the field is not used in the given instruction template.

Definition at line 197 of file LImmDstRegisterField.cc.

198 {
199 try {
202 } catch (const Exception&) {
203 throw NotAvailable(__FILE__, __LINE__, __func__);
204 }
205}

References __func__, destinationMap_, instructionTemplate(), and MapTools::keyForValue().

Referenced by CodeCompressorPlugin::addBitsForDstRegisterField(), addDestination(), BEMValidator::checkLImmDstRegisterFields(), BinaryEncoding::longImmDstRegisterField(), and printLImmDstRegisterField().

Here is the call graph for this function:

◆ instructionTemplate()

std::string LImmDstRegisterField::instructionTemplate ( int  index) const

By the given index, returns an instruction template that uses this destination register field.

Parameters
indexThe index.
Exceptions
OutOfRangeIf the index is negative or not smaller than the number of instruction templates.

Definition at line 162 of file LImmDstRegisterField.cc.

162 {
163 if (index < 0 || index >= instructionTemplateCount()) {
164 throw OutOfRange(__FILE__, __LINE__, __func__);
165 }
166
167 StringMap::const_iterator iter = destinationMap_.begin();
168 for (int i = 0; i < index; i++) {
169 iter++;
170 }
171
172 return iter->first;
173}

References __func__, destinationMap_, and instructionTemplateCount().

Referenced by addDestination(), immediateUnit(), printLImmDstRegisterField(), and usedByInstructionTemplate().

Here is the call graph for this function:

◆ instructionTemplateCount()

int LImmDstRegisterField::instructionTemplateCount ( ) const

Returns the number of instruction templates that use this destination register field.

Returns
The number of instruction templates.

Definition at line 148 of file LImmDstRegisterField.cc.

148 {
149 return destinationMap_.size();
150}

References destinationMap_.

Referenced by instructionTemplate(), and printLImmDstRegisterField().

◆ loadState()

void LImmDstRegisterField::loadState ( const ObjectState state)
privatevirtual

Loads the state of the object from the given ObjectState instance.

Parameters
stateThe ObjectState instance.

Reimplemented from InstructionField.

Definition at line 260 of file LImmDstRegisterField.cc.

260 {
261 if (state->name() != OSNAME_LIMM_DST_REGISTER_FIELD) {
262 throw ObjectStateLoadingException(__FILE__, __LINE__, __func__);
263 }
264
266
267 try {
269 for (int i = 0; i < state->childCount(); i++) {
270 ObjectState* child = state->child(i);
271 if (child->name() != OSNAME_IU_DESTINATION) {
273 __FILE__, __LINE__, __func__);
274 }
275 string iTemp = child->stringAttribute(OSKEY_ITEMP);
276 string iu = child->stringAttribute(OSKEY_DST_IU);
277 addDestination(iTemp, iu);
278 }
279 } catch (const Exception& e) {
281 __FILE__, __LINE__, __func__, e.errorMessage());
282 }
283}
std::string errorMessage() const
Definition Exception.cc:123
virtual void loadState(const ObjectState *state)
static const std::string OSKEY_ITEMP
ObjectState attribute key for the name of the instruction template.
static const std::string OSKEY_DST_IU
ObjectState attribute key for the name of the immediate unit.
static const std::string OSNAME_LIMM_DST_REGISTER_FIELD
ObjectState name for long immediate destination register field.
static const std::string OSKEY_WIDTH
ObjectState attribute key for the width of the field.
static const std::string OSNAME_IU_DESTINATION
ObjectState name for a immediate unit destination.
void addDestination(const std::string &instructionTemplate, const std::string &immediateUnit)
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

References __func__, addDestination(), ObjectState::child(), ObjectState::childCount(), Exception::errorMessage(), ObjectState::intAttribute(), InstructionField::loadState(), ObjectState::name(), OSKEY_DST_IU, OSKEY_ITEMP, OSKEY_WIDTH, OSNAME_IU_DESTINATION, OSNAME_LIMM_DST_REGISTER_FIELD, ObjectState::stringAttribute(), and width_.

Referenced by LImmDstRegisterField().

Here is the call graph for this function:

◆ parent()

BinaryEncoding * LImmDstRegisterField::parent ( ) const

Returns the parent BinaryEncoding instance.

Returns
The parent BinaryEncoding instance.

Definition at line 106 of file LImmDstRegisterField.cc.

106 {
108 if (parent != NULL) {
109 BinaryEncoding* bem = dynamic_cast<BinaryEncoding*>(parent);
110 assert(bem != NULL);
111 return bem;
112 } else {
113 return NULL;
114 }
115}
#define assert(condition)
InstructionField * parent() const

References assert, InstructionField::parent(), and parent().

Referenced by BinaryEncoding::addLongImmDstRegisterField(), LImmDstRegisterField(), LImmDstRegisterField(), parent(), BinaryEncoding::removeLongImmDstRegisterField(), and ~LImmDstRegisterField().

Here is the call graph for this function:

◆ saveState()

ObjectState * LImmDstRegisterField::saveState ( ) const
virtual

Saves the state of the object to an ObjectState instance.

Returns
The newly created ObjectState instance.

Reimplemented from InstructionField.

Definition at line 235 of file LImmDstRegisterField.cc.

235 {
236
239 state->setAttribute(OSKEY_WIDTH, width());
240
241 // add destinations
242 for (StringMap::const_iterator iter = destinationMap_.begin();
243 iter != destinationMap_.end(); iter++) {
245 state->addChild(dstState);
246 dstState->setAttribute(OSKEY_ITEMP, iter->first);
247 dstState->setAttribute(OSKEY_DST_IU, iter->second);
248 }
249
250 return state;
251}
virtual ObjectState * saveState() const
void setName(const std::string &name)
void setAttribute(const std::string &name, const std::string &value)
void addChild(ObjectState *child)

References ObjectState::addChild(), destinationMap_, OSKEY_DST_IU, OSKEY_ITEMP, OSKEY_WIDTH, OSNAME_IU_DESTINATION, OSNAME_LIMM_DST_REGISTER_FIELD, InstructionField::saveState(), ObjectState::setAttribute(), ObjectState::setName(), and width().

Referenced by BinaryEncoding::saveState().

Here is the call graph for this function:

◆ usedByInstructionTemplate()

bool LImmDstRegisterField::usedByInstructionTemplate ( const std::string &  instructionTemplate) const

Tells whether the field is used by the given instruction template.

Parameters
instructionTemplateThe instruction template.

Definition at line 181 of file LImmDstRegisterField.cc.

References MapTools::containsKey(), destinationMap_, and instructionTemplate().

Referenced by BEMValidator::checkLImmDstRegisterFields(), and BinaryEncoding::longImmDstRegisterField().

Here is the call graph for this function:

◆ width()

int LImmDstRegisterField::width ( ) const
virtual

Member Data Documentation

◆ destinationMap_

StringMap LImmDstRegisterField::destinationMap_
private

Maps instruction templates to immediate units.

Definition at line 89 of file LImmDstRegisterField.hh.

Referenced by addDestination(), immediateUnit(), instructionTemplate(), instructionTemplateCount(), saveState(), and usedByInstructionTemplate().

◆ OSKEY_DST_IU

const std::string LImmDstRegisterField::OSKEY_DST_IU = "iu"
static

ObjectState attribute key for the name of the immediate unit.

Definition at line 78 of file LImmDstRegisterField.hh.

Referenced by loadState(), BEMSerializer::longImmDstRegFieldToOM(), BEMSerializer::longImmDstRegisterFieldToFile(), and saveState().

◆ OSKEY_ITEMP

const std::string LImmDstRegisterField::OSKEY_ITEMP = "itemp"
static

ObjectState attribute key for the name of the instruction template.

Definition at line 76 of file LImmDstRegisterField.hh.

Referenced by loadState(), BEMSerializer::longImmDstRegFieldToOM(), BEMSerializer::longImmDstRegisterFieldToFile(), and saveState().

◆ OSKEY_WIDTH

const std::string LImmDstRegisterField::OSKEY_WIDTH = "width"
static

ObjectState attribute key for the width of the field.

Definition at line 72 of file LImmDstRegisterField.hh.

Referenced by loadState(), BEMSerializer::longImmDstRegFieldToOM(), BEMSerializer::longImmDstRegisterFieldToFile(), and saveState().

◆ OSNAME_IU_DESTINATION

const std::string LImmDstRegisterField::OSNAME_IU_DESTINATION = "iu_dst"
static

ObjectState name for a immediate unit destination.

Definition at line 74 of file LImmDstRegisterField.hh.

Referenced by loadState(), BEMSerializer::longImmDstRegFieldToOM(), BEMSerializer::longImmDstRegisterFieldToFile(), and saveState().

◆ OSNAME_LIMM_DST_REGISTER_FIELD

const std::string LImmDstRegisterField::OSNAME_LIMM_DST_REGISTER_FIELD
static
Initial value:
=
"dst_reg_field"

ObjectState name for long immediate destination register field.

Definition at line 70 of file LImmDstRegisterField.hh.

Referenced by BEMSerializer::convertToFileFormat(), BinaryEncoding::loadState(), loadState(), BEMSerializer::longImmDstRegFieldToOM(), and saveState().

◆ width_

int LImmDstRegisterField::width_
private

Width of the field.

Definition at line 87 of file LImmDstRegisterField.hh.

Referenced by loadState(), and width().


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