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

#include <SocketEncoding.hh>

Inheritance diagram for SocketEncoding:
Inheritance graph
Collaboration diagram for SocketEncoding:
Collaboration graph

Public Member Functions

 SocketEncoding (const std::string &name, unsigned int encoding, unsigned int extraBits, SlotField &parent)
 
 SocketEncoding (const ObjectState *state, SlotField &parent)
 
virtual ~SocketEncoding ()
 
SlotFieldparent () const
 
std::string socketName () const
 
void setSocketCodes (SocketCodeTable &codeTable)
 
void unsetSocketCodes ()
 
bool hasSocketCodes () const
 
SocketCodeTablesocketCodes () const
 
int socketCodePosition () const
 
void setEncoding (unsigned int encoding, unsigned int extraBits)
 
int socketIDPosition () const
 
int socketIDWidth () const
 
virtual int width () const
 
virtual int bitPosition () const
 
virtual ObjectStatesaveState () const
 
- Public Member Functions inherited from Encoding
virtual ~Encoding ()
 
InstructionFieldparent () const
 
unsigned int encoding () const
 
unsigned int extraBits () const
 

Static Public Attributes

static const std::string OSNAME_SOCKET_ENCODING = "socket_encoding"
 ObjectState name for socket encoding. More...
 
static const std::string OSKEY_SOCKET_NAME = "socket_name"
 ObjectState attribute key for the name of the socket. More...
 
static const std::string OSKEY_SC_TABLE = "sc_table"
 ObjectState attribute key for the name of the socket code table. More...
 
- Static Public Attributes inherited from Encoding
static const std::string OSNAME_ENCODING = "encoding"
 ObjectState name for Encoding class. More...
 
static const std::string OSKEY_ENCODING = "encoding"
 ObjectState attribute key for the encoding. More...
 
static const std::string OSKEY_EXTRA_BITS = "extra_bits"
 ObjectState attribute key for the number of extra bits. More...
 

Private Member Functions

void detachFromParent ()
 

Private Attributes

std::string name_
 Name of the socket. More...
 
SocketCodeTablesocketCodes_
 Socket code table. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Encoding
 Encoding (unsigned int encoding, unsigned int extraBits, InstructionField *parent)
 
 Encoding (const ObjectState *state, InstructionField *parent)
 
void setParent (InstructionField *parent)
 
void setEncoding (unsigned int encoding, unsigned int extraBits)
 

Detailed Description

The SocketEncoding class models how socket sources or destinations are mapped to control codes.

Sockets have an independent encoding in each source or destination field they appear in. A socket encoding can be more complex than a fixed control code and encode many destinations or sources all reached from the same socket. In this case, the socket encoding contains SocketCodeTable instance.

Definition at line 51 of file SocketEncoding.hh.

Constructor & Destructor Documentation

◆ SocketEncoding() [1/2]

SocketEncoding::SocketEncoding ( const std::string &  name,
unsigned int  encoding,
unsigned int  extraBits,
SlotField parent 
)

The constructor.

Creates a socket encoding and registers it into the given slot field. The socket is identified by name. The (fixed) part of the socket encoding and the parent slot field are given as parameters.

Parameters
nameName of the socket.
encodingFixed part of the encoding.
extraBitsThe number of extra (zero) bits in the encoding.
parentThe parent slot field.
Exceptions
ObjectAlreadyExistsIf the parent slot field already has an encoding for the same socket, or if the given encoding is ambiguous with another encoding in the parent slot field.

Definition at line 66 of file SocketEncoding.cc.

69  : Encoding(encoding, extraBits, NULL), name_(name), socketCodes_(NULL) {
71  setParent(&parent);
72 }

References SlotField::addSocketEncoding(), parent(), and Encoding::setParent().

Here is the call graph for this function:

◆ SocketEncoding() [2/2]

SocketEncoding::SocketEncoding ( const ObjectState state,
SlotField parent 
)

The constructor.

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

Parameters
stateThe ObjectState instance.
parentThe parent slot field.
Exceptions
ObjectStateLoadingExceptionIf an error occurs while loading the state.
ObjectAlreadyExistsIf the parent slot field already has an encoding for the same socket, or if the given encoding is ambiguous with another encoding in the parent slot field.

Definition at line 88 of file SocketEncoding.cc.

89  : Encoding(state, &parent), name_(""), socketCodes_(NULL) {
90  const string procName = "SocketEncoding::SocketEncoding";
91 
92  try {
94  if (state->hasAttribute(OSKEY_SC_TABLE)) {
95  string tableName = state->stringAttribute(OSKEY_SC_TABLE);
96  BinaryEncoding* bem = parent.parent()->parent();
97  if (&bem->socketCodeTable(tableName) ==
100  __FILE__, __LINE__, procName);
101  } else {
102  setSocketCodes(bem->socketCodeTable(tableName));
103  }
104  }
105 
106  } catch (const Exception& exception) {
108  __FILE__, __LINE__, procName, exception.errorMessage());
109  }
110 
111  setParent(NULL);
112  parent.addSocketEncoding(*this);
113  setParent(&parent);
114 }

References SlotField::addSocketEncoding(), Exception::errorMessage(), ObjectState::hasAttribute(), NullSocketCodeTable::instance(), name_, OSKEY_SC_TABLE, OSKEY_SOCKET_NAME, parent(), SlotField::parent(), MoveSlot::parent(), Encoding::setParent(), setSocketCodes(), BinaryEncoding::socketCodeTable(), and ObjectState::stringAttribute().

Here is the call graph for this function:

◆ ~SocketEncoding()

SocketEncoding::~SocketEncoding ( )
virtual

The destructor.

Definition at line 119 of file SocketEncoding.cc.

119 { detachFromParent(); }

References detachFromParent().

Here is the call graph for this function:

Member Function Documentation

◆ bitPosition()

int SocketEncoding::bitPosition ( ) const
virtual

Returns always 0.

Returns
The position.

Implements Encoding.

Definition at line 291 of file SocketEncoding.cc.

291  {
292  return 0;
293 }

◆ detachFromParent()

void SocketEncoding::detachFromParent ( )
private

Removes itself from the parent slot field.

Definition at line 316 of file SocketEncoding.cc.

316  {
317  if (this->parent() == nullptr) {
318  return;
319  }
320  SlotField* parent = this->parent();
321  setParent(nullptr);
322  parent->removeSocketEncoding(*this);
323 }

References parent(), SlotField::removeSocketEncoding(), and Encoding::setParent().

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

Here is the call graph for this function:

◆ hasSocketCodes()

bool SocketEncoding::hasSocketCodes ( ) const

◆ parent()

SlotField * SocketEncoding::parent ( ) const

Returns the parent slot field.

Returns
The parent slot field.

Definition at line 127 of file SocketEncoding.cc.

127  {
129  if (parent != NULL) {
130  SlotField* sField = dynamic_cast<SlotField*>(parent);
131  assert(sField != NULL);
132  return sField;
133  } else {
134  return NULL;
135  }
136 }

References assert, and Encoding::parent().

Referenced by SlotField::addSocketEncoding(), BEMValidator::checkSocketCodeTable(), detachFromParent(), DefaultDecoderGenerator::portCodeCondition(), SlotField::removeSocketEncoding(), DefaultDecoderGenerator::rfOpcodeFromSrcOrDstField(), setEncoding(), socketCodePosition(), SocketEncoding(), socketIDPosition(), and DefaultDecoderGenerator::writeControlRulesOfFUInputPort().

Here is the call graph for this function:

◆ saveState()

ObjectState * SocketEncoding::saveState ( ) const
virtual

Saves the state of the socket encoding to an ObjectState instance.

Returns
The newly created ObjectState instance.

Reimplemented from Encoding.

Definition at line 302 of file SocketEncoding.cc.

302  {
303  ObjectState* state = Encoding::saveState();
306  if (hasSocketCodes()) {
307  state->setAttribute(OSKEY_SC_TABLE, socketCodes().name());
308  }
309  return state;
310 }

References hasSocketCodes(), OSKEY_SC_TABLE, OSKEY_SOCKET_NAME, OSNAME_SOCKET_ENCODING, Encoding::saveState(), ObjectState::setAttribute(), ObjectState::setName(), socketCodes(), and socketName().

Referenced by SlotField::saveState().

Here is the call graph for this function:

◆ setEncoding()

void SocketEncoding::setEncoding ( unsigned int  encoding,
unsigned int  extraBits 
)

Sets new encoding.

Parameters
encodingThe encoding.
extraBitsThe extrabits of the encoding.
Exceptions
ObjectAlreadyExistsIf the parent slot field already has an encoding for the same socket, or if the given encoding is ambiguous with another encoding in the parent slot field.

Definition at line 223 of file SocketEncoding.cc.

223  {
224  SlotField* parent = this->parent();
225  unsigned int oldEncoding = this->encoding();
226  unsigned int oldExtrabits = this->extraBits();
229  try {
230  parent->addSocketEncoding(*this);
231  } catch (ObjectAlreadyExists& e) {
232  Encoding::setEncoding(oldEncoding, oldExtrabits);
233  parent->addSocketEncoding(*this);
234  }
235  setParent(parent);
236 }

References SlotField::addSocketEncoding(), detachFromParent(), Encoding::encoding(), Encoding::extraBits(), parent(), Encoding::setEncoding(), and Encoding::setParent().

Here is the call graph for this function:

◆ setSocketCodes()

void SocketEncoding::setSocketCodes ( SocketCodeTable codeTable)

Attaches a set of socket codes to the socket encoding.

Parameters
codeTableThe socket code table to be attached.

Definition at line 156 of file SocketEncoding.cc.

156  {
157  socketCodes_ = &codeTable;
158 }

References socketCodes_.

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

◆ socketCodePosition()

int SocketEncoding::socketCodePosition ( ) const

Returns the position of the socket code within the slot field.

Definition at line 203 of file SocketEncoding.cc.

203  {
204  if (parent()->componentIDPosition() == BinaryEncoding::RIGHT) {
205  return parent()->width() - parent()->extraBits() -
206  socketCodes().width();
207  } else {
208  return 0;
209  }
210 }

References InstructionField::extraBits(), parent(), BinaryEncoding::RIGHT, socketCodes(), SlotField::width(), and SocketCodeTable::width().

Referenced by BEMTester::conflictsWithDestinationEncodings(), and BEMTester::conflictsWithSourceEncodings().

Here is the call graph for this function:

◆ socketCodes()

SocketCodeTable & SocketEncoding::socketCodes ( ) const

◆ socketIDPosition()

int SocketEncoding::socketIDPosition ( ) const

Returns the position of the socket ID within the slot field.

The position is always 0 if socket ID is in the right end of the field. However, if socket code is in the right end of the field, the position of the socket ID depends on the bit width of the socket code.

Returns
The position of the socket ID.

Definition at line 249 of file SocketEncoding.cc.

249  {
250  if (parent()->componentIDPosition() == BinaryEncoding::RIGHT) {
251  return 0;
252  } else {
253  return parent()->width() - parent()->extraBits() - socketIDWidth();
254  }
255 }

References InstructionField::extraBits(), parent(), BinaryEncoding::RIGHT, socketIDWidth(), and SlotField::width().

Referenced by BEMTester::conflictsWithDestinationEncodings(), BEMTester::conflictsWithSourceEncodings(), DefaultDecoderGenerator::socketEncodingCondition(), and BEMTester::splitEncodingTo().

Here is the call graph for this function:

◆ socketIDWidth()

int SocketEncoding::socketIDWidth ( ) const

◆ socketName()

std::string SocketEncoding::socketName ( ) const

Returns the name of the socket.

Returns
The name of the socket.

Definition at line 145 of file SocketEncoding.cc.

145  {
146  return name_;
147 }

References name_.

Referenced by SlotField::addSocketEncoding(), BEMValidator::checkSocketCodeTable(), SlotField::hasSocketEncoding(), BEMValidator::needsSocketCodeTable(), printSlotFieldEncodings(), saveState(), and SlotField::socketEncoding().

◆ unsetSocketCodes()

void SocketEncoding::unsetSocketCodes ( )

Removes the socket codes from the socket encoding.

Definition at line 165 of file SocketEncoding.cc.

165  {
166  socketCodes_ = NULL;
167 }

References socketCodes_.

Referenced by SocketCodeTable::removeReferences().

◆ width()

int SocketEncoding::width ( ) const
virtual

Returns the number of bits required to encode all the destinations of this socket.

Returns
The number of bits.

Reimplemented from Encoding.

Definition at line 276 of file SocketEncoding.cc.

276  {
277  int width = socketIDWidth();
278  if (hasSocketCodes()) {
279  width += socketCodes().width();
280  }
281  return width;
282 }

References hasSocketCodes(), socketCodes(), socketIDWidth(), and SocketCodeTable::width().

Referenced by printSlotFieldEncodings(), and SlotField::width().

Here is the call graph for this function:

Member Data Documentation

◆ name_

std::string SocketEncoding::name_
private

Name of the socket.

Definition at line 90 of file SocketEncoding.hh.

Referenced by SocketEncoding(), and socketName().

◆ OSKEY_SC_TABLE

const std::string SocketEncoding::OSKEY_SC_TABLE = "sc_table"
static

ObjectState attribute key for the name of the socket code table.

Definition at line 83 of file SocketEncoding.hh.

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

◆ OSKEY_SOCKET_NAME

const std::string SocketEncoding::OSKEY_SOCKET_NAME = "socket_name"
static

ObjectState attribute key for the name of the socket.

Definition at line 81 of file SocketEncoding.hh.

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

◆ OSNAME_SOCKET_ENCODING

const std::string SocketEncoding::OSNAME_SOCKET_ENCODING = "socket_encoding"
static

ObjectState name for socket encoding.

Definition at line 79 of file SocketEncoding.hh.

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

◆ socketCodes_

SocketCodeTable* SocketEncoding::socketCodes_
private

Socket code table.

Definition at line 92 of file SocketEncoding.hh.

Referenced by hasSocketCodes(), setSocketCodes(), socketCodes(), and unsetSocketCodes().


The documentation for this class was generated from the following files:
SocketEncoding::detachFromParent
void detachFromParent()
Definition: SocketEncoding.cc:316
ObjectState::hasAttribute
bool hasAttribute(const std::string &name) const
Definition: ObjectState.cc:205
BinaryEncoding
Definition: BinaryEncoding.hh:61
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
SocketEncoding::setSocketCodes
void setSocketCodes(SocketCodeTable &codeTable)
Definition: SocketEncoding.cc:156
ObjectStateLoadingException
Definition: Exception.hh:551
Encoding::setEncoding
void setEncoding(unsigned int encoding, unsigned int extraBits)
Definition: Encoding.cc:163
Encoding::setParent
void setParent(InstructionField *parent)
Definition: Encoding.cc:155
Encoding::parent
InstructionField * parent() const
Definition: Encoding.cc:97
ObjectState
Definition: ObjectState.hh:59
SocketEncoding::width
virtual int width() const
Definition: SocketEncoding.cc:276
ObjectState::setName
void setName(const std::string &name)
BinaryEncoding::socketCodeTable
SocketCodeTable & socketCodeTable(int index) const
Definition: BinaryEncoding.cc:583
SlotField::removeSocketEncoding
void removeSocketEncoding(SocketEncoding &encoding)
Definition: SlotField.cc:143
InstructionField
Definition: InstructionField.hh:43
assert
#define assert(condition)
Definition: Application.hh:86
SocketEncoding::OSKEY_SC_TABLE
static const std::string OSKEY_SC_TABLE
ObjectState attribute key for the name of the socket code table.
Definition: SocketEncoding.hh:83
SocketEncoding::OSNAME_SOCKET_ENCODING
static const std::string OSNAME_SOCKET_ENCODING
ObjectState name for socket encoding.
Definition: SocketEncoding.hh:79
SocketEncoding::socketName
std::string socketName() const
Definition: SocketEncoding.cc:145
SlotField::width
virtual int width() const
Definition: SlotField.cc:307
SocketEncoding::hasSocketCodes
bool hasSocketCodes() const
Definition: SocketEncoding.cc:177
NullSocketCodeTable::instance
static NullSocketCodeTable & instance()
Definition: NullSocketCodeTable.cc:59
Encoding::encoding
unsigned int encoding() const
Definition: Encoding.cc:108
Exception
Definition: Exception.hh:54
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
SlotField::addSocketEncoding
void addSocketEncoding(SocketEncoding &encoding)
Definition: SlotField.cc:121
Encoding::saveState
virtual ObjectState * saveState() const
Definition: Encoding.cc:141
InstructionField::extraBits
int extraBits() const
Definition: InstructionField.cc:229
SocketEncoding::socketIDWidth
int socketIDWidth() const
Definition: SocketEncoding.cc:264
Encoding::Encoding
Encoding(unsigned int encoding, unsigned int extraBits, InstructionField *parent)
Definition: Encoding.cc:53
MoveSlot::parent
BinaryEncoding * parent() const
Definition: MoveSlot.cc:118
BinaryEncoding::RIGHT
@ RIGHT
Definition: BinaryEncoding.hh:65
ObjectAlreadyExists
Definition: Exception.hh:1002
SlotField
Definition: SlotField.hh:58
SocketEncoding::parent
SlotField * parent() const
Definition: SocketEncoding.cc:127
MathTools::bitLength
static unsigned int bitLength(long unsigned int number)
SocketEncoding::socketCodes_
SocketCodeTable * socketCodes_
Socket code table.
Definition: SocketEncoding.hh:92
SocketEncoding::name_
std::string name_
Name of the socket.
Definition: SocketEncoding.hh:90
SocketEncoding::socketCodes
SocketCodeTable & socketCodes() const
Definition: SocketEncoding.cc:191
SlotField::parent
MoveSlot * parent() const
Definition: SlotField.cc:98
SocketCodeTable::width
int width() const
Definition: SocketCodeTable.cc:200
Encoding::extraBits
unsigned int extraBits() const
Definition: Encoding.cc:119
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100
SocketEncoding::OSKEY_SOCKET_NAME
static const std::string OSKEY_SOCKET_NAME
ObjectState attribute key for the name of the socket.
Definition: SocketEncoding.hh:81