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

#include <SlotField.hh>

Inheritance diagram for SlotField:
Inheritance graph
Collaboration diagram for SlotField:
Collaboration graph

Public Member Functions

virtual ~SlotField ()
 
MoveSlotparent () const
 
void addSocketEncoding (SocketEncoding &encoding)
 
void removeSocketEncoding (SocketEncoding &encoding)
 
int socketEncodingCount () const
 
SocketEncodingsocketEncoding (int index) const
 
bool hasSocketEncoding (const std::string &socket) const
 
SocketEncodingsocketEncoding (const std::string &socket) const
 
void setNoOperationEncoding (NOPEncoding &encoding)
 
void unsetNoOperationEncoding ()
 
bool hasNoOperationEncoding () const
 
NOPEncodingnoOperationEncoding () const
 
BinaryEncoding::Position componentIDPosition () const
 
virtual int width () const
 
virtual int childFieldCount () const
 
virtual InstructionFieldchildField (int position) 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_SLOT_FIELD = "slot_field"
 ObjectState name for slot field.
 
static const std::string OSKEY_COMPONENT_ID_POSITION = "comp_id_pos"
 ObjectState attribute key for component ID position.
 
- 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.
 

Protected Member Functions

 SlotField (BinaryEncoding::Position componentIDPos, MoveSlot &parent)
 
 SlotField (const ObjectState *state, MoveSlot &parent)
 
- Protected Member Functions inherited from InstructionField
 InstructionField (InstructionField *parent)
 
 InstructionField (const ObjectState *state, InstructionField *parent)
 
void setParent (InstructionField *parent)
 

Private Types

typedef std::vector< SocketEncoding * > SocketEncodingTable
 A container type for socket encodings.
 

Private Member Functions

void clearSocketEncodings ()
 
void clearNoOperationEncoding ()
 

Private Attributes

NOPEncodingnopEncoding_
 The NOP encoding.
 
SocketEncodingTable encodings_
 The container for socket encodings.
 
BinaryEncoding::Position componentIDPos_
 Position of the socket and bridge IDs within the field.
 

Additional Inherited Members

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

Detailed Description

SlotField is an abstract base class that models the properties common to SourceField and DestinationField classes.

SlotField contains and manages the encodings for sockets. Encodings for different sources and destinations consists of two parts: socket ID and optional socket code. Socket ID determines the socket. Socket code determines the port (and opcode) the socket is connected to. Socket ID may be on either left or right side of the socket code in the source or destination field. If socket ID is on the left side of socket code, socket ID is aligned to the left end of the whole source/destination field. In the other case, socket ID is aligned to the right end of the source/destination field.

Definition at line 58 of file SlotField.hh.

Member Typedef Documentation

◆ SocketEncodingTable

typedef std::vector<SocketEncoding*> SlotField::SocketEncodingTable
private

A container type for socket encodings.

Definition at line 99 of file SlotField.hh.

Constructor & Destructor Documentation

◆ ~SlotField()

SlotField::~SlotField ( )
virtual

The destructor.

Definition at line 88 of file SlotField.cc.

88 {
91}
void clearSocketEncodings()
Definition SlotField.cc:413
void clearNoOperationEncoding()
Definition SlotField.cc:422

References clearNoOperationEncoding(), and clearSocketEncodings().

Here is the call graph for this function:

◆ SlotField() [1/2]

SlotField::SlotField ( BinaryEncoding::Position  componentIDPos,
MoveSlot parent 
)
protected

The constructor.

Parameters
componentIDPosPosition of the socket (or bridge) ID within the source or destination field.
parentThe parent move slot.

Definition at line 60 of file SlotField.cc.

62 :
64 componentIDPos_(componentIDPos) {
65}
MoveSlot * parent() const
Definition SlotField.cc:98
NOPEncoding * nopEncoding_
The NOP encoding.
Definition SlotField.hh:105
BinaryEncoding::Position componentIDPos_
Position of the socket and bridge IDs within the field.
Definition SlotField.hh:109

◆ SlotField() [2/2]

SlotField::SlotField ( const ObjectState state,
MoveSlot parent 
)
protected

The constructor.

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

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

Definition at line 78 of file SlotField.cc.

79 : InstructionField(state, &parent),
80 nopEncoding_(NULL),
82 loadState(state);
83}
virtual void loadState(const ObjectState *state)
Definition SlotField.cc:358

References loadState().

Here is the call graph for this function:

Member Function Documentation

◆ addSocketEncoding()

void SlotField::addSocketEncoding ( SocketEncoding encoding)

Adds the given socket encoding.

This method is to be called from the constructor of SocketEncoding.

Parameters
encodingThe socket encoding to be added.
Exceptions
ObjectAlreadyExistsIf the field already has an encoding for the same socket or if the encoding is already assigned to another socket.

Definition at line 121 of file SlotField.cc.

121 {
122 // verify that this is called from SocketEncoding constructor
123 assert(encoding.parent() == NULL);
124
125 if (hasSocketEncoding(encoding.socketName()) ||
127 *this, encoding.encoding(), encoding.extraBits())) {
128 const string procName = "SlotField::addSocketEncoding";
129 throw ObjectAlreadyExists(__FILE__, __LINE__, procName);
130 }
131
132 encodings_.push_back(&encoding);
133}
#define assert(condition)
static bool canAddComponentEncoding(SlotField &field, unsigned int encoding, unsigned int extraBits)
Definition BEMTester.cc:73
unsigned int extraBits() const
Definition Encoding.cc:119
unsigned int encoding() const
Definition Encoding.cc:108
bool hasSocketEncoding(const std::string &socket) const
Definition SlotField.cc:188
SocketEncodingTable encodings_
The container for socket encodings.
Definition SlotField.hh:107
std::string socketName() const
SlotField * parent() const

References assert, BEMTester::canAddComponentEncoding(), Encoding::encoding(), encodings_, Encoding::extraBits(), hasSocketEncoding(), SocketEncoding::parent(), and SocketEncoding::socketName().

Referenced by SocketEncoding::setEncoding(), SocketEncoding::SocketEncoding(), and SocketEncoding::SocketEncoding().

Here is the call graph for this function:

◆ childField()

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

Always throws OutOfRange because slot fields do not have any child fields.

Returns
Never returns.
Exceptions
OutOfRangeAlways throws.

Reimplemented from InstructionField.

Definition at line 345 of file SlotField.cc.

345 {
346 const string procName = "SlotField::childField";
347 throw OutOfRange(__FILE__, __LINE__, procName);
348}

◆ childFieldCount()

int SlotField::childFieldCount ( ) const
virtual

Always returns 0 because slot fields do not have any child fields.

Returns
0.

Implements InstructionField.

Definition at line 333 of file SlotField.cc.

333 {
334 return 0;
335}

◆ clearNoOperationEncoding()

void SlotField::clearNoOperationEncoding ( )
private

Deletes the NOP encoding if one exists.

Definition at line 422 of file SlotField.cc.

422 {
424 delete nopEncoding_;
425 }
426}
bool hasNoOperationEncoding() const
Definition SlotField.cc:267

References hasNoOperationEncoding(), and nopEncoding_.

Referenced by loadState(), and ~SlotField().

Here is the call graph for this function:

◆ clearSocketEncodings()

void SlotField::clearSocketEncodings ( )
private

Clears all the socket encodings from the slot field.

Definition at line 413 of file SlotField.cc.

413 {
415}
static void deleteAllItems(SequenceType &aSequence)

References SequenceTools::deleteAllItems(), and encodings_.

Referenced by loadState(), and ~SlotField().

Here is the call graph for this function:

◆ componentIDPosition()

BinaryEncoding::Position SlotField::componentIDPosition ( ) const

◆ hasNoOperationEncoding()

bool SlotField::hasNoOperationEncoding ( ) const

Tells whether the slot field has a NOP encoding.

Returns
True if the slot field has a NOP encoding, otherwise false.

Definition at line 267 of file SlotField.cc.

267 {
268 return nopEncoding_ != NULL;
269}

References nopEncoding_.

Referenced by BEMTester::canAddComponentEncoding(), clearNoOperationEncoding(), CodeCompressorPlugin::encodeNOP(), noOperationEncoding(), printSlotFieldEncodings(), saveState(), setNoOperationEncoding(), unsetNoOperationEncoding(), and width().

◆ hasSocketEncoding()

bool SlotField::hasSocketEncoding ( const std::string &  socket) const

Tells whether the slot field has an encoding for the socket with the given name.

Parameters
socketName of the socket.
Returns
True if the slot field has an encoding for the given socket, otherwise false.

Definition at line 188 of file SlotField.cc.

188 {
189 for (SocketEncodingTable::const_iterator iter = encodings_.begin();
190 iter != encodings_.end(); iter++) {
191 SocketEncoding* encoding = *iter;
192 if (encoding->socketName() == socket) {
193 return true;
194 }
195 }
196 return false;
197}

References encodings_, and SocketEncoding::socketName().

Referenced by addSocketEncoding(), BEMValidator::checkDestinationField(), BEMValidator::checkSourceField(), CodeCompressorPlugin::encodeFUTerminal(), CodeCompressorPlugin::encodeIUTerminal(), and CodeCompressorPlugin::encodeRFTerminal().

Here is the call graph for this function:

◆ loadState()

void SlotField::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.

Reimplemented from InstructionField.

Reimplemented in SourceField.

Definition at line 358 of file SlotField.cc.

358 {
362
363 const string procName = "SlotField::loadState";
364
365 try {
368 for (int i = 0; i < state->childCount(); i++) {
369 ObjectState* child = state->child(i);
371 new SocketEncoding(child, *this);
372 } else if (child->name() == NOPEncoding::OSNAME_NOP_ENCODING) {
373 new NOPEncoding(child, *this);
374 }
375 }
376 } catch (const Exception& exception) {
378 __FILE__, __LINE__, procName, exception.errorMessage());
379 }
380}
std::string errorMessage() const
Definition Exception.cc:123
virtual void loadState(const ObjectState *state)
static const std::string OSNAME_NOP_ENCODING
ObjectState name for NOP encoding.
ObjectState * child(int index) const
int intAttribute(const std::string &name) const
std::string name() const
int childCount() const
static const std::string OSKEY_COMPONENT_ID_POSITION
ObjectState attribute key for component ID position.
Definition SlotField.hh:91
static const std::string OSNAME_SOCKET_ENCODING
ObjectState name for socket encoding.

References ObjectState::child(), ObjectState::childCount(), clearNoOperationEncoding(), clearSocketEncodings(), componentIDPos_, Exception::errorMessage(), ObjectState::intAttribute(), InstructionField::loadState(), ObjectState::name(), OSKEY_COMPONENT_ID_POSITION, NOPEncoding::OSNAME_NOP_ENCODING, and SocketEncoding::OSNAME_SOCKET_ENCODING.

Referenced by SourceField::loadState(), and SlotField().

Here is the call graph for this function:

◆ noOperationEncoding()

NOPEncoding & SlotField::noOperationEncoding ( ) const

Returns the NOP encoding.

Returns NullNOPEncoding instance if the slot field does not have a NOP encoding.

Returns
The NOP encoding.

Definition at line 281 of file SlotField.cc.

281 {
283 return *nopEncoding_;
284 } else {
286 }
287}
static NullNOPEncoding & instance()

References hasNoOperationEncoding(), NullNOPEncoding::instance(), and nopEncoding_.

Referenced by BEMTester::canAddComponentEncoding(), CodeCompressorPlugin::encodeNOP(), printSlotFieldEncodings(), saveState(), unsetNoOperationEncoding(), and width().

Here is the call graph for this function:

◆ parent()

MoveSlot * SlotField::parent ( ) const

Returns the parent move slot.

Definition at line 98 of file SlotField.cc.

98 {
100 if (parent == NULL) {
101 return NULL;
102 } else {
103 MoveSlot* slot = dynamic_cast<MoveSlot*>(parent);
104 assert(slot != NULL);
105 return slot;
106 }
107}
InstructionField * parent() const

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

Referenced by CodeCompressorPlugin::addBitsForDestinationField(), CodeCompressorPlugin::addBitsForSourceField(), BEMGenerator::addEncodings(), BEMGenerator::addEncodings(), BEMValidator::checkSocketCodeTable(), DestinationField::DestinationField(), DestinationField::DestinationField(), CodeCompressorPlugin::encodeFUTerminal(), CodeCompressorPlugin::encodeImmediateTerminal(), CodeCompressorPlugin::encodeIUTerminal(), CodeCompressorPlugin::encodeRFTerminal(), parent(), DefaultDecoderGenerator::portCodeCondition(), DefaultDecoderGenerator::rfOpcodeFromSrcOrDstField(), MoveSlot::setDestinationField(), SourceField::setImmediateEncoding(), MoveSlot::setSourceField(), SocketEncoding::SocketEncoding(), DefaultDecoderGenerator::socketEncodingCondition(), SourceField::SourceField(), SourceField::SourceField(), SourceField::unsetImmediateEncoding(), unsetNoOperationEncoding(), DefaultDecoderGenerator::writeControlRulesOfFUInputPort(), DestinationField::~DestinationField(), and SourceField::~SourceField().

Here is the call graph for this function:

◆ removeSocketEncoding()

void SlotField::removeSocketEncoding ( SocketEncoding encoding)

Removes the given socket encoding.

This method is to be called from SocketEncoding destructor.

Parameters
encodingThe socket encoding to be removed.

Definition at line 143 of file SlotField.cc.

143 {
144 // verify that this is called from SocketEncoding destructor
145 assert(encoding.parent() == NULL);
147}
static bool removeValueIfExists(ContainerType &aContainer, const ElementType &aKey)

References assert, encodings_, SocketEncoding::parent(), and ContainerTools::removeValueIfExists().

Referenced by SocketEncoding::detachFromParent().

Here is the call graph for this function:

◆ saveState()

ObjectState * SlotField::saveState ( ) const
virtual

Saves the state of the object to an ObjectState tree.

Returns
The newly created ObjectState tree.

Reimplemented from InstructionField.

Reimplemented in DestinationField, and SourceField.

Definition at line 388 of file SlotField.cc.

388 {
389
393
394 // add socket encodings
395 for (int i = 0; i < socketEncodingCount(); i++) {
397 state->addChild(enc.saveState());
398 }
399
400 // add NOP encoding
403 }
404
405 return state;
406}
virtual ObjectState * saveState() const
void setName(const std::string &name)
void setAttribute(const std::string &name, const std::string &value)
void addChild(ObjectState *child)
static const std::string OSNAME_SLOT_FIELD
ObjectState name for slot field.
Definition SlotField.hh:89
SocketEncoding & socketEncoding(int index) const
Definition SlotField.cc:170
virtual ObjectState * saveState() const
Definition SlotField.cc:388
NOPEncoding & noOperationEncoding() const
Definition SlotField.cc:281
BinaryEncoding::Position componentIDPosition() const
Definition SlotField.cc:296
int socketEncodingCount() const
Definition SlotField.cc:156
virtual ObjectState * saveState() const

References ObjectState::addChild(), componentIDPosition(), hasNoOperationEncoding(), noOperationEncoding(), OSKEY_COMPONENT_ID_POSITION, OSNAME_SLOT_FIELD, InstructionField::saveState(), saveState(), SocketEncoding::saveState(), ObjectState::setAttribute(), ObjectState::setName(), socketEncoding(), and socketEncodingCount().

Referenced by DestinationField::saveState(), saveState(), and SourceField::saveState().

Here is the call graph for this function:

◆ setNoOperationEncoding()

void SlotField::setNoOperationEncoding ( NOPEncoding encoding)

Sets the given encoding for no operation.

This method is to be called from the constructor of NOPEncoding.

Parameters
encodingThe encoding to be set.
Exceptions
ObjectAlreadyExistsIf the slot field has a NOP encoding already or if the given encoding is ambiguous with some other encoding.

Definition at line 234 of file SlotField.cc.

234 {
235 assert(encoding.parent() == NULL);
236
239 *this, encoding.encoding(), encoding.extraBits())) {
240 const string procName = "SlotField::setNoOperationEncoding";
241 throw ObjectAlreadyExists(__FILE__, __LINE__, procName);
242 }
243
244 nopEncoding_ = &encoding;
245}
SlotField * parent() const

References assert, BEMTester::canAddComponentEncoding(), Encoding::encoding(), Encoding::extraBits(), hasNoOperationEncoding(), nopEncoding_, and NOPEncoding::parent().

Referenced by NOPEncoding::NOPEncoding(), and NOPEncoding::NOPEncoding().

Here is the call graph for this function:

◆ socketEncoding() [1/2]

SocketEncoding & SlotField::socketEncoding ( const std::string &  socket) const

Returns the socket encoding of the socket with the given name.

Returns a NullSocketEncoding instance if this field does not encode the socket.

Parameters
socketName of the socket.
Returns
The socket encoding of the given socket.

Definition at line 210 of file SlotField.cc.

210 {
211 for (SocketEncodingTable::const_iterator iter = encodings_.begin();
212 iter != encodings_.end(); iter++) {
213 SocketEncoding* encoding = *iter;
214 if (encoding->socketName() == socket) {
215 return **iter;
216 }
217 }
218
220}
static NullSocketEncoding & instance()

References encodings_, NullSocketEncoding::instance(), and SocketEncoding::socketName().

Here is the call graph for this function:

◆ socketEncoding() [2/2]

SocketEncoding & SlotField::socketEncoding ( int  index) const

Returns the socket encoding stored at the given position.

Parameters
indexThe position.
Returns
The socket encoding.
Exceptions
OutOfRangeIf the given index is negative or not smaller than the number of sockets encoded in the field.

Definition at line 170 of file SlotField.cc.

170 {
171 if (index < 0 || index >= socketEncodingCount()) {
172 const string procName = "SlotField::socketEncoding";
173 throw OutOfRange(__FILE__, __LINE__, procName);
174 }
175
176 return *encodings_[index];
177}

References encodings_, and socketEncodingCount().

Referenced by BEMTester::canAddComponentEncoding(), BEMValidator::checkDestinationField(), BEMValidator::checkSourceField(), BEMTester::conflictsWithDestinationEncodings(), BEMTester::conflictsWithSourceEncodings(), CodeCompressorPlugin::encodeFUTerminal(), CodeCompressorPlugin::encodeIUTerminal(), CodeCompressorPlugin::encodeRFTerminal(), printSlotFieldEncodings(), SocketCodeTable::removeReferences(), saveState(), DefaultDecoderGenerator::socketEncodingCondition(), width(), DefaultDecoderGenerator::writeControlRulesOfFUInputPort(), DefaultDecoderGenerator::writeControlRulesOfFUOutputPort(), DefaultDecoderGenerator::writeControlRulesOfRFReadPort(), and DefaultDecoderGenerator::writeControlRulesOfRFWritePort().

Here is the call graph for this function:

◆ socketEncodingCount()

int SlotField::socketEncodingCount ( ) const

Returns the number of sockets that are encoded in this field.

Returns
The number of sockets.

Definition at line 156 of file SlotField.cc.

156 {
157 return encodings_.size();
158}

References encodings_.

Referenced by BEMTester::canAddComponentEncoding(), BEMTester::conflictsWithDestinationEncodings(), BEMTester::conflictsWithSourceEncodings(), printSlotFieldEncodings(), SocketCodeTable::removeReferences(), saveState(), socketEncoding(), and width().

◆ unsetNoOperationEncoding()

void SlotField::unsetNoOperationEncoding ( )

Unsets the NOP encoding.

This method is to be called from the destructor of NOPEncoding.

Definition at line 253 of file SlotField.cc.

253 {
255 assert(noOperationEncoding().parent() == NULL);
256 nopEncoding_ = NULL;
257}

References assert, hasNoOperationEncoding(), noOperationEncoding(), nopEncoding_, and parent().

Referenced by NOPEncoding::~NOPEncoding().

Here is the call graph for this function:

◆ width()

int SlotField::width ( ) const
virtual

Returns the bit width required by the socket encodings.

Returns
The bit width.

Implements InstructionField.

Reimplemented in SourceField.

Definition at line 307 of file SlotField.cc.

307 {
308
309 int width(0);
310 int encodings = socketEncodingCount();
311 for (int i = 0; i < encodings; i++) {
312 SocketEncoding& encoding = socketEncoding(i);
313 int encodingWidth = encoding.width();
314 if (encodingWidth > width) {
315 width = encodingWidth;
316 }
317 }
318
321 }
322
323 return width + extraBits();
324}
virtual int width() const
Definition Encoding.cc:130
virtual int width() const
Definition SlotField.cc:307
virtual int width() const

References InstructionField::extraBits(), hasNoOperationEncoding(), noOperationEncoding(), socketEncoding(), socketEncodingCount(), Encoding::width(), width(), and SocketEncoding::width().

Referenced by NOPEncoding::bitPosition(), BEMTester::canAddComponentPriorityEncoding(), CodeCompressorPlugin::encodeMove(), CodeCompressorPlugin::encodeNOP(), CodeCompressorPlugin::encodeSlotField(), ProGe::RV32MicroCodeGenerator::findBusWidths(), printMoveSlotLayout(), printSlotFieldEncodings(), DefaultDecoderGenerator::rfOpcodeFromSrcOrDstField(), SocketEncoding::socketCodePosition(), SocketEncoding::socketIDPosition(), MoveSlot::width(), width(), SourceField::width(), DefaultDecoderGenerator::writeInstructionDismembering(), and DefaultDecoderGenerator::writeMoveFieldSignals().

Here is the call graph for this function:

Member Data Documentation

◆ componentIDPos_

BinaryEncoding::Position SlotField::componentIDPos_
private

Position of the socket and bridge IDs within the field.

Definition at line 109 of file SlotField.hh.

Referenced by componentIDPosition(), and loadState().

◆ encodings_

SocketEncodingTable SlotField::encodings_
private

◆ nopEncoding_

NOPEncoding* SlotField::nopEncoding_
private

◆ OSKEY_COMPONENT_ID_POSITION

const std::string SlotField::OSKEY_COMPONENT_ID_POSITION = "comp_id_pos"
static

ObjectState attribute key for component ID position.

Definition at line 91 of file SlotField.hh.

Referenced by loadState(), saveState(), BEMSerializer::slotFieldToFile(), and BEMSerializer::slotFieldToOM().

◆ OSNAME_SLOT_FIELD

const std::string SlotField::OSNAME_SLOT_FIELD = "slot_field"
static

ObjectState name for slot field.

Definition at line 89 of file SlotField.hh.

Referenced by saveState(), and BEMSerializer::slotFieldToOM().


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