9 #ifndef LLVM_SUPPORT_BINARYSTREAMREADER_H 10 #define LLVM_SUPPORT_BINARYSTREAMREADER_H 22 #include <type_traits> 41 : Stream(Other.Stream), Offset(Other.Offset) {}
44 Stream = Other.Stream;
45 Offset = Other.Offset;
76 static_assert(std::is_integral<T>::value,
77 "Cannot call readInteger with non-integral value!");
83 Dest = llvm::support::endian::read<T, llvm::support::unaligned>(
90 static_assert(std::is_enum<T>::value,
91 "Cannot call readEnum with non-enum value!");
92 typename std::underlying_type<T>::type
N;
95 Dest =
static_cast<T>(
N);
173 Dest =
reinterpret_cast<const T *
>(Buffer.
data());
186 template <
typename T>
189 if (NumElements == 0) {
194 if (NumElements > UINT32_MAX /
sizeof(
T))
195 return make_error<BinaryStreamError>(
198 if (
auto EC =
readBytes(Bytes, NumElements *
sizeof(
T)))
202 "Reading at invalid alignment!");
204 Array =
ArrayRef<T>(
reinterpret_cast<const T *
>(Bytes.
data()), NumElements);
216 template <
typename T,
typename U>
234 template <
typename T>
241 if (NumItems > UINT32_MAX /
sizeof(
T))
242 return make_error<BinaryStreamError>(
269 uint8_t
peek()
const;
273 std::pair<BinaryStreamReader, BinaryStreamReader>
282 #endif // LLVM_SUPPORT_BINARYSTREAMREADER_H virtual ~BinaryStreamReader()
Error padToAlignment(uint32_t Align)
This class represents lattice values for constants.
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
Error readWideString(ArrayRef< UTF16 > &Dest)
Similar to readCString, however read a null-terminated UTF16 string instead.
Error readObject(const T *&Dest)
Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the resul...
void setUnderlyingStream(BinaryStreamRef NewStream, uint32_t NewSkew=0)
uint8_t peek() const
Examine the next byte of the underlying stream without advancing the stream's offset.
FixedStreamArray is similar to VarStreamArray, except with each record having a fixed-length.
BinaryStreamReader & operator=(const BinaryStreamReader &Other)
Error readSLEB128(int64_t &Dest)
Read a signed LEB128 encoded value.
Error readULEB128(uint64_t &Dest)
Read an unsigned LEB128 encoded value.
The access may reference the value stored in memory.
Error readCString(StringRef &Dest)
Read a null terminated string from Dest.
uint32_t getOffset() const
virtual uint32_t getLength()=0
Return the number of bytes of data in this stream.
std::pair< BinaryStreamReader, BinaryStreamReader > split(uint32_t Offset) const
Error readFixedString(StringRef &Dest, uint32_t Length)
Read a Length byte string into Dest.
BinaryStreamReader()=default
virtual llvm::support::endianness getEndian() const =0
Error readArray(FixedStreamArray< T > &Array, uint32_t NumItems)
Read a FixedStreamArray of NumItems elements and store the result into Array.
An interface for accessing data in a stream-like format, but which discourages copying.
Error readArray(VarStreamArray< T, U > &Array, uint32_t Size, uint32_t Skew=0)
Read a VarStreamArray of size Size bytes and store the result into Array.
BinaryStreamReader(const BinaryStreamReader &Other)
bool isAddrAligned(Align Lhs, const void *Addr)
Checks that Addr is a multiple of the alignment.
This struct is a compact representation of a valid (non-zero power of two) alignment.
void setOffset(uint32_t Off)
static ErrorSuccess success()
Create a success value.
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Error readSubstream(BinarySubstreamRef &Ref, uint32_t Length)
Read Length bytes from the underlying stream into Ref.
Error readBytes(ArrayRef< uint8_t > &Buffer, uint32_t Size)
Read Size bytes from the underlying stream at the current offset and and set Buffer to the resulting ...
uint32_t getLength() const
Error readStreamRef(BinaryStreamRef &Ref)
Read the entire remainder of the underlying stream into Ref.
Error skip(uint32_t Amount)
Advance the stream's offset by Amount bytes.
uint32_t bytesRemaining() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Provides read only access to a subclass of BinaryStream.
StringRef - Represent a constant reference to a string, i.e.
Error readEnum(T &Dest)
Similar to readInteger.
Error readLongestContiguousChunk(ArrayRef< uint8_t > &Buffer)
Read as much as possible from the underlying string at the current offset without invoking a copy...
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Get a reference to a NumElements element array of objects of type T from the underlying stream as if ...