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

20#include <type_traits>

21

22namespace llvm {

23

24

25

26

27

28

30public:

36

38

40

42

43

44

45

46

47

48

50

51

52

53

54

55

56

57

59

60

61

62

63

64

65

66

68 static_assert(std::is_integral_v,

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

70

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

73 return EC;

74

75 Dest = llvm::support::endian::read(Bytes.data(), Stream.getEndian());

77 }

78

79

81 static_assert(std::is_enum::value,

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

83 std::underlying_type_t N;

85 return EC;

86 Dest = static_cast<T>(N);

88 }

89

90

91

92

93

95

96

97

98

99

101

102

103

104

105

106

107

109

110

111

112

113

114

116

117

118

119

120

121

122

124

125

126

127

128

129

130

132

133

134

135

136

137

138

139

141

142

143

144

145

146

147

148

150

151

152

153

154

155

156

157

158

159

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

163 return EC;

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

166 }

167

168

169

170

171

172

173

174

175

176

177 template

180 if (NumElements == 0) {

183 }

184

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

186 return make_error(

188

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

190 return EC;

191

193 "Reading at invalid alignment!");

194

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

197 }

198

199

200

201

202

203

204

205

206

207 template <typename T, typename U>

212 return EC;

213 Array.setUnderlyingStream(S, Skew);

215 }

216

217

218

219

220

221

222

223

224

225 template

227 if (NumItems == 0) {

230 }

231

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

233 return make_error(

235

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

238 return EC;

239

242 }

243

249

250

251

252

253

255

256

257

258

259

261

263

264 std::pair<BinaryStreamReader, BinaryStreamReader>

266

267private:

270};

271}

272

273#endif

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