1//===-- DataExtractor.cpp -------------------------------------------------===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 26"unexpected end of data at offset 0x%zx while reading [0x%" PRIx64
32" is beyond the end of data at 0x%zx",
48if (!prepareRead(offset,
sizeof(
T), Err))
50 std::memcpy(&val, &Data.
data()[offset],
sizeof(val));
55 *offset_ptr +=
sizeof(val);
68if (!prepareRead(offset,
sizeof(*dst) *
count, Err))
70for (
T *value_ptr = dst, *end = dst +
count; value_ptr !=
end;
71 ++value_ptr, offset +=
sizeof(*dst))
72 *value_ptr = getU<T>(offset_ptr, Err);
75// Return a non-NULL pointer to the converted data as an indicator of 81return getU<uint8_t>(offset_ptr, Err);
86return getUs<uint8_t>(offset_ptr, dst,
count,
nullptr);
90return getUs<uint8_t>(&
C.Offset, Dst, Count, &
C.Err);
94return getU<uint16_t>(offset_ptr, Err);
99return getUs<uint16_t>(offset_ptr, dst,
count,
nullptr);
103uint24_t ExtractedVal = getU<uint24_t>(OffsetPtr, Err);
104// The 3 bytes are in the correct byte order for the host. 109return getU<uint32_t>(offset_ptr, Err);
114return getUs<uint32_t>(offset_ptr, dst,
count,
nullptr);
118return getU<uint64_t>(offset_ptr, Err);
123return getUs<uint64_t>(offset_ptr, dst,
count,
nullptr);
130returngetU8(offset_ptr, Err);
132returngetU16(offset_ptr, Err);
134returngetU32(offset_ptr, Err);
136returngetU64(offset_ptr, Err);
145return (int8_t)
getU8(offset_ptr);
147return (int16_t)
getU16(offset_ptr);
149return (int32_t)
getU32(offset_ptr);
151return (int64_t)
getU64(offset_ptr);
164 *OffsetPtr = Pos + 1;
169"no null terminated string at offset 0x%" PRIx64,
178return Bytes.
trim(TrimChars);
187if (!prepareRead(*OffsetPtr,
Length, Err))
197T (&Decoder)(
constuint8_t *p,
unsigned *n,
205constchar *
error =
nullptr;
208 Decoder(Bytes.
data() + *OffsetPtr, &bytes_read, Bytes.
end(), &
error);
212"unable to decode LEB128 at offset 0x%8.8" PRIx64
217 *OffsetPtr += bytes_read;
234if (prepareRead(
C.Offset,
Length, &
C.Err))
static T getLEB128(StringRef Data, uint64_t *OffsetPtr, Error *Err, T(&Decoder)(const uint8_t *p, unsigned *n, const uint8_t *end, const char **error))
static bool isError(Error *E)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some functions that are useful when dealing with strings.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
StringRef getFixedLengthString(uint64_t *OffsetPtr, uint64_t Length, StringRef TrimChars={"\0", 1}) const
Extract a fixed length string from *OffsetPtr and consume Length bytes.
uint64_t getUnsigned(uint64_t *offset_ptr, uint32_t byte_size, Error *Err=nullptr) const
Extract an unsigned integer of size byte_size from *offset_ptr.
uint32_t getU32(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint32_t value from *offset_ptr.
StringRef getCStrRef(uint64_t *OffsetPtr, Error *Err=nullptr) const
Extract a C string from *offset_ptr.
uint8_t getU8(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint8_t value from *offset_ptr.
int64_t getSigned(uint64_t *offset_ptr, uint32_t size) const
Extract an signed integer of size byte_size from *offset_ptr.
uint64_t getULEB128(uint64_t *offset_ptr, llvm::Error *Err=nullptr) const
Extract a unsigned LEB128 value from *offset_ptr.
int64_t getSLEB128(uint64_t *OffsetPtr, Error *Err=nullptr) const
Extract a signed LEB128 value from *offset_ptr.
uint16_t getU16(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint16_t value from *offset_ptr.
void skip(Cursor &C, uint64_t Length) const
Advance the Cursor position by the given number of bytes.
uint64_t getU64(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint64_t value from *offset_ptr.
bool isValidOffsetForDataOfSize(uint64_t offset, uint64_t length) const
Test the availability of length bytes of data from offset.
StringRef getBytes(uint64_t *OffsetPtr, uint64_t Length, Error *Err=nullptr) const
Extract a fixed number of bytes from the specified offset.
uint32_t getU24(uint64_t *OffsetPtr, Error *Err=nullptr) const
Extract a 24-bit unsigned value from *offset_ptr and return it in a uint32_t.
Helper for Errors used as out-parameters.
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
static constexpr size_t npos
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
const_iterator end(StringRef path LLVM_LIFETIME_BOUND)
Get end iterator over path.
static const bool IsLittleEndianHost
void swapByteOrder(T &Value)
This is an optimization pass for GlobalISel generic memory operations.
uint64_t decodeULEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a ULEB128 value.
int64_t decodeSLEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a SLEB128 value.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
An auxiliary type to facilitate extraction of 3-byte entities.
uint32_t getAsUint32(bool IsLittleEndian) const