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

#include <ImmediateControlField.hh>

Inheritance diagram for ImmediateControlField:
Inheritance graph
Collaboration diagram for ImmediateControlField:
Collaboration graph

Public Member Functions

 ImmediateControlField (BinaryEncoding &parent)
 
 ImmediateControlField (const ObjectState *state, BinaryEncoding &parent)
 
virtual ~ImmediateControlField ()
 
BinaryEncodingparent () const
 
int templateCount () const
 
std::string instructionTemplate (int index) const
 
bool hasTemplateEncoding (const std::string &name) const
 
unsigned int templateEncoding (const std::string &name) const
 
void addTemplateEncoding (const std::string &name, unsigned int encoding)
 
void removeTemplateEncoding (const std::string &name)
 
virtual int width () const
 
virtual int childFieldCount () const
 
virtual InstructionFieldchildField (int) const
 
virtual void loadState (const ObjectState *state)
 
virtual ObjectStatesaveState () const
 
- Public Member Functions inherited from InstructionField
virtual ~InstructionField ()
 
InstructionFieldparent () 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_IMM_CONTROL_FIELD = "ic_field"
 ObjectState name for immediate control field. More...
 
static const std::string OSNAME_TEMPLATE_MAP = "temp_map"
 ObjectState name for a template mapping. More...
 
static const std::string OSKEY_TEMPLATE_NAME = "temp_name"
 ObjectState attribute key for the name of the instruction template. More...
 
static const std::string OSKEY_ENCODING = "encoding"
 ObjectState attribute key for the encoding of the instruction template. 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, unsigned int > EncodingMap
 A map type for binary encodings. More...
 

Private Member Functions

void clearTemplateEncodings ()
 

Private Attributes

EncodingMap templates_
 Binary encodings for instruction templates. 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

ImmediateControlField is a specialised InstructionField and represents the field of the TTA instruction that contains the long immediate control tag.

This tag defines the template of the instruction. A TTA instruction template specifies which move slots are used to program data transports and which are used to encode immediate bits. An ImmediateControlField object can never exist alone. It is always registered to a BinaryEncoding object.

Definition at line 57 of file ImmediateControlField.hh.

Member Typedef Documentation

◆ EncodingMap

typedef std::map<std::string, unsigned int> ImmediateControlField::EncodingMap
private

A map type for binary encodings.

Definition at line 95 of file ImmediateControlField.hh.

Constructor & Destructor Documentation

◆ ImmediateControlField() [1/2]

ImmediateControlField::ImmediateControlField ( BinaryEncoding parent)

The constructor.

Registers the immediate control field to the parent BinaryEncoding automatically. The field is added as the leftmost field of the TTA instruction.

Parameters
parentThe parent encoding map.
Exceptions
ObjectAlreadyExistsIf the given encoding map has an immediate control field already.

Definition at line 61 of file ImmediateControlField.cc.

63  setParent(NULL);
65  setParent(&parent);
66 }

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

Here is the call graph for this function:

◆ ImmediateControlField() [2/2]

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

The constructor.

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

Parameters
stateThe ObjectState tree.
parentThe parent encoding map.
Exceptions
ObjectStateLoadingExceptionIf an error occurs while loading the state.
ObjectAlreadyExistsIf the given encoding map has an immediate control field already.

Definition at line 80 of file ImmediateControlField.cc.

82  : InstructionField(state, &parent) {
83  loadState(state);
84  setParent(NULL);
86  setParent(&parent);
87 }

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

Here is the call graph for this function:

◆ ~ImmediateControlField()

ImmediateControlField::~ImmediateControlField ( )
virtual

The destructor.

Definition at line 92 of file ImmediateControlField.cc.

92  {
93  BinaryEncoding* oldParent = parent();
94  assert(oldParent != NULL);
95  setParent(NULL);
96  oldParent->unsetImmediateControlField();
97 }

References assert, parent(), InstructionField::setParent(), and BinaryEncoding::unsetImmediateControlField().

Here is the call graph for this function:

Member Function Documentation

◆ addTemplateEncoding()

void ImmediateControlField::addTemplateEncoding ( const std::string &  name,
unsigned int  encoding 
)

Assings the given code to the instruction template identified by the given name.

If the given instruction template has an encoding already, replaces the encoding with the given one.

Parameters
nameName of the instruction template.
encodingThe code to be assigned.
Exceptions
ObjectAlreadyExistsIf the given code is already assigned to another instruction template.

Definition at line 206 of file ImmediateControlField.cc.

207  {
208  if (MapTools::containsValue(templates_, encoding) &&
209  MapTools::keyForValue<string>(templates_, encoding) != name) {
210  const string procName = "ImmediateControlField::addTemplateEncoding";
211  throw ObjectAlreadyExists(__FILE__, __LINE__, procName);
212  }
213 
214 
215  pair<EncodingMap::iterator, bool> result =
216  templates_.insert(pair<string, int>(name, encoding));
217 
218  if (!result.second) {
219  // if there is a code for the template already
220  EncodingMap::iterator iter = templates_.find(name);
221  assert(iter != templates_.end());
222  iter->second = encoding;
223  }
224 }

References assert, MapTools::containsValue(), and templates_.

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

Here is the call graph for this function:

◆ childField()

InstructionField & ImmediateControlField::childField ( int  ) const
virtual

Always throws OutOfRange exception because immediate control field does not have any child fields.

Returns
Never returns.
Exceptions
OutOfRangeAlways thrown.

Reimplemented from InstructionField.

Definition at line 276 of file ImmediateControlField.cc.

276  {
277  const string procName = "ImmediateControlField::childField";
278  throw OutOfRange(__FILE__, __LINE__, procName);
279 }

◆ childFieldCount()

int ImmediateControlField::childFieldCount ( ) const
virtual

Always returns 0.

Returns
0.

Implements InstructionField.

Definition at line 263 of file ImmediateControlField.cc.

263  {
264  return 0;
265 }

◆ clearTemplateEncodings()

void ImmediateControlField::clearTemplateEncodings ( )
private

Clears all the template encodings from the immediate control field.

Definition at line 346 of file ImmediateControlField.cc.

346  {
347  templates_.clear();
348 }

References templates_.

Referenced by loadState().

◆ hasTemplateEncoding()

bool ImmediateControlField::hasTemplateEncoding ( const std::string &  name) const

Tells whether the instruction template with the given name has has a binary encoding in this field.

Parameters
nameName of the instruction template.
Returns
True if the template has a binary encoding, otherwise false.

Definition at line 167 of file ImmediateControlField.cc.

167  {
168  return MapTools::containsKey(templates_, name);
169 }

References MapTools::containsKey(), and templates_.

Referenced by BEMValidator::checkImmediateControlField(), DefaultDecoderGenerator::instructionTemplateCondition(), and templateEncoding().

Here is the call graph for this function:

◆ instructionTemplate()

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

Returns the name of the instruction template encoded in this field at the given position.

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

Definition at line 138 of file ImmediateControlField.cc.

138  {
139  if (index < 0 || index >= templateCount()) {
140  const string procName = "ImmediateControlField::instructionTemplate";
141  throw OutOfRange(__FILE__, __LINE__, procName);
142  }
143 
144  int counter(0);
145  for (EncodingMap::const_iterator iter = templates_.begin();
146  iter != templates_.end(); iter++) {
147 
148  if (counter == index) {
149  return iter->first;
150  } else {
151  counter++;
152  }
153  }
154 
155  assert(false);
156  return "";
157 }

References assert, templateCount(), and templates_.

Referenced by BinaryEncoding::longestTemplateExtraBits(), printImmediateControlField(), saveState(), and BinaryEncoding::width().

Here is the call graph for this function:

◆ loadState()

void ImmediateControlField::loadState ( const ObjectState state)
virtual

Loads the state of the immediate control field from the given ObjectState tree.

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

Reimplemented from InstructionField.

Definition at line 290 of file ImmediateControlField.cc.

290  {
293  const string procName = "ImmediateControlField::loadState";
294 
295  if (state->name() != OSNAME_IMM_CONTROL_FIELD) {
296  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
297  }
298 
299  try {
300  for (int i = 0; i < state->childCount(); i++) {
301  ObjectState* child = state->child(i);
302  if (child->name() != OSNAME_TEMPLATE_MAP) {
304  __FILE__, __LINE__, procName);
305  }
306  string tempName = child->stringAttribute(OSKEY_TEMPLATE_NAME);
307  int encoding = child->intAttribute(OSKEY_ENCODING);
308  addTemplateEncoding(tempName, encoding);
309  }
310 
311  } catch (const Exception& exception) {
313  __FILE__, __LINE__, procName, exception.errorMessage());
314  }
315 }

References addTemplateEncoding(), ObjectState::child(), ObjectState::childCount(), clearTemplateEncodings(), Exception::errorMessage(), ObjectState::intAttribute(), InstructionField::loadState(), ObjectState::name(), OSKEY_ENCODING, OSKEY_TEMPLATE_NAME, OSNAME_IMM_CONTROL_FIELD, OSNAME_TEMPLATE_MAP, and ObjectState::stringAttribute().

Referenced by ImmediateControlField().

Here is the call graph for this function:

◆ parent()

BinaryEncoding * ImmediateControlField::parent ( ) const

Returns the parent encoding map.

Returns
The parent encoding map.

Definition at line 106 of file ImmediateControlField.cc.

106  {
108  if (parent == NULL) {
109  return NULL;
110  } else {
111  BinaryEncoding* encoding = dynamic_cast<BinaryEncoding*>(parent);
112  assert(encoding != NULL);
113  return encoding;
114  }
115 }

References assert, and InstructionField::parent().

Referenced by ImmediateControlField(), BinaryEncoding::setImmediateControlField(), and ~ImmediateControlField().

Here is the call graph for this function:

◆ removeTemplateEncoding()

void ImmediateControlField::removeTemplateEncoding ( const std::string &  name)

Removes the code of the instruction template with the given name.

Parameters
nameName of the instruction template.

Definition at line 232 of file ImmediateControlField.cc.

232  {
233  templates_.erase(name);
234 }

References templates_.

◆ saveState()

ObjectState * ImmediateControlField::saveState ( ) const
virtual

Saves the state of the immediate control field to an ObjectState tree.

Returns
The newly created ObjectState tree.

Reimplemented from InstructionField.

Definition at line 323 of file ImmediateControlField.cc.

323  {
324 
328 
329  for (int i = 0; i < templateCount(); i++) {
330  string temp = instructionTemplate(i);
331  int encoding = templateEncoding(temp);
333  state->addChild(tempMap);
334  tempMap->setAttribute(OSKEY_TEMPLATE_NAME, temp);
335  tempMap->setAttribute(OSKEY_ENCODING, encoding);
336  }
337 
338  return state;
339 }

References ObjectState::addChild(), instructionTemplate(), OSKEY_ENCODING, InstructionField::OSKEY_POSITION, OSKEY_TEMPLATE_NAME, OSNAME_IMM_CONTROL_FIELD, OSNAME_TEMPLATE_MAP, InstructionField::relativePosition(), InstructionField::saveState(), ObjectState::setAttribute(), ObjectState::setName(), templateCount(), and templateEncoding().

Here is the call graph for this function:

◆ templateCount()

int ImmediateControlField::templateCount ( ) const

Returns the number of instruction templates with a binary encoding assigned.

Returns
The number of instruction templates.

Definition at line 124 of file ImmediateControlField.cc.

124  {
125  return templates_.size();
126 }

References templates_.

Referenced by instructionTemplate(), BinaryEncoding::longestTemplateExtraBits(), printImmediateControlField(), saveState(), and BinaryEncoding::width().

◆ templateEncoding()

unsigned int ImmediateControlField::templateEncoding ( const std::string &  name) const

Returns the code that identifies the instruction template with the given name.

Parameters
nameName of the instruction template.
Returns
The code that identifies the given instruction template.
Exceptions
InstanceNotFoundIf the given instruction template does not have a binary encoding in this field.

Definition at line 182 of file ImmediateControlField.cc.

182  {
183  if (!hasTemplateEncoding(name)) {
184  const string procName = "ImmediateControlField::templateEncoding";
185  throw InstanceNotFound(__FILE__, __LINE__, procName);
186  }
187 
188  EncodingMap::const_iterator iter = templates_.find(name);
189  assert(iter != templates_.end());
190  return iter->second;
191 }

References assert, hasTemplateEncoding(), and templates_.

Referenced by CodeCompressorPlugin::addBitsForICField(), DefaultDecoderGenerator::instructionTemplateCondition(), printImmediateControlField(), saveState(), and DefaultDecoderGenerator::writeSquashSignalGenerationProcess().

Here is the call graph for this function:

◆ width()

int ImmediateControlField::width ( ) const
virtual

Returns the bit width of the immediate control field.

Returns
The bit width of the field.

Implements InstructionField.

Definition at line 243 of file ImmediateControlField.cc.

243  {
244  int minWidth(0);
245  for (EncodingMap::const_iterator iter = templates_.begin();
246  iter != templates_.end(); iter++) {
247  int encoding = iter->second;
248  int requiredBits = MathTools::bitLength(encoding);
249  if (requiredBits > minWidth) {
250  minWidth = requiredBits;
251  }
252  }
253  return minWidth + extraBits();
254 }

References MathTools::bitLength(), InstructionField::extraBits(), and templates_.

Referenced by CodeCompressorPlugin::addBitsForICField(), CodeCompressorPlugin::bemInstructionBits(), CodeCompressorPlugin::firstMoveSlotIndex(), printImmediateControlField(), BinaryEncoding::width(), DefaultDecoderGenerator::writeInstructionDismembering(), and DefaultDecoderGenerator::writeLongImmediateTagSignal().

Here is the call graph for this function:

Member Data Documentation

◆ OSKEY_ENCODING

const std::string ImmediateControlField::OSKEY_ENCODING = "encoding"
static

ObjectState attribute key for the encoding of the instruction template.

Definition at line 91 of file ImmediateControlField.hh.

Referenced by loadState(), BEMSerializer::longImmTagToFile(), BEMSerializer::longImmTagToOM(), and saveState().

◆ OSKEY_TEMPLATE_NAME

const std::string ImmediateControlField::OSKEY_TEMPLATE_NAME = "temp_name"
static

ObjectState attribute key for the name of the instruction template.

Definition at line 88 of file ImmediateControlField.hh.

Referenced by loadState(), BEMSerializer::longImmTagToFile(), BEMSerializer::longImmTagToOM(), and saveState().

◆ OSNAME_IMM_CONTROL_FIELD

const std::string ImmediateControlField::OSNAME_IMM_CONTROL_FIELD = "ic_field"
static

◆ OSNAME_TEMPLATE_MAP

const std::string ImmediateControlField::OSNAME_TEMPLATE_MAP = "temp_map"
static

ObjectState name for a template mapping.

Definition at line 86 of file ImmediateControlField.hh.

Referenced by loadState(), BEMSerializer::longImmTagToFile(), BEMSerializer::longImmTagToOM(), and saveState().

◆ templates_

EncodingMap ImmediateControlField::templates_
private

The documentation for this class was generated from the following files:
ImmediateControlField::OSKEY_TEMPLATE_NAME
static const std::string OSKEY_TEMPLATE_NAME
ObjectState attribute key for the name of the instruction template.
Definition: ImmediateControlField.hh:88
BinaryEncoding
Definition: BinaryEncoding.hh:61
InstructionField::OSKEY_POSITION
static const std::string OSKEY_POSITION
ObjectState attribute key for the relative position of the field.
Definition: InstructionField.hh:77
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
ObjectStateLoadingException
Definition: Exception.hh:551
OutOfRange
Definition: Exception.hh:320
ImmediateControlField::OSNAME_IMM_CONTROL_FIELD
static const std::string OSNAME_IMM_CONTROL_FIELD
ObjectState name for immediate control field.
Definition: ImmediateControlField.hh:84
BinaryEncoding::setImmediateControlField
void setImmediateControlField(ImmediateControlField &field)
Definition: BinaryEncoding.cc:367
BinaryEncoding::unsetImmediateControlField
void unsetImmediateControlField()
Definition: BinaryEncoding.cc:385
ImmediateControlField::parent
BinaryEncoding * parent() const
Definition: ImmediateControlField.cc:106
ImmediateControlField::templates_
EncodingMap templates_
Binary encodings for instruction templates.
Definition: ImmediateControlField.hh:100
ObjectState
Definition: ObjectState.hh:59
ImmediateControlField::templateCount
int templateCount() const
Definition: ImmediateControlField.cc:124
ObjectState::setName
void setName(const std::string &name)
InstructionField
Definition: InstructionField.hh:43
ImmediateControlField::hasTemplateEncoding
bool hasTemplateEncoding(const std::string &name) const
Definition: ImmediateControlField.cc:167
InstructionField::saveState
virtual ObjectState * saveState() const
Definition: InstructionField.cc:268
assert
#define assert(condition)
Definition: Application.hh:86
ImmediateControlField::OSNAME_TEMPLATE_MAP
static const std::string OSNAME_TEMPLATE_MAP
ObjectState name for a template mapping.
Definition: ImmediateControlField.hh:86
InstructionField::setParent
void setParent(InstructionField *parent)
Definition: InstructionField.cc:282
InstructionField::parent
InstructionField * parent() const
Definition: InstructionField.cc:100
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
ImmediateControlField::clearTemplateEncodings
void clearTemplateEncodings()
Definition: ImmediateControlField.cc:346
ObjectState::name
std::string name() const
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
ImmediateControlField::instructionTemplate
std::string instructionTemplate(int index) const
Definition: ImmediateControlField.cc:138
MapTools::containsKey
static bool containsKey(const MapType &aMap, const KeyType &aKey)
InstructionField::extraBits
int extraBits() const
Definition: InstructionField.cc:229
MapTools::containsValue
static bool containsValue(const MapType &aMap, const ValueType &aValue)
ObjectAlreadyExists
Definition: Exception.hh:1002
InstructionField::loadState
virtual void loadState(const ObjectState *state)
Definition: InstructionField.cc:242
MathTools::bitLength
static unsigned int bitLength(long unsigned int number)
ImmediateControlField::OSKEY_ENCODING
static const std::string OSKEY_ENCODING
ObjectState attribute key for the encoding of the instruction template.
Definition: ImmediateControlField.hh:91
InstructionField::relativePosition
int relativePosition() const
Definition: InstructionField.cc:160
ObjectState::intAttribute
int intAttribute(const std::string &name) const
Definition: ObjectState.cc:276
ImmediateControlField::templateEncoding
unsigned int templateEncoding(const std::string &name) const
Definition: ImmediateControlField.cc:182
ImmediateControlField::loadState
virtual void loadState(const ObjectState *state)
Definition: ImmediateControlField.cc:290
ImmediateControlField::addTemplateEncoding
void addTemplateEncoding(const std::string &name, unsigned int encoding)
Definition: ImmediateControlField.cc:206
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
InstanceNotFound
Definition: Exception.hh:304