LLVM: include/llvm/Support/BinaryStreamReader.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_SUPPORT_BINARYSTREAMREADER_H

10#define LLVM_SUPPORT_BINARYSTREAMREADER_H

11

21#include <type_traits>

22

23namespace llvm {

24

25

26

27

28

29

31public:

38

40

42

44

45

46

47

48

49

50

52

53

54

55

56

57

58

59

61

62

63

64

65

66

67

68

70 static_assert(std::is_integral_v,

71 "Cannot call readInteger with non-integral value!");

72

74 if (auto EC = readBytes(Bytes, sizeof(T)))

75 return EC;

76

79 }

80

81

83 static_assert(std::is_enum::value,

84 "Cannot call readEnum with non-enum value!");

85 std::underlying_type_t N;

87 return EC;

88 Dest = static_cast<T>(N);

90 }

91

92

93

94

95

97

98

99

100

101

103

104

105

106

107

108

109

111

112

113

114

115

116

118

119

120

121

122

123

124

126

127

128

129

130

131

132

134

135

136

137

138

139

140

141

143

144

145

146

147

148

149

150

152

153

154

155

156

157

158

159

160

161

164 if (auto EC = readBytes(Buffer, sizeof(T)))

165 return EC;

166 Dest = reinterpret_cast<const T *>(Buffer.data());

168 }

169

170

171

172

173

174

175

176

177

178

179 template

182 if (NumElements == 0) {

185 }

186

187 if (NumElements > UINT32_MAX / sizeof(T))

190

191 if (auto EC = readBytes(Bytes, NumElements * sizeof(T)))

192 return EC;

193

195 "Reading at invalid alignment!");

196

197 Array = ArrayRef(reinterpret_cast<const T *>(Bytes.data()), NumElements);

199 }

200

201

202

203

204

205

206

207

208

209 template <typename T, typename U>

214 return EC;

215 Array.setUnderlyingStream(S, Skew);

217 }

218

219

220

221

222

223

224

225

226

227 template

229 if (NumItems == 0) {

232 }

233

234 if (NumItems > UINT32_MAX / sizeof(T))

237

239 if (auto EC = readStreamRef(View, NumItems * sizeof(T)))

240 return EC;

241

244 }

245

251

252

253

254

255

257

258

259

260

261

263

265

266 LLVM_ABI std::pair<BinaryStreamReader, BinaryStreamReader>

268

269private:

272};

273}

274

275#endif

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

Lightweight arrays that are backed by an arbitrary BinaryStream.

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

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

Definition BinaryStreamReader.h:162

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

Definition BinaryStreamReader.h:228

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

LLVM_ABI uint8_t peek() const

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

LLVM_ABI Error readWideString(ArrayRef< UTF16 > &Dest)

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

uint64_t getLength() const

Definition BinaryStreamReader.h:249

LLVM_ABI Error readSubstream(BinarySubstreamRef &Ref, uint32_t Length)

Read Length bytes from the underlying stream into Ref.

Error readEnum(T &Dest)

Similar to readInteger.

Definition BinaryStreamReader.h:82

Error readInteger(T &Dest)

Read an integer of the specified endianness into Dest and update the stream's offset.

Definition BinaryStreamReader.h:69

BinaryStreamReader()=default

uint64_t bytesRemaining() const

Definition BinaryStreamReader.h:250

bool empty() const

Definition BinaryStreamReader.h:246

uint64_t getOffset() const

Definition BinaryStreamReader.h:248

LLVM_ABI Error readSLEB128(int64_t &Dest)

Read a signed LEB128 encoded value.

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

LLVM_ABI Error padToAlignment(uint32_t Align)

LLVM_ABI Error readFixedString(StringRef &Dest, uint32_t Length)

Read a Length byte string into Dest.

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

void setOffset(uint64_t Off)

Definition BinaryStreamReader.h:247

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

Definition BinaryStreamReader.h:180

LLVM_ABI Error readULEB128(uint64_t &Dest)

Read an unsigned LEB128 encoded value.

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

Definition BinaryStreamReader.h:210

virtual ~BinaryStreamReader()=default

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.

value_type read(const void *memory, endianness endian)

Read a value of a particular endianness from memory.

This is an optimization pass for GlobalISel generic memory operations.

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.

FunctionAddr VTableAddr uintptr_t uintptr_t Data

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.

static constexpr Align Of()

Allow constructions of constexpr Align from types.