![]() |
P4C
The P4 Compiler
|
#include <bitrange.h>
Public Types | |
using | FromTo = BitRange::FromTo |
using | MinToMax = BitRange::MinToMax |
using | StartLen = BitRange::StartLen |
using | ZeroToMax = BitRange::ZeroToMax |
Public Member Functions | |
ClosedRange (const HalfOpenRange< Unit, Order > &r) | |
ClosedRange (FromTo &&fromTo) | |
constexpr | ClosedRange (int lo, int hi) |
ClosedRange (MinToMax &&) | |
ClosedRange (StartLen &&startLen) | |
ClosedRange (std::pair< int, int > range) | |
ClosedRange (ZeroToMax &&) | |
bool | contains (ClosedRange other) const |
bool | contains (int index) const |
cstring | formatAsSlice (int spaceSize) const |
int | hiByte () const |
HalfOpenRange< Unit, Order > | intersectWith (ClosedRange a) const |
HalfOpenRange< Unit, Order > | intersectWith (int l, int h) const |
bool | isHiAligned () const |
bool | isLoAligned () const |
int | loByte () const |
int | nextByte () const |
bool | operator!= (ClosedRange other) const |
HalfOpenRange< Unit, Order > | operator& (ClosedRange a) const |
HalfOpenRange< Unit, Order > | operator&= (ClosedRange a) |
bool | operator< (const ClosedRange &other) const |
bool | operator== (ClosedRange other) const |
ClosedRange | operator| (ClosedRange a) const |
ClosedRange | operator|= (ClosedRange a) |
bool | overlaps (ClosedRange a) const |
bool | overlaps (int l, int h) const |
ClosedRange< RangeUnit::Bit, Order > | resizedToBits (int size) const |
ClosedRange | resizedToBytes (int size) const |
ClosedRange< RangeUnit::Bit, Order > | shiftedByBits (int offset) const |
ClosedRange | shiftedByBytes (int offset) const |
ssize_t | size () const |
void | toJSON (JSONGenerator &json) const |
JSON serialization/deserialization. | |
template<Endian DestOrder> | |
ClosedRange< Unit, DestOrder > | toOrder (int spaceSize) const |
template<RangeUnit DestUnit> | |
ClosedRange< DestUnit, Order > | toUnit () const |
ClosedRange | unionWith (ClosedRange a) const |
ClosedRange | unionWith (int l, int h) const |
Static Public Member Functions | |
static ClosedRange | fromJSON (JSONLoader &json) |
Public Attributes | |
int | hi |
int | lo |
Static Public Attributes | |
static constexpr Endian | order = Order |
static constexpr RangeUnit | unit = Unit |
Friends | |
size_t | hash_value (const ClosedRange &r) |
A closed range of bits or bytes - [lo, hi]
specified in terms of a specific endian order. Closed ranges include both lo
and hi
, so ClosedRange(3, 5)
contains 3
, 4
, and 5
.
Use a closed range when you want to forbid the possibility of an empty range. Using a closed range may also make certain algorithms easier to express.
XXX: ClosedRange's interface is very similar to HalfOpenRange, but they have almost totally different implementations, and the limitations of C++ templates make sharing the things they do have in common challenging. Most of the benefit would have come from sharing documentation; as a compromise, most of the methods in ClosedRange just reference HalfOpenRange's documentation.
XXX: Currently, for backwards compatibility, it's possible to construct ranges where lo
is greater than or equal to hi
. We should enforce that ranges are consistent; we'll add the necessary checks after the existing code has been audited.
XXX: We should also add checks to avoid integer overflow.
|
inline |
|
inline |
|
inline |
Formats this range as P4 syntax by converting to a little-endian range of bits, and formatting the result as "[hi:lo]".
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
int P4::ClosedRange< Unit, Order >::hi |
The highest numbered index in the range. For Endian::Network, this is the least significant bit or byte; for Endian::Little, it's the most significant. Because this is a closed range, the range element this index identifies is included in the range.
int P4::ClosedRange< Unit, Order >::lo |
The lowest numbered index in the range. For Endian::Network, this is the most significant bit or byte; for Endian::Little, it's the least significant.