OpenASIP  2.0
Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Private Attributes | List of all members
InstructionField Class Referenceabstract

#include <InstructionField.hh>

Inheritance diagram for InstructionField:
Inheritance graph
Collaboration diagram for InstructionField:
Collaboration graph

Public Member Functions

virtual ~InstructionField ()
 
InstructionFieldparent () const
 
virtual int childFieldCount () const =0
 
virtual InstructionFieldchildField (int position) const
 
virtual int width () const =0
 
int bitPosition () const
 
int relativePosition () const
 
virtual void setRelativePosition (int position)
 
void setExtraBits (int bits)
 
int extraBits () 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_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...
 

Protected Member Functions

 InstructionField (InstructionField *parent)
 
 InstructionField (const ObjectState *state, InstructionField *parent)
 
void setParent (InstructionField *parent)
 

Static Protected Member Functions

static void reorderSubfields (ObjectState *state)
 

Private Attributes

int relativePos_
 Indicates the relative position of the field. More...
 
int extraBits_
 The number of extra bits. More...
 
InstructionFieldparent_
 The parent instruction field. More...
 

Detailed Description

InstructionField is an abstract base class that represents the properties common to all types of bit fields of the TTA instruction word.

Definition at line 43 of file InstructionField.hh.

Constructor & Destructor Documentation

◆ ~InstructionField()

InstructionField::~InstructionField ( )
virtual

The destructor.

Definition at line 88 of file InstructionField.cc.

88  {
89 }

◆ InstructionField() [1/2]

InstructionField::InstructionField ( InstructionField parent)
protected

The constructor.

Parameters
relativePositionRelative position of the instruction field within its parent field.
parentThe parent instruction field.

Definition at line 56 of file InstructionField.cc.

56  :
58 
59  if (parent != NULL) {
61  }
62 }

References childFieldCount(), parent(), and relativePos_.

Here is the call graph for this function:

◆ InstructionField() [2/2]

InstructionField::InstructionField ( const ObjectState state,
InstructionField parent 
)
protected

The constructor.

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

Parameters
stateThe ObjectState tree.
parentThe parent instruction field.
Exceptions
ObjectStateLoadingExceptionIf an error occurs while loading the state.

Definition at line 75 of file InstructionField.cc.

78  if (parent != NULL) {
80  }
81 
82  loadState(state);
83 }

References childFieldCount(), loadState(), parent(), and relativePos_.

Here is the call graph for this function:

Member Function Documentation

◆ bitPosition()

int InstructionField::bitPosition ( ) const

Returns the bit-accurate position of the field within its parent field.

Returns
The position.

Definition at line 132 of file InstructionField.cc.

132  {
133 
134  InstructionField* parent = this->parent();
135 
136  if (parent == NULL) {
137  return 0;
138  }
139 
140  int position(0);
141 
142  for (int i = 0; i < relativePosition(); i++) {
144  position += childField.width();
145  }
146 
147  return position;
148 }

References childField(), parent(), relativePosition(), and width().

Referenced by BEMTester::canAddComponentPriorityEncoding(), BEMTester::fieldsOverlap(), ProGe::RV32MicroCodeGenerator::findBusWidths(), printImmediateControlField(), printLImmDstRegisterField(), printMoveSlot(), DefaultDecoderGenerator::writeInstructionDismembering(), and DefaultDecoderGenerator::writeInstructionTemplateProcedures().

Here is the call graph for this function:

◆ childField()

InstructionField & InstructionField::childField ( int  position) const
virtual

Returns the child field which has the given relative position within the instruction field.

This base class implementation just checks whether the given position is out of range and throw the exception if necessary.

Parameters
positionThe position.
Exceptions
OutOfRangeIf the position is negative or not smaller than the number of child fields.

Reimplemented in GuardField, ImmediateControlField, BinaryEncoding, MoveSlot, SlotField, and NullInstructionField.

Definition at line 117 of file InstructionField.cc.

117  {
118  if (position < 0 || position >= childFieldCount()) {
119  const string procName = "InstructionField::childField";
120  throw OutOfRange(__FILE__, __LINE__, procName);
121  }
122 
124 }

References childFieldCount(), and NullInstructionField::instance().

Referenced by bitPosition(), MoveSlot::childField(), and setRelativePosition().

Here is the call graph for this function:

◆ childFieldCount()

virtual int InstructionField::childFieldCount ( ) const
pure virtual

Returns the number of (immediate) child fields within the instruction field.

Implemented in BinaryEncoding, GuardField, MoveSlot, SlotField, ImmediateControlField, LImmDstRegisterField, ImmediateSlotField, and NullInstructionField.

Referenced by childField(), InstructionField(), and setRelativePosition().

◆ extraBits()

int InstructionField::extraBits ( ) const

◆ loadState()

void InstructionField::loadState ( const ObjectState state)
virtual

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

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

Implements Serializable.

Reimplemented in BinaryEncoding, GuardField, MoveSlot, SlotField, LImmDstRegisterField, ImmediateControlField, SourceField, and ImmediateSlotField.

Definition at line 242 of file InstructionField.cc.

242  {
243  const string procName = "InstructionField::loadState";
244 
245  try {
247  if (relativePosition() != state->intAttribute(OSKEY_POSITION)) {
248  format errorMsg(
249  "Invalid relative position %1%. Should be %2%.");
250  errorMsg % state->stringAttribute(OSKEY_POSITION) %
253  __FILE__, __LINE__, __func__, errorMsg.str());
254  }
255 
256  } catch (const Exception& exception) {
258  __FILE__, __LINE__, procName, exception.errorMessage());
259  }
260 }

References __func__, Exception::errorMessage(), ObjectState::intAttribute(), OSKEY_EXTRA_BITS, OSKEY_POSITION, relativePosition(), setExtraBits(), and ObjectState::stringAttribute().

Referenced by InstructionField(), ImmediateSlotField::loadState(), ImmediateControlField::loadState(), LImmDstRegisterField::loadState(), SlotField::loadState(), MoveSlot::loadState(), and GuardField::loadState().

Here is the call graph for this function:

◆ parent()

InstructionField * InstructionField::parent ( ) const

Returns the parent instruction field.

Returns NULL if the field has no parent field (BinaryEncoding).

Returns
The parent instruction field.

Definition at line 100 of file InstructionField.cc.

100  {
101  return parent_;
102 }

References parent_.

Referenced by bitPosition(), InstructionField(), ImmediateSlotField::parent(), LImmDstRegisterField::parent(), GuardField::parent(), SlotField::parent(), ImmediateControlField::parent(), MoveSlot::parent(), setParent(), setRelativePosition(), and BinaryEncoding::unsetImmediateControlField().

◆ relativePosition()

int InstructionField::relativePosition ( ) const

Returns the relative position of the field compared to sibling fields.

If the field is the rightmost field, returns 0. The leftmost field returns the number of sibling fields - 1.

Returns
The relative position.

Definition at line 160 of file InstructionField.cc.

160  {
161  return relativePos_;
162 }

References relativePos_.

Referenced by bitPosition(), MoveSlot::childField(), BinaryEncoding::childField(), loadState(), saveState(), ImmediateControlField::saveState(), and setRelativePosition().

◆ reorderSubfields()

void InstructionField::reorderSubfields ( ObjectState state)
staticprotected

Sorts the child ObjectState instances of the given ObjectState instance such that they are returned by child(index) method in the correct order.

The correct order means that at first the rightmost subfield is returned and then the next to left and so on.

Parameters
stateThe ObjectState instance.

Definition at line 297 of file InstructionField.cc.

297  {
298 
299  typedef list<ObjectState*> OSList;
300  OSList list;
301 
302  for (int i = 0; i < state->childCount();) {
303  ObjectState* child = state->child(i);
305  state->removeChild(child);
306  int position = child->intAttribute(
308 
309  // insert the object to the list at correct position
310  bool inserted = false;
311  for (OSList::iterator iter = list.begin(); iter != list.end();
312  iter++) {
313  ObjectState* item = *iter;
314  int itemPosition = item->intAttribute(
316  if (itemPosition > position) {
317  list.insert(iter, child);
318  inserted = true;
319  break;
320  }
321  }
322  if (!inserted) {
323  list.push_back(child);
324  }
325  } else {
326  i++;
327  }
328  }
329 
330  // add the sub fields again in the correct order
331  for (OSList::const_iterator iter = list.begin(); iter != list.end();
332  iter++) {
333  ObjectState* child = *iter;
334  state->addChild(child);
335  }
336 }

References ObjectState::addChild(), ObjectState::child(), ObjectState::childCount(), ObjectState::hasAttribute(), ObjectState::intAttribute(), OSKEY_POSITION, and ObjectState::removeChild().

Referenced by MoveSlot::loadState(), and BinaryEncoding::loadState().

Here is the call graph for this function:

◆ saveState()

ObjectState * InstructionField::saveState ( ) const
virtual

◆ setExtraBits()

void InstructionField::setExtraBits ( int  bits)

Sets the number of extra (zero) bits to the field.

The field can be forced longer than necessary by defining some number of extra bits. In practice, there will be the given amount of zeros always in the MSB end of the field.

Parameters
bitsThe number of extra bits.
Exceptions
OutOfRangeIf the given number is negative.

Definition at line 214 of file InstructionField.cc.

214  {
215  if (bits < 0) {
216  const string procName = "InstructionField::setExtraBits";
217  throw OutOfRange(__FILE__, __LINE__, procName);
218  }
219 
220  extraBits_ = bits;
221 }

References extraBits_.

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

◆ setParent()

void InstructionField::setParent ( InstructionField parent)
protected

◆ setRelativePosition()

void InstructionField::setRelativePosition ( int  position)
virtual

Sets a new relative position for the field.

Parameters
positionThe new relative position.
Exceptions
OutOfRangeIf the given position is negative.

Definition at line 172 of file InstructionField.cc.

172  {
173  if (position < 0 || position >= parent()->childFieldCount()) {
174  const string procName = "InstructionField::setRelativePosition";
175  throw OutOfRange(__FILE__, __LINE__, procName);
176  }
177 
178  InstructionField& fieldToMove = parent()->childField(position);
179  relativePos_ = position;
180 
181  int childFields = parent()->childFieldCount();
182  int emptyPosition(-1);
183  for (int i = 0; i < childFields; i++) {
185  emptyPosition = i;
186  break;
187  }
188  }
189 
190  if (emptyPosition != -1) {
191  if (emptyPosition < fieldToMove.relativePosition()) {
192  fieldToMove.
193  setRelativePosition(fieldToMove.relativePosition() - 1);
194  } else if (emptyPosition > fieldToMove.relativePosition()) {
195  fieldToMove.
196  setRelativePosition(fieldToMove.relativePosition() + 1);
197  } else {
198  assert(false);
199  }
200  }
201 }

References assert, childField(), childFieldCount(), NullInstructionField::instance(), parent(), relativePos_, and relativePosition().

Referenced by GuardField::GuardField().

Here is the call graph for this function:

◆ width()

virtual int InstructionField::width ( ) const
pure virtual

Member Data Documentation

◆ extraBits_

int InstructionField::extraBits_
private

The number of extra bits.

Definition at line 90 of file InstructionField.hh.

Referenced by extraBits(), and setExtraBits().

◆ OSKEY_EXTRA_BITS

const std::string InstructionField::OSKEY_EXTRA_BITS = "extra_bits"
static

◆ OSKEY_POSITION

const std::string InstructionField::OSKEY_POSITION = "position"
static

◆ OSNAME_INSTRUCTION_FIELD

const std::string InstructionField::OSNAME_INSTRUCTION_FIELD = "instr_field"
static

ObjectState name for instruction field.

Definition at line 73 of file InstructionField.hh.

Referenced by saveState().

◆ parent_

InstructionField* InstructionField::parent_
private

The parent instruction field.

Definition at line 92 of file InstructionField.hh.

Referenced by parent(), and setParent().

◆ relativePos_

int InstructionField::relativePos_
private

Indicates the relative position of the field.

Definition at line 88 of file InstructionField.hh.

Referenced by InstructionField(), relativePosition(), and setRelativePosition().


The documentation for this class was generated from the following files:
ObjectState::hasAttribute
bool hasAttribute(const std::string &name) const
Definition: ObjectState.cc:205
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
InstructionField::childField
virtual InstructionField & childField(int position) const
Definition: InstructionField.cc:117
ObjectState
Definition: ObjectState.hh:59
InstructionField::relativePos_
int relativePos_
Indicates the relative position of the field.
Definition: InstructionField.hh:88
InstructionField::OSKEY_EXTRA_BITS
static const std::string OSKEY_EXTRA_BITS
ObjectState attribute key for the number of extra bits.
Definition: InstructionField.hh:75
NullInstructionField::instance
static NullInstructionField & instance()
Definition: NullInstructionField.cc:62
InstructionField
Definition: InstructionField.hh:43
assert
#define assert(condition)
Definition: Application.hh:86
InstructionField::width
virtual int width() const =0
__func__
#define __func__
Definition: Application.hh:67
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
InstructionField::OSNAME_INSTRUCTION_FIELD
static const std::string OSNAME_INSTRUCTION_FIELD
ObjectState name for instruction field.
Definition: InstructionField.hh:73
InstructionField::setExtraBits
void setExtraBits(int bits)
Definition: InstructionField.cc:214
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
InstructionField::childFieldCount
virtual int childFieldCount() const =0
InstructionField::extraBits
int extraBits() const
Definition: InstructionField.cc:229
ObjectState::removeChild
void removeChild(ObjectState *child)
Definition: ObjectState.cc:389
InstructionField::loadState
virtual void loadState(const ObjectState *state)
Definition: InstructionField.cc:242
InstructionField::relativePosition
int relativePosition() const
Definition: InstructionField.cc:160
ObjectState::intAttribute
int intAttribute(const std::string &name) const
Definition: ObjectState.cc:276
InstructionField::parent_
InstructionField * parent_
The parent instruction field.
Definition: InstructionField.hh:92
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100
InstructionField::extraBits_
int extraBits_
The number of extra bits.
Definition: InstructionField.hh:90
InstructionField::setRelativePosition
virtual void setRelativePosition(int position)
Definition: InstructionField.cc:172