31 #ifndef __BASE_BITUNION_HH__ 32 #define __BASE_BITUNION_HH__ 36 #include <type_traits> 56 static_assert(std::is_empty<Base>::value,
57 "Bitfield base class must be empty.");
66 template<
typename C,
typename Type1,
typename Type2>
67 struct T<void (C::*)(Type1 &, Type2)>
86 Type
getter(
const Storage &storage)
const =
delete;
87 void setter(Storage &storage, Type
val) =
delete;
96 return Base::getter(__storage);
102 Base::setter(__storage, val);
109 return *
this = (
Type)other;
125 operator Type ()
const {
return Impl::operator
Type(); }
130 return Impl::operator=(other);
146 operator Type ()
const {
return Impl::operator
Type(); }
150 template <
class Base>
165 return Impl::operator=(other);
173 template<
class Storage,
int first,
int last>
176 static_assert(first >= last,
177 "Bitfield ranges must be specified as <msb, lsb>");
183 return bits(storage, first, last);
193 template<
class Storage,
int first,
int last>
196 static_assert(first >= last,
197 "Bitfield ranges must be specified as <msb, lsb>");
203 return sext<first - last + 1>(
bits(storage, first, last));
216 template<
class Storage>
221 template<
int first,
int last=first>
223 template<
int first,
int last=first>
226 template<
int first,
int last=first>
230 template<
int first,
int last=first>
233 template<
int first,
int last=first>
236 template<
int first,
int last=first>
247 template <
class Base>
250 static_assert(
sizeof(Base) ==
sizeof(
typename Base::__StorageType),
251 "BitUnion larger than its storage type.");
256 Base::__storage =
val;
263 operator const typename Base::__StorageType ()
const 265 return Base::__storage;
268 typename Base::__StorageType
271 Base::__storage =
val;
275 typename Base::__StorageType
278 Base::__storage = other;
279 return Base::__storage;
285 return Base::__storage < base.__storage;
291 return Base::__storage == base.__storage;
311 #define __BitUnion(type, name) \ 312 class BitfieldUnderlyingClasses##name : \ 313 public BitfieldBackend::BitfieldTypes<type> \ 316 typedef type __StorageType; \ 317 friend BitfieldBackend::BitUnionBaseType< \ 318 BitfieldBackend::BitUnionOperators< \ 319 BitfieldUnderlyingClasses##name> >; \ 320 friend BitfieldBackend::BitUnionBaseType< \ 321 BitfieldUnderlyingClasses##name>; \ 330 #define EndBitUnion(name) \ 333 typedef BitfieldBackend::BitUnionOperators< \ 334 BitfieldUnderlyingClasses##name> name; 341 #define __SubBitUnion(name, fieldType, ...) \ 346 fieldType<__VA_ARGS__> __storage; 353 #define EndSubBitUnion(name) \ 355 inline operator __StorageType () const \ 356 { return __storage; } \ 358 inline __StorageType operator = (const __StorageType & _storage) \ 359 { return __storage = _storage;} \ 364 #define SubBitUnion(name, first, last) \ 365 __SubBitUnion(name, Bitfield, first, last) 369 #define SignedSubBitUnion(name, first, last) \ 370 __SubBitUnion(name, SignedBitfield, first, last) 373 #define BitUnion(type, name) __BitUnion(type, name) 376 #define BitUnion64(name) __BitUnion(uint64_t, name) 377 #define BitUnion32(name) __BitUnion(uint32_t, name) 378 #define BitUnion16(name) __BitUnion(uint16_t, name) 379 #define BitUnion8(name) __BitUnion(uint8_t, name) 397 template <
typename T>
415 template <
typename T>
422 template <
typename T>
428 return hash<BitUnionBaseType<T> >::operator()(
val);
438 static inline std::ostream &
449 inline std::ostream &
457 inline std::ostream &
460 os << (
unsigned int)t;
467 template <
typename T>
469 operator << (std::ostream &os, const BitUnionType<T> &bu)
475 #endif // __BASE_BITUNION_HH__ Type operator=(const Type val)
T< decltype(&Wrapper::setter)>::Storage Storage
static std::ostream & bitfieldBackendPrinter(std::ostream &os, const T &t)
uint64_t getter(const Storage &storage) const
Type operator=(const Type val)
void setter(Storage &storage, int64_t val)
std::ostream & bitfieldBackendPrinter(std::ostream &os, const unsigned char &t)
BitUnionType< T >::__StorageType Type
Type operator=(BitfieldType< Base > const &other)
Overload hash function for BasicBlockRange type.
int64_t getter(const Storage &storage) const
Base::__StorageType operator=(typename Base::__StorageType const &val)
void replaceBits(T &val, int first, int last, B bit_val)
A convenience function to replace bits first to last of val with bit_val in place.
T< decltype(&Wrapper::setter)>::Type Type
Type operator=(const Type val)
bool operator==(Base const &base) const
Type operator=(BitfieldWOType< Base > const &other)
Type getter(const Storage &storage) const =delete
typename BitfieldBackend::BitUnionBaseType< T >::Type BitUnionBaseType
BitUnionType< T >::__StorageType Type
BitfieldTypeImpl()=default
BitUnionOperators(typename Base::__StorageType const &val)
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it...
bool operator<(const Time &l, const Time &r)
void setter(Storage &storage, uint64_t val)
void setter(Storage &storage, Type val)=delete
uint64_t sext(uint64_t val)
Sign-extend an N-bit value to 64 bits.
Type operator=(BitfieldTypeImpl< Base > const &other)
Base::__StorageType operator=(BitUnionOperators const &other)
TypeDeducer::Storage Storage