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

#include <SourceField.hh>

Inheritance diagram for SourceField:
Inheritance graph
Collaboration diagram for SourceField:
Collaboration graph

Public Member Functions

 SourceField (BinaryEncoding::Position componentIDPos, MoveSlot &parent)
 
 SourceField (const ObjectState *state, MoveSlot &parent)
 
virtual ~SourceField ()
 
void addBridgeEncoding (BridgeEncoding &encoding)
 
void removeBridgeEncoding (BridgeEncoding &encoding)
 
bool hasBridgeEncoding (const std::string &bridge) const
 
BridgeEncodingbridgeEncoding (const std::string &bridge) const
 
int bridgeEncodingCount () const
 
BridgeEncodingbridgeEncoding (int index) const
 
void setImmediateEncoding (ImmediateEncoding &encoding)
 
void unsetImmediateEncoding ()
 
bool hasImmediateEncoding () const
 
ImmediateEncodingimmediateEncoding () const
 
virtual int width () const
 
virtual void loadState (const ObjectState *state)
 
virtual ObjectStatesaveState () const
 
- Public Member Functions inherited from SlotField
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 childFieldCount () const
 
virtual InstructionFieldchildField (int position) 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_SOURCE_FIELD = "source_field"
 ObjectState name for source field.
 
- Static Public Attributes inherited from SlotField
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.
 

Private Types

typedef std::vector< BridgeEncoding * > BridgeEncodingTable
 Container type for bridge encodings.
 

Private Member Functions

void clearBridgeEncodings ()
 
void clearImmediateEncoding ()
 

Private Attributes

BridgeEncodingTable bridgeEncodings_
 Container for bridge encodings.
 
ImmediateEncodingimmEncoding_
 The immediate encoding.
 

Additional Inherited Members

- Protected Member Functions inherited from SlotField
 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)
 
- Static Protected Member Functions inherited from InstructionField
static void reorderSubfields (ObjectState *state)
 

Detailed Description

SourceField class represents the source field of a move slot.

It is a specialisation of InstructionField class. In addition to socket encodings, a source field may encode an inline immediate or up to two bridge sources.

Definition at line 48 of file SourceField.hh.

Member Typedef Documentation

◆ BridgeEncodingTable

typedef std::vector<BridgeEncoding*> SourceField::BridgeEncodingTable
private

Container type for bridge encodings.

Definition at line 78 of file SourceField.hh.

Constructor & Destructor Documentation

◆ SourceField() [1/2]

SourceField::SourceField ( BinaryEncoding::Position  componentIDPos,
MoveSlot parent 
)

The constructor.

Creates a source field and registers it into the given move slot.

Parameters
componentIDPosPosition of the socket or bridge ID within the source field.
parentThe parent move slot.
Exceptions
ObjectAlreadyExistsIf the given move slot already has a source field.
IllegalParametersIf the given component ID position is not the same with other source fields in the binary encoding map.

Definition at line 65 of file SourceField.cc.

67 : SlotField(componentIDPos, parent), immEncoding_(NULL) {
69 for (int i = 0; i < bem->moveSlotCount(); i++) {
70 MoveSlot& slot = bem->moveSlot(i);
71 if (slot.hasSourceField() &&
72 (slot.sourceField().componentIDPosition() != componentIDPos)) {
73 const string procName = "SourceField::SourceField";
74 throw IllegalParameters(__FILE__, __LINE__, procName);
75 } else {
76 break;
77 }
78 }
79
80 setParent(NULL);
83}
int moveSlotCount() const
MoveSlot & moveSlot(int index) const
void setParent(InstructionField *parent)
BinaryEncoding * parent() const
Definition MoveSlot.cc:118
SourceField & sourceField() const
Definition MoveSlot.cc:277
void setSourceField(SourceField &field)
Definition MoveSlot.cc:233
bool hasSourceField() const
Definition MoveSlot.cc:264
MoveSlot * parent() const
Definition SlotField.cc:98
BinaryEncoding::Position componentIDPosition() const
Definition SlotField.cc:296
ImmediateEncoding * immEncoding_
The immediate encoding.

References SlotField::componentIDPosition(), MoveSlot::hasSourceField(), BinaryEncoding::moveSlot(), BinaryEncoding::moveSlotCount(), MoveSlot::parent(), SlotField::parent(), InstructionField::setParent(), MoveSlot::setSourceField(), and MoveSlot::sourceField().

Here is the call graph for this function:

◆ SourceField() [2/2]

SourceField::SourceField ( const ObjectState state,
MoveSlot parent 
)

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.
ObjectAlreadyExistsIf the given move slot already has a source field.

Definition at line 97 of file SourceField.cc.

98 : SlotField(state, parent), immEncoding_(NULL) {
99 loadState(state);
100 setParent(NULL);
101 parent.setSourceField(*this);
103}
virtual void loadState(const ObjectState *state)

References loadState(), SlotField::parent(), InstructionField::setParent(), and MoveSlot::setSourceField().

Here is the call graph for this function:

◆ ~SourceField()

SourceField::~SourceField ( )
virtual

The destructor.

Definition at line 108 of file SourceField.cc.

108 {
111 MoveSlot* parent = this->parent();
112 setParent(NULL);
114}
void unsetSourceField()
Definition MoveSlot.cc:251
void clearBridgeEncodings()
void clearImmediateEncoding()

References clearBridgeEncodings(), clearImmediateEncoding(), SlotField::parent(), InstructionField::setParent(), and MoveSlot::unsetSourceField().

Here is the call graph for this function:

Member Function Documentation

◆ addBridgeEncoding()

void SourceField::addBridgeEncoding ( BridgeEncoding encoding)

Adds the given encoding for a bridge to the source field.

This method is to be called from the constructor of BridgeEncoding class.

Parameters
encodingThe encoding to be added.
Exceptions
ObjectAlreadyExistsIf the field already has an encoding for the given bridge or if the encoding is ambiguous with another encoding or if the source field has encodings for two bridges already.

Definition at line 130 of file SourceField.cc.

130 {
131 assert(encoding.parent() == NULL);
132 string bridge = encoding.bridgeName();
133
134 const string procName = "SourceField::addBridgeEncoding";
135
136 if (hasBridgeEncoding(bridge) ||
138 *this, encoding.encoding(), encoding.extraBits()) ||
139 bridgeEncodingCount() == 2) {
140 throw ObjectAlreadyExists(__FILE__, __LINE__, procName);
141 }
142
143 bridgeEncodings_.push_back(&encoding);
144}
#define assert(condition)
static bool canAddComponentEncoding(SlotField &field, unsigned int encoding, unsigned int extraBits)
Definition BEMTester.cc:73
std::string bridgeName() const
SourceField * parent() const
unsigned int extraBits() const
Definition Encoding.cc:119
unsigned int encoding() const
Definition Encoding.cc:108
BridgeEncodingTable bridgeEncodings_
Container for bridge encodings.
int bridgeEncodingCount() const
bool hasBridgeEncoding(const std::string &bridge) const

References assert, bridgeEncodingCount(), bridgeEncodings_, BridgeEncoding::bridgeName(), BEMTester::canAddComponentEncoding(), Encoding::encoding(), Encoding::extraBits(), hasBridgeEncoding(), and BridgeEncoding::parent().

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

Here is the call graph for this function:

◆ bridgeEncoding() [1/2]

BridgeEncoding & SourceField::bridgeEncoding ( const std::string &  bridge) const

Returns the encoding for the given bridge.

Parameters
bridgeName of the bridge.
Returns
The bridge encoding for the given bridge or NullBridgeEncoding instance if there is no encoding for the given bridge.

Definition at line 191 of file SourceField.cc.

191 {
192 int encodingCount = bridgeEncodingCount();
193 for (int i = 0; i < encodingCount; i++) {
194 BridgeEncoding& encoding = bridgeEncoding(i);
195 if (encoding.bridgeName() == bridge) {
196 return encoding;
197 }
198 }
200}
static NullBridgeEncoding & instance()
BridgeEncoding & bridgeEncoding(const std::string &bridge) const

References bridgeEncoding(), bridgeEncodingCount(), BridgeEncoding::bridgeName(), and NullBridgeEncoding::instance().

Referenced by bridgeEncoding(), BEMTester::canAddComponentEncoding(), hasBridgeEncoding(), printSourceFieldEncodings(), saveState(), and width().

Here is the call graph for this function:

◆ bridgeEncoding() [2/2]

BridgeEncoding & SourceField::bridgeEncoding ( int  index) const

Returns the bridge encoding stored at the given position.

Parameters
indexThe position.
Exceptions
OutOfRangeIf the given index is negative or not smaller than the number of bridge encodings.

Definition at line 222 of file SourceField.cc.

222 {
223 if (index < 0 || index >= bridgeEncodingCount()) {
224 const string procName = "SourceField::bridgeEncoding";
225 throw OutOfRange(__FILE__, __LINE__, procName);
226 }
227
228 return *bridgeEncodings_[index];
229}

References bridgeEncodingCount(), and bridgeEncodings_.

Here is the call graph for this function:

◆ bridgeEncodingCount()

int SourceField::bridgeEncodingCount ( ) const

Returns the number of bridge encodings defined for this source field.

Returns
The number of bridge encodings.

Definition at line 209 of file SourceField.cc.

209 {
210 return bridgeEncodings_.size();
211}

References bridgeEncodings_.

Referenced by addBridgeEncoding(), bridgeEncoding(), bridgeEncoding(), BEMTester::canAddComponentEncoding(), hasBridgeEncoding(), printSourceFieldEncodings(), saveState(), and width().

◆ clearBridgeEncodings()

void SourceField::clearBridgeEncodings ( )
private

Clears all the bridge encodings from the source field.

Definition at line 396 of file SourceField.cc.

396 {
398}
static void deleteAllItems(SequenceType &aSequence)

References bridgeEncodings_, and SequenceTools::deleteAllItems().

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

Here is the call graph for this function:

◆ clearImmediateEncoding()

void SourceField::clearImmediateEncoding ( )
private

Deletes the immediate encoding if one exists.

Definition at line 405 of file SourceField.cc.

405 {
406 if (hasImmediateEncoding()) {
407 delete immEncoding_;
408 }
409}
bool hasImmediateEncoding() const

References hasImmediateEncoding(), and immEncoding_.

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

Here is the call graph for this function:

◆ hasBridgeEncoding()

bool SourceField::hasBridgeEncoding ( const std::string &  bridge) const

Tells whether the source field has an encoding defined for the given bridge.

Parameters
bridgeName of the bridge.
Returns
True if there is an encoding for the given bridge, otherwise false.

Definition at line 169 of file SourceField.cc.

169 {
170
171 int bridgeEncodings = bridgeEncodingCount();
172 for (int i = 0; i < bridgeEncodings; i++) {
173 BridgeEncoding& encoding = bridgeEncoding(i);
174 if (encoding.bridgeName() == bridge) {
175 return true;
176 }
177 }
178
179 return false;
180}

References bridgeEncoding(), bridgeEncodingCount(), and BridgeEncoding::bridgeName().

Referenced by addBridgeEncoding(), and BEMValidator::checkSourceField().

Here is the call graph for this function:

◆ hasImmediateEncoding()

bool SourceField::hasImmediateEncoding ( ) const

Tells whether the source field has an immediate encoding.

Returns
True if the source field has an immediate encoding, otherwise false.

Definition at line 279 of file SourceField.cc.

279 {
280 return immEncoding_ != NULL;
281}

References immEncoding_.

Referenced by BEMTester::canAddComponentEncoding(), BEMValidator::checkSourceField(), clearImmediateEncoding(), BEMTester::conflictsWithSourceEncodings(), immediateEncoding(), printSourceFieldEncodings(), saveState(), setImmediateEncoding(), unsetImmediateEncoding(), width(), and DefaultDecoderGenerator::writeBusControlRulesOfSImmSocketOfBus().

◆ immediateEncoding()

ImmediateEncoding & SourceField::immediateEncoding ( ) const

Returns the immediate encoding.

Returns NullImmediateEncoding instance if the source field does not have an immediate encoding.

Returns
The immediate encoding.

Definition at line 293 of file SourceField.cc.

293 {
294 if (hasImmediateEncoding()) {
295 return *immEncoding_;
296 } else {
298 }
299}
static NullImmediateEncoding & instance()

References hasImmediateEncoding(), immEncoding_, and NullImmediateEncoding::instance().

Referenced by BEMTester::canAddComponentEncoding(), BEMTester::conflictsWithSourceEncodings(), CodeCompressorPlugin::encodeImmediateTerminal(), printSourceFieldEncodings(), saveState(), unsetImmediateEncoding(), width(), DefaultDecoderGenerator::writeBusControlRulesOfSImmSocketOfBus(), and DefaultDecoderGenerator::writeSimmDataSignal().

Here is the call graph for this function:

◆ loadState()

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

Definition at line 336 of file SourceField.cc.

336 {
337 const string procName = "SourceField::loadState";
338
339 if (state->name() != OSNAME_SOURCE_FIELD) {
340 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
341 }
342
346
347 try {
348 for (int i = 0; i < state->childCount(); i++) {
349 ObjectState* child = state->child(i);
351 new BridgeEncoding(child, *this);
352 } else if (child->name() ==
354 new ImmediateEncoding(child, *this);
355 }
356 }
357 } catch (const Exception& exception) {
359 __FILE__, __LINE__, procName, exception.errorMessage());
360 }
361
362 // TODO: check that the positions of the encodings match with the
363 // ones given in the ObjectState instances
364}
static const std::string OSNAME_BRIDGE_ENCODING
ObjectState name for bridge encoding.
std::string errorMessage() const
Definition Exception.cc:123
static const std::string OSNAME_IMM_ENCODING
ObjectState name for immediate encoding.
ObjectState * child(int index) const
std::string name() const
int childCount() const
virtual void loadState(const ObjectState *state)
Definition SlotField.cc:358
static const std::string OSNAME_SOURCE_FIELD
ObjectState name for source field.

References ObjectState::child(), ObjectState::childCount(), clearBridgeEncodings(), clearImmediateEncoding(), Exception::errorMessage(), SlotField::loadState(), ObjectState::name(), BridgeEncoding::OSNAME_BRIDGE_ENCODING, ImmediateEncoding::OSNAME_IMM_ENCODING, and OSNAME_SOURCE_FIELD.

Referenced by SourceField().

Here is the call graph for this function:

◆ removeBridgeEncoding()

void SourceField::removeBridgeEncoding ( BridgeEncoding encoding)

Removes the given bridge encoding from the source field.

This method is to be called from the destructor of BridgeEncoding class.

Parameters
encodingThe encoding to be removed.

Definition at line 154 of file SourceField.cc.

154 {
155 assert(encoding.parent() == NULL);
157}
static bool removeValueIfExists(ContainerType &aContainer, const ElementType &aKey)

References assert, bridgeEncodings_, BridgeEncoding::parent(), and ContainerTools::removeValueIfExists().

Referenced by BridgeEncoding::~BridgeEncoding().

Here is the call graph for this function:

◆ saveState()

ObjectState * SourceField::saveState ( ) const
virtual

Saves the state of the object to an ObjectState tree.

Returns
The newly created ObjectState tree.

Reimplemented from SlotField.

Definition at line 372 of file SourceField.cc.

372 {
373
376
377 // add bridge encodings
378 for (int i = 0; i < bridgeEncodingCount(); i++) {
380 state->addChild(enc.saveState());
381 }
382
383 // add immediate encoding
384 if (hasImmediateEncoding()) {
386 }
387
388 return state;
389}
virtual ObjectState * saveState() const
void setName(const std::string &name)
void addChild(ObjectState *child)
virtual ObjectState * saveState() const
Definition SlotField.cc:388
ImmediateEncoding & immediateEncoding() const
virtual ObjectState * saveState() const

References ObjectState::addChild(), bridgeEncoding(), bridgeEncodingCount(), hasImmediateEncoding(), immediateEncoding(), OSNAME_SOURCE_FIELD, BridgeEncoding::saveState(), SlotField::saveState(), saveState(), and ObjectState::setName().

Referenced by saveState().

Here is the call graph for this function:

◆ setImmediateEncoding()

void SourceField::setImmediateEncoding ( ImmediateEncoding encoding)

Sets the given encoding for inline immediates.

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

Parameters
encodingThe encoding to be set.
Exceptions
ObjectAlreadyExistsIf the source field has an immediate encoding already or if the given encoding is ambiguous with some socket or bridge encoding.

Definition at line 243 of file SourceField.cc.

243 {
244 assert(encoding.parent() == NULL);
245
246 if (hasImmediateEncoding() ||
248 *this, encoding.encoding(), encoding.extraBits())) {
249 BEMTextGenerator textGen;
250 format text = textGen.text(BEMTextGenerator::TXT_ILLEGAL_IMM_ENC);
251 text % parent()->name();
252 const string procName = "SourceField::setImmediateEncoding";
253 throw ObjectAlreadyExists(__FILE__, __LINE__, procName, text.str());
254 }
255
256 immEncoding_ = &encoding;
257}
SourceField * parent() const
std::string name() const
Definition MoveSlot.cc:136
virtual boost::format text(int textId)

References assert, BEMTester::canAddComponentEncoding(), Encoding::encoding(), Encoding::extraBits(), hasImmediateEncoding(), immEncoding_, MoveSlot::name(), ImmediateEncoding::parent(), SlotField::parent(), Texts::TextGenerator::text(), and BEMTextGenerator::TXT_ILLEGAL_IMM_ENC.

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

Here is the call graph for this function:

◆ unsetImmediateEncoding()

void SourceField::unsetImmediateEncoding ( )

Unsets the immediate encoding.

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

Definition at line 265 of file SourceField.cc.

265 {
267 assert(immediateEncoding().parent() == NULL);
268 immEncoding_ = NULL;
269}

References assert, hasImmediateEncoding(), immediateEncoding(), immEncoding_, and SlotField::parent().

Referenced by ImmediateEncoding::~ImmediateEncoding().

Here is the call graph for this function:

◆ width()

int SourceField::width ( ) const
virtual

Returns the bit width of the source field.

Returns
The bit width.

Reimplemented from SlotField.

Definition at line 308 of file SourceField.cc.

308 {
309
310 int maxEncodingWidth = SlotField::width() - extraBits();
311
312 for (int i = 0; i < bridgeEncodingCount(); i++) {
313 BridgeEncoding& encoding = bridgeEncoding(i);
314 if (encoding.width() > maxEncodingWidth) {
315 maxEncodingWidth = encoding.width();
316 }
317 }
318
320 maxEncodingWidth) {
321 maxEncodingWidth = immediateEncoding().width();
322 }
323
324 return maxEncodingWidth + extraBits();
325}
virtual int width() const
Definition Encoding.cc:130
virtual int width() const
virtual int width() const
Definition SlotField.cc:307
virtual int width() const

References bridgeEncoding(), bridgeEncodingCount(), InstructionField::extraBits(), hasImmediateEncoding(), immediateEncoding(), Encoding::width(), ImmediateEncoding::width(), SlotField::width(), and width().

Referenced by CodeCompressorPlugin::addBitsForSourceField(), BridgeEncoding::bitPosition(), BEMTester::canAddComponentPriorityEncoding(), CodeCompressorPlugin::encodeImmediateTerminal(), CodeCompressorPlugin::encodeMove(), CodeCompressorPlugin::encodeNOP(), ImmediateEncoding::encodingPosition(), ImmediateEncoding::immediatePosition(), printMoveSlotLayout(), printSourceFieldEncodings(), MoveSlot::width(), width(), DefaultDecoderGenerator::writeInstructionDismembering(), and DefaultDecoderGenerator::writeMoveFieldSignals().

Here is the call graph for this function:

Member Data Documentation

◆ bridgeEncodings_

BridgeEncodingTable SourceField::bridgeEncodings_
private

Container for bridge encodings.

Definition at line 84 of file SourceField.hh.

Referenced by addBridgeEncoding(), bridgeEncoding(), bridgeEncodingCount(), clearBridgeEncodings(), and removeBridgeEncoding().

◆ immEncoding_

ImmediateEncoding* SourceField::immEncoding_
private

◆ OSNAME_SOURCE_FIELD

const std::string SourceField::OSNAME_SOURCE_FIELD = "source_field"
static

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