OpenASIP  2.0
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. More...
 
static const std::string OSKEY_WIDTH = "width"
 ObjectState attribute key for the width of the field. More...
 
static const std::string OSNAME_IU_DESTINATION = "iu_dst"
 ObjectState name for a immediate unit destination. More...
 
static const std::string OSKEY_ITEMP = "itemp"
 ObjectState attribute key for the name of the instruction template. More...
 
static const std::string OSKEY_DST_IU = "iu"
 ObjectState attribute key for the name of the immediate unit. More...
 
- Static Public Attributes inherited from InstructionField
static const std::string OSNAME_INSTRUCTION_FIELD = "instr_field"
 ObjectState name for instruction field. More...
 
static const std::string OSKEY_EXTRA_BITS = "extra_bits"
 ObjectState attribute key for the number of extra bits. More...
 
static const std::string OSKEY_POSITION = "position"
 ObjectState attribute key for the relative position of the field. More...
 

Private Types

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

Private Member Functions

void loadState (const ObjectState *state)
 

Private Attributes

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

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);
67  setParent(&parent);
68 }

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);
87  setParent(&parent);
88 }

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 }

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  {
132  MapTools::valueForKey<string>(destinationMap_, instructionTemplate)
133  != immediateUnit) {
134  throw NotAvailable(__FILE__, __LINE__, __func__);
135  } else {
136  destinationMap_.insert(
137  std::pair<string, string>(instructionTemplate, immediateUnit));
138  }
139 }

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

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 {
200  return MapTools::valueForKey<string>(
202  } catch (const Exception&) {
203  throw NotAvailable(__FILE__, __LINE__, __func__);
204  }
205 }

References __func__, destinationMap_, and instructionTemplate().

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 {
268  width_ = state->intAttribute(OSKEY_WIDTH);
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 }

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 }

References assert, and InstructionField::parent().

Referenced by BinaryEncoding::addLongImmDstRegisterField(), LImmDstRegisterField(), 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 }

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.

182  {
183 
185 }

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(), loadState(), BinaryEncoding::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:
LImmDstRegisterField::loadState
void loadState(const ObjectState *state)
Definition: LImmDstRegisterField.cc:260
BinaryEncoding
Definition: BinaryEncoding.hh:61
LImmDstRegisterField::destinationMap_
StringMap destinationMap_
Maps instruction templates to immediate units.
Definition: LImmDstRegisterField.hh:89
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
ObjectStateLoadingException
Definition: Exception.hh:551
OutOfRange
Definition: Exception.hh:320
LImmDstRegisterField::instructionTemplateCount
int instructionTemplateCount() const
Definition: LImmDstRegisterField.cc:148
ObjectState
Definition: ObjectState.hh:59
ObjectState::setName
void setName(const std::string &name)
NotAvailable
Definition: Exception.hh:728
InstructionField
Definition: InstructionField.hh:43
InstructionField::saveState
virtual ObjectState * saveState() const
Definition: InstructionField.cc:268
assert
#define assert(condition)
Definition: Application.hh:86
LImmDstRegisterField::OSKEY_DST_IU
static const std::string OSKEY_DST_IU
ObjectState attribute key for the name of the immediate unit.
Definition: LImmDstRegisterField.hh:78
LImmDstRegisterField::instructionTemplate
std::string instructionTemplate(int index) const
Definition: LImmDstRegisterField.cc:162
BinaryEncoding::addLongImmDstRegisterField
void addLongImmDstRegisterField(LImmDstRegisterField &field)
Definition: BinaryEncoding.cc:459
LImmDstRegisterField::width_
int width_
Width of the field.
Definition: LImmDstRegisterField.hh:87
InstructionField::setParent
void setParent(InstructionField *parent)
Definition: InstructionField.cc:282
InstructionField::parent
InstructionField * parent() const
Definition: InstructionField.cc:100
__func__
#define __func__
Definition: Application.hh:67
LImmDstRegisterField::immediateUnit
std::string immediateUnit(const std::string &instructionTemplate) const
Definition: LImmDstRegisterField.cc:197
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
LImmDstRegisterField::OSKEY_WIDTH
static const std::string OSKEY_WIDTH
ObjectState attribute key for the width of the field.
Definition: LImmDstRegisterField.hh:72
LImmDstRegisterField::width
virtual int width() const
Definition: LImmDstRegisterField.cc:213
Exception
Definition: Exception.hh:54
ObjectState::name
std::string name() const
LImmDstRegisterField::OSNAME_IU_DESTINATION
static const std::string OSNAME_IU_DESTINATION
ObjectState name for a immediate unit destination.
Definition: LImmDstRegisterField.hh:74
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
LImmDstRegisterField::OSNAME_LIMM_DST_REGISTER_FIELD
static const std::string OSNAME_LIMM_DST_REGISTER_FIELD
ObjectState name for long immediate destination register field.
Definition: LImmDstRegisterField.hh:70
MapTools::containsKey
static bool containsKey(const MapType &aMap, const KeyType &aKey)
LImmDstRegisterField::addDestination
void addDestination(const std::string &instructionTemplate, const std::string &immediateUnit)
Definition: LImmDstRegisterField.cc:129
InstructionField::loadState
virtual void loadState(const ObjectState *state)
Definition: InstructionField.cc:242
LImmDstRegisterField::OSKEY_ITEMP
static const std::string OSKEY_ITEMP
ObjectState attribute key for the name of the instruction template.
Definition: LImmDstRegisterField.hh:76
ObjectState::intAttribute
int intAttribute(const std::string &name) const
Definition: ObjectState.cc:276
BinaryEncoding::removeLongImmDstRegisterField
void removeLongImmDstRegisterField(LImmDstRegisterField &field)
Definition: BinaryEncoding.cc:475
LImmDstRegisterField::parent
BinaryEncoding * parent() const
Definition: LImmDstRegisterField.cc:106
InstructionField::InstructionField
InstructionField(InstructionField *parent)
Definition: InstructionField.cc:56
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100