9#ifndef LLVM_SUPPORT_BINARYSTREAMREADER_H
10#define LLVM_SUPPORT_BINARYSTREAMREADER_H
69 static_assert(std::is_integral_v<T>,
70 "Cannot call readInteger with non-integral value!");
76 Dest = llvm::support::endian::read<T, llvm::support::unaligned>(
83 static_assert(std::is_enum<T>::value,
84 "Cannot call readEnum with non-enum value!");
85 std::underlying_type_t<T>
N;
88 Dest =
static_cast<T>(
N);
166 Dest =
reinterpret_cast<const T *
>(Buffer.
data());
179 template <
typename T>
182 if (NumElements == 0) {
187 if (NumElements > UINT32_MAX /
sizeof(
T))
188 return make_error<BinaryStreamError>(
191 if (
auto EC =
readBytes(Bytes, NumElements *
sizeof(
T)))
195 "Reading at invalid alignment!");
197 Array =
ArrayRef<T>(
reinterpret_cast<const T *
>(Bytes.
data()), NumElements);
209 template <
typename T,
typename U>
215 Array.setUnderlyingStream(S, Skew);
227 template <
typename T>
234 if (NumItems > UINT32_MAX /
sizeof(
T))
235 return make_error<BinaryStreamError>(
262 uint8_t
peek()
const;
266 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::support::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.