CIRCT 23.0.0git
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
esi::UIntView Class Reference

Non-owning view of an unsigned bit vector with toUI64() and implicit conversions to unsigned scalar types. More...

#include <Values.h>

Inheritance diagram for esi::UIntView:
Inheritance graph
[legend]
Collaboration diagram for esi::UIntView:
Collaboration graph
[legend]

Public Member Functions

 UIntView ()=default
 
 UIntView (const BitVector &v)
 Adopt an existing view as unsigned.
 
uint64_t toUI64 () const
 Convert to a uint64_t, throwing if the value does not fit.
 
 operator uint64_t () const
 
 operator uint32_t () const
 
 operator uint16_t () const
 
 operator uint8_t () const
 
 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)
 
- Public Member Functions inherited from esi::BitVector
 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)
 
BitVectoroperator= (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 bytegetSpan () 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.
 
BitVectoroperator>>= (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.
 

Private Member Functions

template<typename T >
toUInt () const
 

Additional Inherited Members

- Public Types inherited from esi::BitVector
using byte = uint8_t
 
- Protected Member Functions inherited from esi::BitVector
void checkHighBytesEqual (unsigned lowExclusive, uint8_t expectedByte, const char *fmt, unsigned target) const
 
- Protected Attributes inherited from esi::BitVector
std::span< const bytedata {}
 
size_t bitWidth = 0
 
uint8_t bitIndex = 0
 

Detailed Description

Non-owning view of an unsigned bit vector with toUI64() and implicit conversions to unsigned scalar types.

Adds only static-type tagging and conversion methods on top of BitVector. See the lifetime note on BitVector.

Definition at line 205 of file Values.h.

Constructor & Destructor Documentation

◆ UIntView() [1/2]

esi::UIntView::UIntView ( )
default

◆ UIntView() [2/2]

esi::UIntView::UIntView ( const BitVector v)
inline

Adopt an existing view as unsigned.

Cheap (no copy of bytes); the resulting UIntView aliases the same buffer.

Definition at line 211 of file Values.h.

Member Function Documentation

◆ BitVector() [1/3]

esi::BitVector::BitVector ( )
default

◆ BitVector() [2/3]

BitVector::BitVector ( const BitVector other)

Definition at line 60 of file Values.cpp.

◆ BitVector() [3/3]

BitVector::BitVector ( std::span< const byte bytes,
std::optional< size_t >  width = std::nullopt,
uint8_t  bitIndex = 0 
)

Construct from an existing span.

Width defaults to the number of bits in the span (size * 8). The BitVector does not take ownership.

Definition at line 57 of file Values.cpp.

◆ operator uint16_t()

esi::UIntView::operator uint16_t ( ) const
inline

Definition at line 217 of file Values.h.

◆ operator uint32_t()

esi::UIntView::operator uint32_t ( ) const
inline

Definition at line 216 of file Values.h.

◆ operator uint64_t()

esi::UIntView::operator uint64_t ( ) const
inline

Definition at line 215 of file Values.h.

References toUI64().

◆ operator uint8_t()

esi::UIntView::operator uint8_t ( ) const
inline

Definition at line 218 of file Values.h.

◆ toUI64()

uint64_t UIntView::toUI64 ( ) const

Convert to a uint64_t, throwing if the value does not fit.

Definition at line 566 of file Values.cpp.

References esi::BitVector::bitWidth, esi::BitVector::checkHighBytesEqual(), and esi::BitVector::getBit().

Referenced by operator uint64_t(), and toUInt().

◆ toUInt()

template<typename T >
T esi::UIntView::toUInt ( ) const
inlineprivate

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