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

#include <PortCode.hh>

Inheritance diagram for PortCode:
Inheritance graph
Collaboration diagram for PortCode:
Collaboration graph

Public Member Functions

virtual ~PortCode ()
 
std::string unitName () const
 
bool hasEncoding () const
 
unsigned int encoding () const
 
unsigned int extraBits () const
 
int width () const
 
int encodingWidth () const
 
int indexWidth () const
 
void setMaxIndex (unsigned regIndex)
 
bool isMaxIndexSet () const
 
unsigned maxIndex () const
 
SocketCodeTableparent () const
 
virtual ObjectStatesaveState () const
 

Static Public Attributes

static const std::string OSNAME_PORT_CODE = "port_code"
 ObjectState name for PortCode. More...
 
static const std::string OSKEY_UNIT_NAME = "unit_name"
 ObjectState attribute key for the name of the unit. 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...
 
static const std::string OSKEY_INDEX_WIDTH = "index_width"
 ObjectState attribute key for the widht of register index. More...
 
static const std::string OSKEY_MAX_INDEX = "max-index"
 ObjectState attribute key for the max-index attribute. More...
 

Protected Member Functions

 PortCode (const std::string &unitName, unsigned int encoding, unsigned int extraBits, int indexWidth)
 
 PortCode (const std::string &unitName, int indexWidth)
 
 PortCode (const ObjectState *state)
 
void setParent (SocketCodeTable *parent)
 

Private Attributes

std::string unitName_
 Name of the unit. More...
 
unsigned int encoding_
 The encoding. More...
 
unsigned int extraBits_
 The number of extra bits in the encoding. More...
 
int indexWidth_
 The width of the register index in the port code. More...
 
bool hasEncoding_
 Tells whether the port code has an encoding. More...
 
SocketCodeTableparent_
 The parent socket code table. More...
 
unsigned maxRegIndex_
 In case this is set to non-zero, the whole width of the index field is not used because the number of register indices is not an exponent of two. This allow sharing the field with other values. More...
 

Detailed Description

Base class for FUPortCode, RFPortCode and IUPortCode.

Definition at line 45 of file PortCode.hh.

Constructor & Destructor Documentation

◆ ~PortCode()

PortCode::~PortCode ( )
virtual

The destructor.

Definition at line 130 of file PortCode.cc.

130  {
131 }

◆ PortCode() [1/3]

PortCode::PortCode ( const std::string &  unitName,
unsigned int  encoding,
unsigned int  extraBits,
int  indexWidth 
)
protected

The constructor.

Creates a port code with port ID.

Parameters
unitNameName of the unit.
encodingThe encoding.
extraBitsThe number of extra bits in the encoding.
indexWidthThe width of the register index.
Exceptions
OutOfRangeIf the some of the given values is negative.

Definition at line 56 of file PortCode.cc.

63  hasEncoding_(true),
64  parent_(NULL),
65  maxRegIndex_(0) {
66  if (indexWidth_ < 0) {
67  throw OutOfRange(__FILE__, __LINE__, __func__);
68  }
69 }

References __func__, and indexWidth_.

◆ PortCode() [2/3]

PortCode::PortCode ( const std::string &  unitName,
int  indexWidth 
)
protected

The constructor.

Creates a port code without port ID.

Parameters
unitNameName of the unit.
indexWidthThe width of the register index.
Exceptions
OutOfRangeIf the some of the given values is negative.

Definition at line 80 of file PortCode.cc.

82  encoding_(0),
83  extraBits_(0),
85  hasEncoding_(false),
86  parent_(NULL),
87  maxRegIndex_(0) {
88  if (indexWidth_ < 0) {
89  throw OutOfRange(__FILE__, __LINE__, __func__);
90  }
91 }

References __func__, and indexWidth_.

◆ PortCode() [3/3]

PortCode::PortCode ( const ObjectState state)
protected

The constructor.

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

Parameters
stateThe ObjectState instance.
Exceptions
ObjectStateLoadingExceptionIf the given ObjectState instance is erroneous.

Definition at line 102 of file PortCode.cc.

103  : unitName_(""),
104  encoding_(0),
105  extraBits_(0),
106  indexWidth_(0),
107  hasEncoding_(false),
108  parent_(NULL),
109  maxRegIndex_(0) {
110  try {
112  if (state->hasAttribute(OSKEY_MAX_INDEX))
114  if (state->hasAttribute(OSKEY_ENCODING)) {
117  hasEncoding_ = true;
118  }
119  if (state->hasAttribute(OSKEY_INDEX_WIDTH)) {
121  }
122  } catch (const Exception&) {
123  throw ObjectStateLoadingException(__FILE__, __LINE__, __func__);
124  }
125 }

References __func__, encoding_, extraBits_, ObjectState::hasAttribute(), hasEncoding_, indexWidth_, ObjectState::intAttribute(), maxRegIndex_, OSKEY_ENCODING, OSKEY_EXTRA_BITS, OSKEY_INDEX_WIDTH, OSKEY_MAX_INDEX, OSKEY_UNIT_NAME, ObjectState::stringAttribute(), and unitName_.

Here is the call graph for this function:

Member Function Documentation

◆ encoding()

unsigned int PortCode::encoding ( ) const

Returns the encoding.

Returns
The encoding.
Exceptions
NotAvailableIf the port code does not have an encoding (port ID).

Definition at line 164 of file PortCode.cc.

164  {
165  if (!hasEncoding()) {
166  throw NotAvailable(__FILE__, __LINE__, __func__);
167  }
168  return encoding_;
169 }

References __func__, encoding_, and hasEncoding().

Referenced by SocketCodeTable::addFUPortCode(), SocketCodeTable::addIUPortCode(), SocketCodeTable::addRFPortCode(), BEMTester::canAddPortEncoding(), BEMTester::conflictsWithSocketTableEncodings(), CodeCompressorPlugin::encodeFUTerminal(), portCodeBits(), DefaultDecoderGenerator::portCodeCondition(), saveState(), CodeCompressorPlugin::socketCodeBits(), width(), and DefaultDecoderGenerator::writeControlRulesOfFUInputPort().

Here is the call graph for this function:

◆ encodingWidth()

int PortCode::encodingWidth ( ) const

Returns the width of the encoding (port ID).

Returns
The width of the encoding.

Definition at line 204 of file PortCode.cc.

204  {
205  return width() - indexWidth();
206 }

References indexWidth(), and width().

Referenced by BEMTester::canAddPortEncoding(), BEMTester::conflictsWithSocketTableEncodings(), portCodeBits(), DefaultDecoderGenerator::portCodeCondition(), and DefaultDecoderGenerator::writeControlRulesOfFUInputPort().

Here is the call graph for this function:

◆ extraBits()

unsigned int PortCode::extraBits ( ) const

Returns the number of extra bits in the encoding.

Returns
The number of extra bits.

Definition at line 177 of file PortCode.cc.

177  {
178  return extraBits_;
179 }

References extraBits_.

Referenced by SocketCodeTable::addFUPortCode(), SocketCodeTable::addIUPortCode(), SocketCodeTable::addRFPortCode(), BEMTester::canAddPortEncoding(), saveState(), and width().

◆ hasEncoding()

bool PortCode::hasEncoding ( ) const

Tells whether the port code has an encoding (port ID).

Returns
True if the port code has an encoding, otherwise false.

Definition at line 151 of file PortCode.cc.

151  {
152  return hasEncoding_;
153 }

References hasEncoding_.

Referenced by SocketCodeTable::addIUPortCode(), SocketCodeTable::addRFPortCode(), encoding(), portCodeBits(), saveState(), CodeCompressorPlugin::socketCodeBits(), width(), DefaultDecoderGenerator::writeControlRulesOfRFReadPort(), and DefaultDecoderGenerator::writeControlRulesOfRFWritePort().

◆ indexWidth()

int PortCode::indexWidth ( ) const

◆ isMaxIndexSet()

bool PortCode::isMaxIndexSet ( ) const
inline

Definition at line 59 of file PortCode.hh.

59 { return maxRegIndex_ != 0; }

References maxRegIndex_.

◆ maxIndex()

unsigned PortCode::maxIndex ( ) const
inline

Definition at line 60 of file PortCode.hh.

60 { return maxRegIndex_; }

References maxRegIndex_.

◆ parent()

SocketCodeTable * PortCode::parent ( ) const

◆ saveState()

ObjectState * PortCode::saveState ( ) const
virtual

Saves the state of the object to an ObjectState instance.

Returns
The newly created ObjectState instance.

Reimplemented in FUPortCode, RFPortCode, and IUPortCode.

Definition at line 237 of file PortCode.cc.

237  {
240  if (hasEncoding()) {
243  }
246  return state;
247 }

References encoding(), extraBits(), hasEncoding(), indexWidth(), maxRegIndex_, OSKEY_ENCODING, OSKEY_EXTRA_BITS, OSKEY_INDEX_WIDTH, OSKEY_MAX_INDEX, OSKEY_UNIT_NAME, OSNAME_PORT_CODE, ObjectState::setAttribute(), and unitName().

Referenced by IUPortCode::saveState(), RFPortCode::saveState(), and FUPortCode::saveState().

Here is the call graph for this function:

◆ setMaxIndex()

void PortCode::setMaxIndex ( unsigned  regIndex)
inline

Definition at line 58 of file PortCode.hh.

58 { maxRegIndex_ = regIndex; }

References maxRegIndex_.

◆ setParent()

void PortCode::setParent ( SocketCodeTable parent)
protected

Sets the parent socket code table pointer.

Parameters
parentThe parent pointer.

Definition at line 256 of file PortCode.cc.

256  {
257  parent_ = parent;
258 }

References parent(), and parent_.

Referenced by FUPortCode::FUPortCode(), IUPortCode::IUPortCode(), RFPortCode::RFPortCode(), FUPortCode::~FUPortCode(), IUPortCode::~IUPortCode(), and RFPortCode::~RFPortCode().

Here is the call graph for this function:

◆ unitName()

std::string PortCode::unitName ( ) const

Returns the name of the unit.

Returns
The name of the unit.

Definition at line 140 of file PortCode.cc.

140  {
141  return unitName_;
142 }

References unitName_.

Referenced by SocketCodeTable::addFUPortCode(), SocketCodeTable::addIUPortCode(), SocketCodeTable::addRFPortCode(), SocketCodeTable::fuPortCode(), SocketCodeTable::iuPortCode(), portCodeDescription(), SocketCodeTable::rfPortCode(), and saveState().

◆ width()

int PortCode::width ( ) const

Returns the width of the whole port code (portID + opcode).

Returns
The width.

Definition at line 188 of file PortCode.cc.

188  {
189  if (hasEncoding()) {
190  return MathTools::bitLength(encoding()) + extraBits() +
191  indexWidth();
192  } else {
193  return indexWidth();
194  }
195 }

References MathTools::bitLength(), encoding(), extraBits(), hasEncoding(), and indexWidth().

Referenced by encodingWidth(), SocketCodeTable::maxCodeWidth(), portCodeBits(), and CodeCompressorPlugin::socketCodeBits().

Here is the call graph for this function:

Member Data Documentation

◆ encoding_

unsigned int PortCode::encoding_
private

The encoding.

Definition at line 91 of file PortCode.hh.

Referenced by encoding(), and PortCode().

◆ extraBits_

unsigned int PortCode::extraBits_
private

The number of extra bits in the encoding.

Definition at line 93 of file PortCode.hh.

Referenced by extraBits(), and PortCode().

◆ hasEncoding_

bool PortCode::hasEncoding_
private

Tells whether the port code has an encoding.

Definition at line 97 of file PortCode.hh.

Referenced by hasEncoding(), and PortCode().

◆ indexWidth_

int PortCode::indexWidth_
private

The width of the register index in the port code.

Definition at line 95 of file PortCode.hh.

Referenced by indexWidth(), and PortCode().

◆ maxRegIndex_

unsigned PortCode::maxRegIndex_
private

In case this is set to non-zero, the whole width of the index field is not used because the number of register indices is not an exponent of two. This allow sharing the field with other values.

Definition at line 104 of file PortCode.hh.

Referenced by isMaxIndexSet(), maxIndex(), PortCode(), saveState(), and setMaxIndex().

◆ OSKEY_ENCODING

const std::string PortCode::OSKEY_ENCODING = "encoding"
static

◆ OSKEY_EXTRA_BITS

const std::string PortCode::OSKEY_EXTRA_BITS = "extra_bits"
static

◆ OSKEY_INDEX_WIDTH

const std::string PortCode::OSKEY_INDEX_WIDTH = "index_width"
static

ObjectState attribute key for the widht of register index.

Definition at line 75 of file PortCode.hh.

Referenced by PortCode(), BEMSerializer::readRegisterFilePortCode(), saveState(), and BEMSerializer::socketCodeTableToFile().

◆ OSKEY_MAX_INDEX

const std::string PortCode::OSKEY_MAX_INDEX = "max-index"
static

ObjectState attribute key for the max-index attribute.

Definition at line 77 of file PortCode.hh.

Referenced by PortCode(), saveState(), and BEMSerializer::socketCodeTableToFile().

◆ OSKEY_UNIT_NAME

const std::string PortCode::OSKEY_UNIT_NAME = "unit_name"
static

◆ OSNAME_PORT_CODE

const std::string PortCode::OSNAME_PORT_CODE = "port_code"
static

ObjectState name for PortCode.

Definition at line 67 of file PortCode.hh.

Referenced by saveState().

◆ parent_

SocketCodeTable* PortCode::parent_
private

The parent socket code table.

Definition at line 99 of file PortCode.hh.

Referenced by parent(), and setParent().

◆ unitName_

std::string PortCode::unitName_
private

Name of the unit.

Definition at line 89 of file PortCode.hh.

Referenced by PortCode(), and unitName().


The documentation for this class was generated from the following files:
ObjectState::hasAttribute
bool hasAttribute(const std::string &name) const
Definition: ObjectState.cc:205
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
ObjectStateLoadingException
Definition: Exception.hh:551
PortCode::OSKEY_EXTRA_BITS
static const std::string OSKEY_EXTRA_BITS
ObjectState attribute key for the number of extra bits.
Definition: PortCode.hh:73
OutOfRange
Definition: Exception.hh:320
ObjectState
Definition: ObjectState.hh:59
PortCode::OSKEY_UNIT_NAME
static const std::string OSKEY_UNIT_NAME
ObjectState attribute key for the name of the unit.
Definition: PortCode.hh:69
PortCode::parent_
SocketCodeTable * parent_
The parent socket code table.
Definition: PortCode.hh:99
PortCode::OSKEY_ENCODING
static const std::string OSKEY_ENCODING
ObjectState attribute key for the encoding.
Definition: PortCode.hh:71
NotAvailable
Definition: Exception.hh:728
PortCode::unitName
std::string unitName() const
Definition: PortCode.cc:140
PortCode::extraBits_
unsigned int extraBits_
The number of extra bits in the encoding.
Definition: PortCode.hh:93
PortCode::extraBits
unsigned int extraBits() const
Definition: PortCode.cc:177
PortCode::indexWidth_
int indexWidth_
The width of the register index in the port code.
Definition: PortCode.hh:95
PortCode::OSKEY_MAX_INDEX
static const std::string OSKEY_MAX_INDEX
ObjectState attribute key for the max-index attribute.
Definition: PortCode.hh:77
PortCode::indexWidth
int indexWidth() const
Definition: PortCode.cc:215
PortCode::width
int width() const
Definition: PortCode.cc:188
PortCode::maxRegIndex_
unsigned maxRegIndex_
In case this is set to non-zero, the whole width of the index field is not used because the number of...
Definition: PortCode.hh:104
__func__
#define __func__
Definition: Application.hh:67
Exception
Definition: Exception.hh:54
PortCode::unitName_
std::string unitName_
Name of the unit.
Definition: PortCode.hh:89
PortCode::OSKEY_INDEX_WIDTH
static const std::string OSKEY_INDEX_WIDTH
ObjectState attribute key for the widht of register index.
Definition: PortCode.hh:75
MathTools::bitLength
static unsigned int bitLength(long unsigned int number)
PortCode::encoding_
unsigned int encoding_
The encoding.
Definition: PortCode.hh:91
ObjectState::intAttribute
int intAttribute(const std::string &name) const
Definition: ObjectState.cc:276
PortCode::hasEncoding
bool hasEncoding() const
Definition: PortCode.cc:151
PortCode::parent
SocketCodeTable * parent() const
Definition: PortCode.cc:226
PortCode::OSNAME_PORT_CODE
static const std::string OSNAME_PORT_CODE
ObjectState name for PortCode.
Definition: PortCode.hh:67
PortCode::encoding
unsigned int encoding() const
Definition: PortCode.cc:164
PortCode::hasEncoding_
bool hasEncoding_
Tells whether the port code has an encoding.
Definition: PortCode.hh:97
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100