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

Non-owning view of a signed bit vector with toI64() and implicit conversions to signed scalar types. More...

#include <Values.h>

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

Public Member Functions

 IntView ()=default
 
 IntView (const BitVector &v)
 Adopt an existing view as signed.
 
int64_t toI64 () const
 Convert to an int64_t, sign-extending from the high bit and throwing if the value does not fit.
 
 operator int64_t () const
 
 operator int32_t () const
 
 operator int16_t () const
 
 operator int8_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 >
toInt () 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 a signed bit vector with toI64() and implicit conversions to signed scalar types.

See the lifetime note on BitVector.

Definition at line 240 of file Values.h.

Constructor & Destructor Documentation

◆ IntView() [1/2]

esi::IntView::IntView ( )
default

◆ IntView() [2/2]

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

Adopt an existing view as signed.

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

Definition at line 246 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 int16_t()

esi::IntView::operator int16_t ( ) const
inline

Definition at line 253 of file Values.h.

◆ operator int32_t()

esi::IntView::operator int32_t ( ) const
inline

Definition at line 252 of file Values.h.

◆ operator int64_t()

esi::IntView::operator int64_t ( ) const
inline

Definition at line 251 of file Values.h.

References toI64().

◆ operator int8_t()

esi::IntView::operator int8_t ( ) const
inline

Definition at line 254 of file Values.h.

◆ toI64()

int64_t IntView::toI64 ( ) const

Convert to an int64_t, sign-extending from the high bit and throwing if the value does not fit.

Definition at line 538 of file Values.cpp.

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

Referenced by operator int64_t(), and toInt().

◆ toInt()

template<typename T >
T esi::IntView::toInt ( ) const
inlineprivate

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