OpenASIP 2.2
Loading...
Searching...
No Matches
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.
 
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.
 

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.
 
int extraBits_
 The number of extra bits.
 
InstructionFieldparent_
 The parent instruction field.
 

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}
InstructionField * parent() const
int relativePos_
Indicates the relative position of the field.
int extraBits_
The number of extra bits.
InstructionField * parent_
The parent instruction field.
virtual int childFieldCount() const =0

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

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}
virtual int width() const =0
virtual InstructionField & childField(int position) const
int relativePosition() const

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 BinaryEncoding, MoveSlot, NullInstructionField, SlotField, GuardField, and ImmediateControlField.

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}
static NullInstructionField & instance()

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, ImmediateControlField, ImmediateSlotField, LImmDstRegisterField, MoveSlot, NullInstructionField, and SlotField.

Referenced by childField(), InstructionField(), 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, ImmediateControlField, ImmediateSlotField, LImmDstRegisterField, MoveSlot, SlotField, and SourceField.

Definition at line 242 of file InstructionField.cc.

242 {
243 const string procName = "InstructionField::loadState";
244
245 try {
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}
#define __func__
std::string errorMessage() const
Definition Exception.cc:123
void setExtraBits(int bits)
static const std::string OSKEY_POSITION
ObjectState attribute key for the relative position of the field.
static const std::string OSKEY_EXTRA_BITS
ObjectState attribute key for the number of extra bits.
std::string stringAttribute(const std::string &name) const
int intAttribute(const std::string &name) const

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

Referenced by InstructionField(), GuardField::loadState(), ImmediateControlField::loadState(), ImmediateSlotField::loadState(), LImmDstRegisterField::loadState(), MoveSlot::loadState(), and SlotField::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(), InstructionField(), GuardField::parent(), ImmediateControlField::parent(), ImmediateSlotField::parent(), LImmDstRegisterField::parent(), MoveSlot::parent(), SlotField::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(), BinaryEncoding::childField(), MoveSlot::childField(), loadState(), ImmediateControlField::saveState(), 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}
bool hasAttribute(const std::string &name) const
void removeChild(ObjectState *child)
ObjectState * child(int index) const
void addChild(ObjectState *child)
int childCount() const

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

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

Here is the call graph for this function:

◆ saveState()

ObjectState * InstructionField::saveState ( ) const
virtual

Saves the state of the object to an ObjectState tree.

Returns
The newly created ObjectState tree.

Implements Serializable.

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

Definition at line 268 of file InstructionField.cc.

268 {
272 return state;
273}
static const std::string OSNAME_INSTRUCTION_FIELD
ObjectState name for instruction field.
void setAttribute(const std::string &name, const std::string &value)

References extraBits(), OSKEY_EXTRA_BITS, OSKEY_POSITION, OSNAME_INSTRUCTION_FIELD, relativePosition(), and ObjectState::setAttribute().

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

Here is the call graph for this function:

◆ 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}
#define assert(condition)
virtual void setRelativePosition(int position)

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

Referenced by GuardField::GuardField(), and setRelativePosition().

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(), InstructionField(), relativePosition(), and setRelativePosition().


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