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

#include <ImmediateEncoding.hh>

Inheritance diagram for ImmediateEncoding:
Inheritance graph
Collaboration diagram for ImmediateEncoding:
Collaboration graph

Public Member Functions

 ImmediateEncoding (unsigned int encoding, unsigned int extraBits, int immediateWidth, SourceField &parent)
 
 ImmediateEncoding (const ObjectState *state, SourceField &parent)
 
virtual ~ImmediateEncoding ()
 
SourceFieldparent () const
 
int immediateWidth () const
 
int encodingWidth () const
 
int encodingPosition () const
 
int immediatePosition () const
 
virtual int bitPosition () const
 
virtual int width () 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_IMM_ENCODING = "imm_encoding"
 ObjectState name for immediate encoding. More...
 
static const std::string OSKEY_IMM_WIDTH = "imm_width"
 ObjectState attribute key for the immediate width. 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 Attributes

int immediateWidth_
 

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

Represents the encoding for inline immediate within the source field.

Definition at line 44 of file ImmediateEncoding.hh.

Constructor & Destructor Documentation

◆ ImmediateEncoding() [1/2]

ImmediateEncoding::ImmediateEncoding ( unsigned int  encoding,
unsigned int  extraBits,
int  immediateWidth,
SourceField parent 
)

The constructor.

Registers the encoding automatically to the parent source field.

Parameters
encodingThe encoding for inline immediates.
extraBitsThe number of extra bits in the encoding.
immediateWidthWidth of the inline immediate.
parentThe parent source field.
Exceptions
ObjectAlreadyExistsIf the given source field has an immediate encoding already or if the encoding is ambiguous with some socket or bridge encoding in the source field.
OutOfRangeIf the given immediate width is negative.

Definition at line 60 of file ImmediateEncoding.cc.

64  if (immediateWidth < 0) {
65  throw OutOfRange(__FILE__, __LINE__, __func__);
66  }
67 
69  setParent(&parent);
70 }

References __func__, immediateWidth(), parent(), SourceField::setImmediateEncoding(), and Encoding::setParent().

Here is the call graph for this function:

◆ ImmediateEncoding() [2/2]

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

The constructor.

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

Parameters
stateThe ObjectState instance.
parentThe parent source field.
Exceptions
ObjectAlreadyExistsIf the given source field has an immediate encoding already or if the encoding is ambiguous with some socket or bridge encoding in the source field.
ObjectStateLoadingExceptionIf the given ObjectState instance is erroneous.

Definition at line 86 of file ImmediateEncoding.cc.

88  : Encoding(state, NULL) {
89  const string procName = "ImmediateEncoding::ImmediateEncoding";
90 
91  if (state->name() != OSNAME_IMM_ENCODING) {
92  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
93  }
94 
95  try {
97  if (immediateWidth_ < 0) {
98  throw OutOfRange(__FILE__, __LINE__, __func__);
99  }
100  } catch (const Exception& e) {
102  __FILE__, __LINE__, __func__, e.errorMessage());
103  }
104 
106  setParent(&parent);
107 }

References __func__, Exception::errorMessage(), immediateWidth_, ObjectState::intAttribute(), ObjectState::name(), OSKEY_IMM_WIDTH, OSNAME_IMM_ENCODING, parent(), SourceField::setImmediateEncoding(), and Encoding::setParent().

Here is the call graph for this function:

◆ ~ImmediateEncoding()

ImmediateEncoding::~ImmediateEncoding ( )
virtual

The destructor.

Definition at line 112 of file ImmediateEncoding.cc.

112  {
113  SourceField* oldParent = parent();
114  assert(oldParent != NULL);
115  setParent(NULL);
116  oldParent->unsetImmediateEncoding();
117 }

References assert, parent(), Encoding::setParent(), and SourceField::unsetImmediateEncoding().

Here is the call graph for this function:

Member Function Documentation

◆ bitPosition()

int ImmediateEncoding::bitPosition ( ) const
virtual

Returns always 0.

Returns
The position of the encoding.

Implements Encoding.

Definition at line 196 of file ImmediateEncoding.cc.

196  {
197  return 0;
198 }

◆ encodingPosition()

int ImmediateEncoding::encodingPosition ( ) const

Returns the position of the immediate encoding.

Returns
The position of the immediate encoding.

Definition at line 166 of file ImmediateEncoding.cc.

166  {
167  if (parent()->componentIDPosition() == BinaryEncoding::LEFT) {
168  return parent()->width() - parent()->extraBits() - encodingWidth();
169  } else {
170  return 0;
171  }
172 }

References encodingWidth(), InstructionField::extraBits(), BinaryEncoding::LEFT, parent(), and SourceField::width().

Referenced by BEMTester::conflictsWithSourceEncodings(), and DefaultDecoderGenerator::writeBusControlRulesOfSImmSocketOfBus().

Here is the call graph for this function:

◆ encodingWidth()

int ImmediateEncoding::encodingWidth ( ) const

Returns the encoding width.

Returns
The encoding width.

Definition at line 155 of file ImmediateEncoding.cc.

155  {
156  return Encoding::width();
157 }

References Encoding::width().

Referenced by BEMTester::conflictsWithSourceEncodings(), CodeCompressorPlugin::encodeImmediateTerminal(), encodingPosition(), printSourceFieldEncodings(), width(), and DefaultDecoderGenerator::writeBusControlRulesOfSImmSocketOfBus().

Here is the call graph for this function:

◆ immediatePosition()

int ImmediateEncoding::immediatePosition ( ) const

Returns the position of the short immediate within the source field.

Returns
The position of the short immediate.

Definition at line 181 of file ImmediateEncoding.cc.

181  {
182  if (parent()->componentIDPosition() == BinaryEncoding::LEFT) {
183  return 0;
184  } else {
185  return parent()->width() - parent()->extraBits() - immediateWidth();
186  }
187 }

References InstructionField::extraBits(), immediateWidth(), BinaryEncoding::LEFT, parent(), and SourceField::width().

Referenced by DefaultDecoderGenerator::writeBusControlRulesOfSImmSocketOfBus(), and DefaultDecoderGenerator::writeSimmDataSignal().

Here is the call graph for this function:

◆ immediateWidth()

int ImmediateEncoding::immediateWidth ( ) const

◆ parent()

SourceField * ImmediateEncoding::parent ( ) const

Returns the parent source field.

Returns
The parent.

Definition at line 126 of file ImmediateEncoding.cc.

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

References assert, and Encoding::parent().

Referenced by encodingPosition(), ImmediateEncoding(), immediatePosition(), SourceField::setImmediateEncoding(), and ~ImmediateEncoding().

Here is the call graph for this function:

◆ saveState()

ObjectState * ImmediateEncoding::saveState ( ) const
virtual

Saves the state of the object to an ObjectState instance.

Returns
The newly created ObjectState instance.

Reimplemented from Encoding.

Definition at line 218 of file ImmediateEncoding.cc.

218  {
219  ObjectState* state = Encoding::saveState();
222  return state;
223 }

References immediateWidth(), OSKEY_IMM_WIDTH, OSNAME_IMM_ENCODING, Encoding::saveState(), ObjectState::setAttribute(), and ObjectState::setName().

Here is the call graph for this function:

◆ width()

int ImmediateEncoding::width ( ) const
virtual

Returns the width of the encoding + immediate width.

Returns
The width.

Reimplemented from Encoding.

Definition at line 207 of file ImmediateEncoding.cc.

207  {
208  return immediateWidth() + encodingWidth();
209 }

References encodingWidth(), and immediateWidth().

Referenced by BEMTester::canAddComponentEncoding(), printSourceFieldEncodings(), and SourceField::width().

Here is the call graph for this function:

Member Data Documentation

◆ immediateWidth_

int ImmediateEncoding::immediateWidth_
private

Definition at line 68 of file ImmediateEncoding.hh.

Referenced by ImmediateEncoding(), and immediateWidth().

◆ OSKEY_IMM_WIDTH

const std::string ImmediateEncoding::OSKEY_IMM_WIDTH = "imm_width"
static

ObjectState attribute key for the immediate width.

Definition at line 65 of file ImmediateEncoding.hh.

Referenced by ImmediateEncoding(), saveState(), BEMSerializer::sourceFieldToFile(), and BEMSerializer::sourceFieldToOM().

◆ OSNAME_IMM_ENCODING

const std::string ImmediateEncoding::OSNAME_IMM_ENCODING = "imm_encoding"
static

The documentation for this class was generated from the following files:
SourceField::setImmediateEncoding
void setImmediateEncoding(ImmediateEncoding &encoding)
Definition: SourceField.cc:243
ObjectStateLoadingException
Definition: Exception.hh:551
ImmediateEncoding::OSNAME_IMM_ENCODING
static const std::string OSNAME_IMM_ENCODING
ObjectState name for immediate encoding.
Definition: ImmediateEncoding.hh:63
SourceField::unsetImmediateEncoding
void unsetImmediateEncoding()
Definition: SourceField.cc:265
OutOfRange
Definition: Exception.hh:320
Encoding::setParent
void setParent(InstructionField *parent)
Definition: Encoding.cc:155
Encoding::parent
InstructionField * parent() const
Definition: Encoding.cc:97
ImmediateEncoding::parent
SourceField * parent() const
Definition: ImmediateEncoding.cc:126
ObjectState
Definition: ObjectState.hh:59
ObjectState::setName
void setName(const std::string &name)
ImmediateEncoding::immediateWidth_
int immediateWidth_
Definition: ImmediateEncoding.hh:68
InstructionField
Definition: InstructionField.hh:43
assert
#define assert(condition)
Definition: Application.hh:86
Encoding::width
virtual int width() const
Definition: Encoding.cc:130
ImmediateEncoding::OSKEY_IMM_WIDTH
static const std::string OSKEY_IMM_WIDTH
ObjectState attribute key for the immediate width.
Definition: ImmediateEncoding.hh:65
BinaryEncoding::LEFT
@ LEFT
Definition: BinaryEncoding.hh:64
__func__
#define __func__
Definition: Application.hh:67
SourceField::width
virtual int width() const
Definition: SourceField.cc:308
Encoding::encoding
unsigned int encoding() const
Definition: Encoding.cc:108
Exception
Definition: Exception.hh:54
ObjectState::name
std::string name() const
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
ImmediateEncoding::immediateWidth
int immediateWidth() const
Definition: ImmediateEncoding.cc:144
Encoding::saveState
virtual ObjectState * saveState() const
Definition: Encoding.cc:141
InstructionField::extraBits
int extraBits() const
Definition: InstructionField.cc:229
ImmediateEncoding::encodingWidth
int encodingWidth() const
Definition: ImmediateEncoding.cc:155
Encoding::Encoding
Encoding(unsigned int encoding, unsigned int extraBits, InstructionField *parent)
Definition: Encoding.cc:53
ObjectState::intAttribute
int intAttribute(const std::string &name) const
Definition: ObjectState.cc:276
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
SourceField
Definition: SourceField.hh:48