OpenASIP  2.0
Public Member Functions | List of all members
BitVector Class Reference

#include <BitVector.hh>

Inheritance diagram for BitVector:
Inheritance graph
Collaboration diagram for BitVector:
Collaboration graph

Public Member Functions

 BitVector ()
 
 BitVector (const BitVector &vector, unsigned int firstIndex, unsigned int lastIndex)
 
virtual ~BitVector ()
 
void pushBack (long long unsigned int integer, int size)
 
void pushBack (const BitVector &bits)
 
void pushBack (bool bit)
 
std::string toString () const
 

Detailed Description

BitVector is a specialization of STL's bit vector. It provides some handy helper methods.

Definition at line 44 of file BitVector.hh.

Constructor & Destructor Documentation

◆ BitVector() [1/2]

BitVector::BitVector ( )

The constructor.

Definition at line 44 of file BitVector.cc.

44  {
45 }

◆ BitVector() [2/2]

BitVector::BitVector ( const BitVector vector,
unsigned int  firstIndex,
unsigned int  lastIndex 
)

The constructor.

Creates a bit vector that is a sub vector of the given vector.

Parameters
vectorThe bit vector.
firstIndexThe index of the given vector that is to be the first element in the created vector.
lastIndexThe index of the given vector that is to be that last element in the created vector.
Exceptions
OutOfRangeIf the given indexes are too big or too small.

Definition at line 60 of file BitVector.cc.

61  {
62  if (lastIndex < firstIndex || lastIndex >= vector.size()) {
63  const string procName = "BitVector::BitVector";
64  throw OutOfRange(__FILE__, __LINE__, procName);
65  }
66 
67  BitVector::const_iterator firstIter = vector.begin();
68  firstIter += firstIndex;
69  BitVector::const_iterator lastIter = vector.begin();
70  lastIter += lastIndex + 1;
71  insert(begin(), firstIter, lastIter);
72  assert(size() == lastIndex - firstIndex + 1);
73 }

References assert.

◆ ~BitVector()

BitVector::~BitVector ( )
virtual

The destructor.

Definition at line 78 of file BitVector.cc.

78  {
79 }

Member Function Documentation

◆ pushBack() [1/3]

void BitVector::pushBack ( bool  bit)

Pushes back the given bit.

Parameters
bitThe bit to be added.

Definition at line 120 of file BitVector.cc.

120  {
121  push_back(bit);
122 }

◆ pushBack() [2/3]

void BitVector::pushBack ( const BitVector bits)

Pushes back the given bit vector.

Parameters
bitsThe bit vector.

Definition at line 107 of file BitVector.cc.

107  {
108  reserve(size() + bits.size());
109  for (std::vector<bool>::const_iterator iter = bits.begin();
110  iter != bits.end(); iter++) {
111  push_back(*iter);
112  }
113 }

◆ pushBack() [3/3]

void BitVector::pushBack ( long long unsigned int  integer,
int  size 
)

Pushes back the given number and increases the size of the vector by the given amount.

For example, if number 6 (110) is added with size 5, bits 00110 are concatenated to the vector. If size 2 is given, then bits 10 are concatenated to the vector.

Parameters
integerThe number to be added.
sizeThe number of bits to be added.

Definition at line 94 of file BitVector.cc.

94  {
95  for (int i = size - 1; i >= 0; i--) {
96  push_back(MathTools::bit(integer, i));
97  }
98 }

References MathTools::bit().

Referenced by CodeCompressorPlugin::addBitsForDstRegisterField(), CodeCompressorPlugin::addBitsForGuardField(), CodeCompressorPlugin::addBitsForICField(), CodeCompressorPlugin::addBitsForImmediateSlot(), MoveSlotDictionary::addInstructions(), CodeCompressorPlugin::encodeFUTerminal(), CodeCompressorPlugin::encodeIUTerminal(), CodeCompressorPlugin::encodeNOP(), CodeCompressorPlugin::encodeRFTerminal(), CodeCompressorPlugin::encodeSlotField(), ProGe::RV32MicroCodeGenerator::initializeOperations(), InstructionBitVector::pushBack(), CodeCompressorPlugin::socketCodeBits(), and ProgramImageGenerator::writeDataSection().

Here is the call graph for this function:

◆ toString()

std::string BitVector::toString ( ) const

Converts BitVector to std::string format

Definition at line 130 of file BitVector.cc.

130  {
131  std::string bits;
132  for (unsigned int i = 0; i < this->size(); i++) {
133  bits.append(std::to_string(this->at(i)));
134  }
135  return bits;
136 }

Referenced by ProGe::RV32MicroCodeGenerator::generateNOP(), and ProGe::RV32MicroCodeGenerator::initializeOperations().


The documentation for this class was generated from the following files:
OutOfRange
Definition: Exception.hh:320
assert
#define assert(condition)
Definition: Application.hh:86
MathTools::bit
static bool bit(ULongWord integer, unsigned int index)