LLVM: lib/Support/BinaryStreamReader.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

10

14

15using namespace llvm;

16

18

20

23 : Stream(Data, Endian) {}

24

26 : Stream(Data, Endian) {}

27

30 if (auto EC = Stream.readLongestContiguousChunk(Offset, Buffer))

31 return EC;

32 Offset += Buffer.size();

34}

35

37 if (auto EC = Stream.readBytes(Offset, Size, Buffer))

38 return EC;

39 Offset += Size;

41}

42

46

47

48 do {

49 if (auto Err = readBytes(NextByte, 1))

50 return Err;

51 EncodedBytes.push_back(NextByte[0]);

52 } while (NextByte[0] & 0x80);

53

56}

57

61

62

63 do {

64 if (auto Err = readBytes(NextByte, 1))

65 return Err;

66 EncodedBytes.push_back(NextByte[0]);

67 } while (NextByte[0] & 0x80);

68

71}

72

76 while (true) {

80 return EC;

81 StringRef S(reinterpret_cast<const char *>(Buffer.begin()), Buffer.size());

84 FoundOffset = Pos + ThisOffset;

85 break;

86 }

87 }

88 assert(FoundOffset >= OriginalOffset);

89

91 size_t Length = FoundOffset - OriginalOffset;

92

94 return EC;

95

96

99}

100

105 while (true) {

107 return EC;

108 if (*C == 0x0000)

109 break;

111 }

114

116 return EC;

119}

120

124 return EC;

125 Dest = StringRef(reinterpret_cast<const char *>(Bytes.begin()), Bytes.size());

127}

128

132

140

146

150 Offset += Amount;

152}

153

156 return skip(NewOffset - Offset);

157}

158

161 auto EC = Stream.readBytes(Offset, 1, Buffer);

162 assert(!EC && "Cannot peek an empty buffer!");

164 return Buffer[0];

165}

166

167std::pair<BinaryStreamReader, BinaryStreamReader>

170

172

177 return {W1, W2};

178}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

#define LLVM_LIKELY(EXPR)

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

size_t size() const

size - Get the array size.

LLVM_ABI Error readStreamRef(BinaryStreamRef &Ref)

Read the entire remainder of the underlying stream into Ref.

Definition BinaryStreamReader.cpp:129

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...

LLVM_ABI Error readCString(StringRef &Dest)

Read a null terminated string from Dest.

Definition BinaryStreamReader.cpp:73

LLVM_ABI 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 ...

Definition BinaryStreamReader.cpp:36

LLVM_ABI uint8_t peek() const

Examine the next byte of the underlying stream without advancing the stream's offset.

Definition BinaryStreamReader.cpp:159

LLVM_ABI Error readWideString(ArrayRef< UTF16 > &Dest)

Similar to readCString, however read a null-terminated UTF16 string instead.

Definition BinaryStreamReader.cpp:101

uint64_t getLength() const

LLVM_ABI Error readSubstream(BinarySubstreamRef &Ref, uint32_t Length)

Read Length bytes from the underlying stream into Ref.

Definition BinaryStreamReader.cpp:141

BinaryStreamReader()=default

uint64_t bytesRemaining() const

uint64_t getOffset() const

LLVM_ABI Error readSLEB128(int64_t &Dest)

Read a signed LEB128 encoded value.

Definition BinaryStreamReader.cpp:58

LLVM_ABI Error readLongestContiguousChunk(ArrayRef< uint8_t > &Buffer)

Read as much as possible from the underlying string at the current offset without invoking a copy,...

Definition BinaryStreamReader.cpp:28

LLVM_ABI Error padToAlignment(uint32_t Align)

Definition BinaryStreamReader.cpp:154

LLVM_ABI Error readFixedString(StringRef &Dest, uint32_t Length)

Read a Length byte string into Dest.

Definition BinaryStreamReader.cpp:121

LLVM_ABI std::pair< BinaryStreamReader, BinaryStreamReader > split(uint64_t Offset) const

Definition BinaryStreamReader.cpp:168

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 ...

LLVM_ABI Error readULEB128(uint64_t &Dest)

Read an unsigned LEB128 encoded value.

Definition BinaryStreamReader.cpp:43

LLVM_ABI Error skip(uint64_t Amount)

Advance the stream's offset by Amount bytes.

Definition BinaryStreamReader.cpp:147

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.

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringRef - Represent a constant reference to a string, i.e.

static constexpr size_t npos

size_t find_first_of(char C, size_t From=0) const

Find the first character in the string that is C, or npos if not found.

@ C

The default llvm calling convention, compatible with C.

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 make_error(ArgTs &&... Args)

Make a Error instance representing failure using the given error info type.

@ Ref

The access may reference the value stored in memory.

@ First

Helpers to iterate all locations in the MemoryEffectsBase class.

FunctionAddr VTableAddr uintptr_t uintptr_t Data

uint64_t alignTo(uint64_t Size, Align A)

Returns a multiple of A needed to store Size bytes.

void consumeError(Error Err)

Consume a Error without doing anything.

This struct is a compact representation of a valid (non-zero power of two) alignment.