OpenASIP 2.2
Loading...
Searching...
No Matches
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.
 
static const std::string OSKEY_SOCKET_NAME = "socket_name"
 ObjectState attribute key for the name of the socket.
 
static const std::string OSKEY_SC_TABLE = "sc_table"
 ObjectState attribute key for the name of the socket code table.
 
- Static Public Attributes inherited from Encoding
static const std::string OSNAME_ENCODING = "encoding"
 ObjectState name for Encoding class.
 
static const std::string OSKEY_ENCODING = "encoding"
 ObjectState attribute key for the encoding.
 
static const std::string OSKEY_EXTRA_BITS = "extra_bits"
 ObjectState attribute key for the number of extra bits.
 

Private Member Functions

void detachFromParent ()
 

Private Attributes

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

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) {
72}
unsigned int extraBits() const
Definition Encoding.cc:119
void setParent(InstructionField *parent)
Definition Encoding.cc:155
unsigned int encoding() const
Definition Encoding.cc:108
void addSocketEncoding(SocketEncoding &encoding)
Definition SlotField.cc:121
SlotField * parent() const
SocketCodeTable * socketCodes_
Socket code table.
std::string name_
Name of the socket.

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);
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);
114}
SocketCodeTable & socketCodeTable(int index) const
std::string errorMessage() const
Definition Exception.cc:123
BinaryEncoding * parent() const
Definition MoveSlot.cc:118
static NullSocketCodeTable & instance()
bool hasAttribute(const std::string &name) const
std::string stringAttribute(const std::string &name) const
MoveSlot * parent() const
Definition SlotField.cc:98
void setSocketCodes(SocketCodeTable &codeTable)
static const std::string OSKEY_SOCKET_NAME
ObjectState attribute key for the name of the socket.
static const std::string OSKEY_SC_TABLE
ObjectState attribute key for the name of the socket code table.

References SlotField::addSocketEncoding(), Exception::errorMessage(), ObjectState::hasAttribute(), NullSocketCodeTable::instance(), name_, OSKEY_SC_TABLE, OSKEY_SOCKET_NAME, MoveSlot::parent(), SlotField::parent(), 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}
void removeSocketEncoding(SocketEncoding &encoding)
Definition SlotField.cc:143

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}
#define assert(condition)
InstructionField * parent() const
Definition Encoding.cc:97

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

Referenced by SlotField::addSocketEncoding(), BEMValidator::checkSocketCodeTable(), detachFromParent(), parent(), DefaultDecoderGenerator::portCodeCondition(), SlotField::removeSocketEncoding(), DefaultDecoderGenerator::rfOpcodeFromSrcOrDstField(), setEncoding(), socketCodePosition(), SocketEncoding(), 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 {
306 if (hasSocketCodes()) {
307 state->setAttribute(OSKEY_SC_TABLE, socketCodes().name());
308 }
309 return state;
310}
virtual ObjectState * saveState() const
Definition Encoding.cc:141
void setName(const std::string &name)
void setAttribute(const std::string &name, const std::string &value)
SocketCodeTable & socketCodes() const
bool hasSocketCodes() const
static const std::string OSNAME_SOCKET_ENCODING
ObjectState name for socket encoding.
std::string socketName() const

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);
234 }
236}
void setEncoding(unsigned int encoding, unsigned int extraBits)
Definition Encoding.cc:163

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(), 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}
virtual int width() const
Definition SlotField.cc:307

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}
int socketIDWidth() const

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}
virtual int width() const

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

Referenced by printSlotFieldEncodings(), SlotField::width(), and 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: