OpenASIP  2.0
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. More...
 
static const std::string OSKEY_COMPONENT_ID_POSITION = "comp_id_pos"
 ObjectState attribute key for component ID position. 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...
 

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. More...
 

Private Member Functions

void clearSocketEncodings ()
 
void clearNoOperationEncoding ()
 

Private Attributes

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

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 }

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 }

◆ 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 }

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 }

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

Referenced by SocketEncoding::setEncoding(), 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  {
423  if (hasNoOperationEncoding()) {
424  delete nopEncoding_;
425  }
426 }

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 }

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 }

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  {
282  if (hasNoOperationEncoding()) {
283  return *nopEncoding_;
284  } else {
285  return NullNOPEncoding::instance();
286  }
287 }

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

◆ 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 }

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 SourceField, and DestinationField.

Definition at line 388 of file SlotField.cc.

388  {
389 
391  state->setName(OSNAME_SLOT_FIELD);
393 
394  // add socket encodings
395  for (int i = 0; i < socketEncodingCount(); i++) {
396  SocketEncoding& enc = socketEncoding(i);
397  state->addChild(enc.saveState());
398  }
399 
400  // add NOP encoding
401  if (hasNoOperationEncoding()) {
403  }
404 
405  return state;
406 }

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

Referenced by DestinationField::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 
237  if (hasNoOperationEncoding() ||
239  *this, encoding.encoding(), encoding.extraBits())) {
240  const string procName = "SlotField::setNoOperationEncoding";
241  throw ObjectAlreadyExists(__FILE__, __LINE__, procName);
242  }
243 
244  nopEncoding_ = &encoding;
245 }

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

Referenced by 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 }

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

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

The container for socket encodings.

Definition at line 107 of file SlotField.hh.

Referenced by addSocketEncoding(), clearSocketEncodings(), hasSocketEncoding(), removeSocketEncoding(), socketEncoding(), and socketEncodingCount().

◆ 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:
SlotField::noOperationEncoding
NOPEncoding & noOperationEncoding() const
Definition: SlotField.cc:281
MoveSlot
Definition: MoveSlot.hh:60
SlotField::componentIDPos_
BinaryEncoding::Position componentIDPos_
Position of the socket and bridge IDs within the field.
Definition: SlotField.hh:109
ObjectStateLoadingException
Definition: Exception.hh:551
SocketEncoding::saveState
virtual ObjectState * saveState() const
Definition: SocketEncoding.cc:302
SlotField::hasSocketEncoding
bool hasSocketEncoding(const std::string &socket) const
Definition: SlotField.cc:188
OutOfRange
Definition: Exception.hh:320
SlotField::saveState
virtual ObjectState * saveState() const
Definition: SlotField.cc:388
ObjectState
Definition: ObjectState.hh:59
SlotField::hasNoOperationEncoding
bool hasNoOperationEncoding() const
Definition: SlotField.cc:267
SocketEncoding::width
virtual int width() const
Definition: SocketEncoding.cc:276
ObjectState::setName
void setName(const std::string &name)
NullNOPEncoding::instance
static NullNOPEncoding & instance()
Definition: NullNOPEncoding.cc:65
SlotField::socketEncoding
SocketEncoding & socketEncoding(int index) const
Definition: SlotField.cc:170
InstructionField
Definition: InstructionField.hh:43
InstructionField::saveState
virtual ObjectState * saveState() const
Definition: InstructionField.cc:268
assert
#define assert(condition)
Definition: Application.hh:86
NOPEncoding::parent
SlotField * parent() const
Definition: NOPEncoding.cc:105
Encoding::width
virtual int width() const
Definition: Encoding.cc:130
SlotField::clearNoOperationEncoding
void clearNoOperationEncoding()
Definition: SlotField.cc:422
SequenceTools::deleteAllItems
static void deleteAllItems(SequenceType &aSequence)
SocketEncoding::OSNAME_SOCKET_ENCODING
static const std::string OSNAME_SOCKET_ENCODING
ObjectState name for socket encoding.
Definition: SocketEncoding.hh:79
BinaryEncoding::Position
Position
Definition: BinaryEncoding.hh:63
SlotField::encodings_
SocketEncodingTable encodings_
The container for socket encodings.
Definition: SlotField.hh:107
ContainerTools::removeValueIfExists
static bool removeValueIfExists(ContainerType &aContainer, const ElementType &aKey)
SocketEncoding::socketName
std::string socketName() const
Definition: SocketEncoding.cc:145
SlotField::clearSocketEncodings
void clearSocketEncodings()
Definition: SlotField.cc:413
BinaryEncoding::LEFT
@ LEFT
Definition: BinaryEncoding.hh:64
InstructionField::parent
InstructionField * parent() const
Definition: InstructionField.cc:100
SlotField::width
virtual int width() const
Definition: SlotField.cc:307
SlotField::nopEncoding_
NOPEncoding * nopEncoding_
The NOP encoding.
Definition: SlotField.hh:105
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
Encoding::encoding
unsigned int encoding() const
Definition: Encoding.cc:108
SlotField::componentIDPosition
BinaryEncoding::Position componentIDPosition() const
Definition: SlotField.cc:296
Exception
Definition: Exception.hh:54
NOPEncoding
Definition: NOPEncoding.hh:44
ObjectState::name
std::string name() const
NullSocketEncoding::instance
static NullSocketEncoding & instance()
Definition: NullSocketEncoding.cc:65
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
InstructionField::extraBits
int extraBits() const
Definition: InstructionField.cc:229
SlotField::OSNAME_SLOT_FIELD
static const std::string OSNAME_SLOT_FIELD
ObjectState name for slot field.
Definition: SlotField.hh:89
ObjectAlreadyExists
Definition: Exception.hh:1002
SocketEncoding::parent
SlotField * parent() const
Definition: SocketEncoding.cc:127
InstructionField::loadState
virtual void loadState(const ObjectState *state)
Definition: InstructionField.cc:242
BEMTester::canAddComponentEncoding
static bool canAddComponentEncoding(SlotField &field, unsigned int encoding, unsigned int extraBits)
Definition: BEMTester.cc:73
SlotField::socketEncodingCount
int socketEncodingCount() const
Definition: SlotField.cc:156
ObjectState::intAttribute
int intAttribute(const std::string &name) const
Definition: ObjectState.cc:276
NOPEncoding::OSNAME_NOP_ENCODING
static const std::string OSNAME_NOP_ENCODING
ObjectState name for NOP encoding.
Definition: NOPEncoding.hh:57
SlotField::OSKEY_COMPONENT_ID_POSITION
static const std::string OSKEY_COMPONENT_ID_POSITION
ObjectState attribute key for component ID position.
Definition: SlotField.hh:91
SocketEncoding
Definition: SocketEncoding.hh:51
SlotField::parent
MoveSlot * parent() const
Definition: SlotField.cc:98
Encoding::extraBits
unsigned int extraBits() const
Definition: Encoding.cc:119
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
SlotField::loadState
virtual void loadState(const ObjectState *state)
Definition: SlotField.cc:358