|
CIRCT 23.0.0git
|
A lightweight, non-owning bit vector view backed by a byte array span. More...
#include <Values.h>


Classes | |
| class | bit_iterator |
| Forward iterator for iterating over bits from LSB (index 0) to MSB. More... | |
Public Types | |
| using | byte = uint8_t |
Public Member Functions | |
| BitVector (std::span< const byte > bytes, std::optional< size_t > width=std::nullopt, uint8_t bitIndex=0) | |
| Construct from an existing span. | |
| BitVector ()=default | |
| BitVector (const BitVector &other) | |
| BitVector & | operator= (const BitVector &other) |
| size_t | width () const |
| size_t | size () const |
| bool | getBit (size_t i) const |
| Return the i-th bit (0 = LSB) as boolean. | |
| std::span< const byte > | getSpan () const |
| Return a handle to the underlying span. | |
| BitVector | operator>> (size_t n) const |
| Logical right shift that drops the least-significant n bits by advancing the byte/bit index and reducing width. | |
| BitVector & | operator>>= (size_t n) |
| BitVector | slice (size_t offset, size_t sliceWidth) const |
| Create a new immutable view of a contiguous bit slice [offset, offset+sliceWidth). | |
| BitVector | lsb (size_t n) const |
| Return a view of the N least-significant bits. | |
| BitVector | msb (size_t n) const |
| Return a view of the N most-significant bits. | |
| std::string | toString (unsigned base=16) const |
| bool | operator== (const BitVector &rhs) const |
| bool | operator!= (const BitVector &rhs) const |
| bit_iterator | begin () const |
| Return an iterator to the first bit (LSB). | |
| bit_iterator | end () const |
| Return an iterator past the last bit. | |
Protected Member Functions | |
| void | checkHighBytesEqual (unsigned lowExclusive, uint8_t expectedByte, const char *fmt, unsigned target) const |
Protected Attributes | |
| std::span< const byte > | data {} |
| size_t | bitWidth = 0 |
| uint8_t | bitIndex = 0 |
Friends | |
| MutableBitVector | operator& (const BitVector &a, const BitVector &b) |
| Bitwise AND: creates a new MutableBitVector with the result. | |
| MutableBitVector | operator| (const BitVector &a, const BitVector &b) |
| Bitwise OR: creates a new MutableBitVector with the result. | |
| MutableBitVector | operator^ (const BitVector &a, const BitVector &b) |
| Bitwise XOR: creates a new MutableBitVector with the result. | |
A lightweight, non-owning bit vector view backed by a byte array span.
BitVector is immutable wrt. modifying the underlying bits, and provides read-only access to bits. It supports bit-level access and returns new views for operations.
Lifetime: BitVector, IntView, and UIntView (defined just below) are non-owning views, in the same family as std::span / std::string_view. They store only a span pointer + width + bitIndex and do not extend the lifetime of the underlying buffer. A view returned from an accessor of a temporary dangles once the temporary is destroyed; bind the parent to a named local, or construct an owning Int / UInt / MutableBitVector from the view if the value needs to outlive its source.
| using esi::BitVector::byte = uint8_t |
| BitVector::BitVector | ( | std::span< const byte > | bytes, |
| std::optional< size_t > | width = std::nullopt, |
||
| uint8_t | bitIndex = 0 |
||
| ) |
|
default |
| BitVector::BitVector | ( | const BitVector & | other | ) |
Definition at line 29 of file Values.cpp.
|
inline |
|
protected |
Definition at line 437 of file Values.cpp.
References bitIndex, bitWidth, and data.
Referenced by esi::IntView::toI64(), esi::IntView::toInt(), esi::UIntView::toUI64(), and esi::UIntView::toUInt().
|
inline |
| bool BitVector::getBit | ( | size_t | i | ) | const |
Return the i-th bit (0 = LSB) as boolean.
Definition at line 41 of file Values.cpp.
References bitIndex, bitWidth, and data.
Referenced by esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::operator&=(), esi::BitVector::bit_iterator::operator*(), esi::MutableBitVector::operator<<=(), esi::MutableBitVector::operator<<=(), esi::MutableBitVector::operator^=(), esi::MutableBitVector::operator|=(), esi::MutableBitVector::operator~(), toDecimalString(), esi::IntView::toI64(), esi::IntView::toInt(), toString(), and esi::UIntView::toUI64().
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 32 of file Values.cpp.
| bool BitVector::operator== | ( | const BitVector & | rhs | ) | const |
Definition at line 420 of file Values.cpp.
References bitWidth.
| BitVector BitVector::operator>> | ( | size_t | n | ) | const |
Logical right shift that drops the least-significant n bits by advancing the byte/bit index and reducing width.
Returns a new immutable view. Does not modify the underlying storage contents.
Definition at line 50 of file Values.cpp.
| BitVector & BitVector::operator>>= | ( | size_t | n | ) |
Definition at line 78 of file Values.cpp.
|
inline |
Definition at line 64 of file Values.h.
References width().
Referenced by esiaccel.types.ArrayType::deserialize(), and esiaccel.types.ArrayType::is_valid().
| BitVector BitVector::slice | ( | size_t | offset, |
| size_t | sliceWidth | ||
| ) | const |
Create a new immutable view of a contiguous bit slice [offset, offset+sliceWidth).
The returned BitVector is a view (not an owning copy) into the same underlying span. Throws if the requested slice exceeds the current width.
Definition at line 83 of file Values.cpp.
| std::string BitVector::toString | ( | unsigned | base = 16 | ) | const |
Definition at line 362 of file Values.cpp.
References bitWidth, getBit(), toDecimalString(), and toPowerOfTwoString().
Referenced by esi::operator<<().
|
inline |
Definition at line 63 of file Values.h.
References bitWidth.
Referenced by esi::Int::Int(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::Int::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::operator<<=(), esi::SIntType::serialize(), esi::UIntType::serialize(), esi::StructType::serialize(), esi::ArrayType::serialize(), esi::UnionType::serialize(), size(), toDecimalString(), esi::IntView::toInt(), esi::UIntView::toUInt(), and esi::UInt::UInt().
|
friend |
Bitwise AND: creates a new MutableBitVector with the result.
|
friend |
Bitwise XOR: creates a new MutableBitVector with the result.
|
friend |
Bitwise OR: creates a new MutableBitVector with the result.
|
protected |
Definition at line 189 of file Values.h.
Referenced by BitVector(), checkHighBytesEqual(), getBit(), getSpan(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::operator<<=(), esi::MutableBitVector::operator<<=(), operator=(), esi::MutableBitVector::operator=(), esi::MutableBitVector::operator>>=(), and slice().
|
protected |
Definition at line 188 of file Values.h.
Referenced by BitVector(), checkHighBytesEqual(), end(), getBit(), msb(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::operator&=(), esi::BitVector::bit_iterator::operator*(), esi::MutableBitVector::operator<<=(), esi::MutableBitVector::operator<<=(), operator=(), esi::MutableBitVector::operator=(), operator==(), esi::BitVector::bit_iterator::operator==(), operator>>(), esi::MutableBitVector::operator>>=(), esi::MutableBitVector::operator^=(), esi::MutableBitVector::operator|=(), esi::MutableBitVector::operator~(), esi::MutableBitVector::setBit(), slice(), esi::IntView::toI64(), toString(), esi::UIntView::toUI64(), and width().
|
protected |
Definition at line 187 of file Values.h.
Referenced by BitVector(), checkHighBytesEqual(), getBit(), getSpan(), esi::MutableBitVector::getSpan(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::operator<<=(), esi::MutableBitVector::operator<<=(), operator=(), esi::MutableBitVector::operator=(), esi::MutableBitVector::operator>>=(), and slice().