9#ifndef LLVM_SUPPORT_BINARYSTREAMREADER_H
10#define LLVM_SUPPORT_BINARYSTREAMREADER_H
68 static_assert(std::is_integral_v<T>,
69 "Cannot call readInteger with non-integral value!");
75 Dest = llvm::support::endian::read<T>(Bytes.
data(), Stream.
getEndian());
81 static_assert(std::is_enum<T>::value,
82 "Cannot call readEnum with non-enum value!");
83 std::underlying_type_t<T>
N;
86 Dest =
static_cast<T>(
N);
164 Dest =
reinterpret_cast<const T *
>(Buffer.
data());
177 template <
typename T>
180 if (NumElements == 0) {
185 if (NumElements > UINT32_MAX /
sizeof(
T))
186 return make_error<BinaryStreamError>(
189 if (
auto EC =
readBytes(Bytes, NumElements *
sizeof(
T)))
193 "Reading at invalid alignment!");
195 Array =
ArrayRef<T>(
reinterpret_cast<const T *
>(Bytes.
data()), NumElements);
207 template <
typename T,
typename U>
213 Array.setUnderlyingStream(S, Skew);
225 template <
typename T>
232 if (NumItems > UINT32_MAX /
sizeof(
T))
233 return make_error<BinaryStreamError>(
260 uint8_t
peek()
const;
264 std::pair<BinaryStreamReader, BinaryStreamReader>
Lightweight arrays that are backed by an arbitrary BinaryStream.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Provides read only access to a subclass of BinaryStream.
Error readStreamRef(BinaryStreamRef &Ref)
Read the entire remainder of the underlying stream into Ref.
BinaryStreamReader & operator=(const BinaryStreamReader &Other)=default
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...
Error readCString(StringRef &Dest)
Read a null terminated string from Dest.
Error readArray(FixedStreamArray< T > &Array, uint32_t NumItems)
Read a FixedStreamArray of NumItems elements and store the result into Array.
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 ...
uint8_t peek() const
Examine the next byte of the underlying stream without advancing the stream's offset.
Error readWideString(ArrayRef< UTF16 > &Dest)
Similar to readCString, however read a null-terminated UTF16 string instead.
uint64_t getLength() const
Error readSubstream(BinarySubstreamRef &Ref, uint32_t Length)
Read Length bytes from the underlying stream into Ref.
Error readEnum(T &Dest)
Similar to readInteger.
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
BinaryStreamReader()=default
uint64_t bytesRemaining() const
uint64_t getOffset() const
Error readSLEB128(int64_t &Dest)
Read a signed LEB128 encoded value.
Error readLongestContiguousChunk(ArrayRef< uint8_t > &Buffer)
Read as much as possible from the underlying string at the current offset without invoking a copy,...
Error padToAlignment(uint32_t Align)
Error readFixedString(StringRef &Dest, uint32_t Length)
Read a Length byte string into Dest.
std::pair< BinaryStreamReader, BinaryStreamReader > split(uint64_t Offset) const
void setOffset(uint64_t Off)
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 ...
Error readULEB128(uint64_t &Dest)
Read an unsigned LEB128 encoded value.
Error skip(uint64_t Amount)
Advance the stream's offset by Amount bytes.
BinaryStreamReader(const BinaryStreamReader &Other)=default
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.
virtual ~BinaryStreamReader()=default
llvm::endianness getEndian() const
uint64_t getLength() const
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
An interface for accessing data in a stream-like format, but which discourages copying.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
FixedStreamArray is similar to VarStreamArray, except with each record having a fixed-length.
StringRef - Represent a constant reference to a string, i.e.
This is an optimization pass for GlobalISel generic memory operations.
@ Ref
The access may reference the value stored in memory.
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.