10 #ifndef LLVM_SUPPORT_BINARYSTREAMREADER_H 11 #define LLVM_SUPPORT_BINARYSTREAMREADER_H 23 #include <type_traits> 42 : Stream(Other.Stream), Offset(Other.Offset) {}
45 Stream = Other.Stream;
46 Offset = Other.Offset;
77 static_assert(std::is_integral<T>::value,
78 "Cannot call readInteger with non-integral value!");
84 Dest = llvm::support::endian::read<T, llvm::support::unaligned>(
91 static_assert(std::is_enum<T>::value,
92 "Cannot call readEnum with non-enum value!");
93 typename std::underlying_type<T>::type
N;
96 Dest =
static_cast<T>(
N);
162 Dest =
reinterpret_cast<const T *
>(Buffer.
data());
175 template <
typename T>
178 if (NumElements == 0) {
183 if (NumElements > UINT32_MAX /
sizeof(
T))
184 return make_error<BinaryStreamError>(
187 if (
auto EC =
readBytes(Bytes, NumElements *
sizeof(
T)))
191 "Reading at invalid alignment!");
193 Array =
ArrayRef<T>(
reinterpret_cast<const T *
>(Bytes.
data()), NumElements);
205 template <
typename T,
typename U>
223 template <
typename T>
230 if (NumItems > UINT32_MAX /
sizeof(
T))
231 return make_error<BinaryStreamError>(
258 uint8_t
peek()
const;
262 std::pair<BinaryStreamReader, BinaryStreamReader>
271 #endif // LLVM_SUPPORT_BINARYSTREAMREADER_H virtual ~BinaryStreamReader()
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Error padToAlignment(uint32_t Align)
Error readSubstream(BinarySubstreamRef &Stream, uint32_t Size)
Read Length bytes from the underlying stream into Stream.
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...
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)
void setUnderlyingStream(BinaryStreamRef S, uint32_t Skew=0)
The access may reference the value stored in memory.
Error readCString(StringRef &Dest)
Read a null terminated string from Dest.
uint32_t getOffset() const
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.
size_t alignmentAdjustment(const void *Ptr, size_t Alignment)
Returns the necessary adjustment for aligning Ptr to Alignment bytes, rounding up.
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)
void setOffset(uint32_t Off)
static ErrorSuccess success()
Create a success value.
BinaryStreamRef is to BinaryStream what ArrayRef is to an 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 ...
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 ...