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

1

2

3

4

5

6

7

8

15

16using namespace llvm;

17

21 return true;

22 if (E) {

26 "unexpected end of data at offset 0x%zx while reading [0x%" PRIx64

27 ", 0x%" PRIx64 ")",

29 else

31 "offset 0x%" PRIx64

32 " is beyond the end of data at 0x%zx",

34 }

35 return false;

36}

37

39

40template

41T DataExtractor::getU(uint64_t *offset_ptr, Error *Err) const {

43 T val = 0;

45 return val;

46

47 uint64_t offset = *offset_ptr;

48 if (!prepareRead(offset, sizeof(T), Err))

49 return val;

50 std::memcpy(&val, &Data.data()[offset], sizeof(val));

53

54

55 *offset_ptr += sizeof(val);

56 return val;

57}

58

59template

61 Error *Err) const {

64 return nullptr;

65

66 uint64_t offset = *offset_ptr;

67

68 if (!prepareRead(offset, sizeof(*dst) * count, Err))

69 return nullptr;

70 for (T *value_ptr = dst, *end = dst + count; value_ptr != end;

71 ++value_ptr, offset += sizeof(*dst))

72 *value_ptr = getU(offset_ptr, Err);

73

74 *offset_ptr = offset;

75

76

77 return dst;

78}

79

81 return getU<uint8_t>(offset_ptr, Err);

82}

83

86 return getUs<uint8_t>(offset_ptr, dst, count, nullptr);

87}

88

90 return getUs<uint8_t>(&C.Offset, Dst, Count, &C.Err);

91}

92

94 return getU<uint16_t>(offset_ptr, Err);

95}

96

99 return getUs<uint16_t>(offset_ptr, dst, count, nullptr);

100}

101

103 uint24_t ExtractedVal = getU<uint24_t>(OffsetPtr, Err);

104

106}

107

109 return getU<uint32_t>(offset_ptr, Err);

110}

111

114 return getUs<uint32_t>(offset_ptr, dst, count, nullptr);

115}

116

118 return getU<uint64_t>(offset_ptr, Err);

119}

120

123 return getUs<uint64_t>(offset_ptr, dst, count, nullptr);

124}

125

128 switch (byte_size) {

129 case 1:

130 return getU8(offset_ptr, Err);

131 case 2:

132 return getU16(offset_ptr, Err);

133 case 4:

134 return getU32(offset_ptr, Err);

135 case 8:

136 return getU64(offset_ptr, Err);

137 }

139}

140

141int64_t

143 switch (byte_size) {

144 case 1:

145 return (int8_t)getU8(offset_ptr);

146 case 2:

147 return (int16_t)getU16(offset_ptr);

148 case 4:

149 return (int32_t)getU32(offset_ptr);

150 case 8:

151 return (int64_t)getU64(offset_ptr);

152 }

154}

155

160

164 *OffsetPtr = Pos + 1;

165 return StringRef(Data.data() + Start, Pos - Start);

166 }

167 if (Err)

169 "no null terminated string at offset 0x%" PRIx64,

170 Start);

172}

173

178 return Bytes.trim(TrimChars);

179}

180

182 Error *Err) const {

186

187 if (!prepareRead(*OffsetPtr, Length, Err))

189

191 *OffsetPtr += Length;

192 return Result;

193}

194

195template

197 T (&Decoder)(const uint8_t *p, unsigned *n,

203 return T();

204

205 const char *error = nullptr;

206 unsigned bytes_read;

207 T result =

208 Decoder(Bytes.data() + *OffsetPtr, &bytes_read, Bytes.end(), &error);

210 if (Err)

212 "unable to decode LEB128 at offset 0x%8.8" PRIx64

213 ": %s",

214 *OffsetPtr, error);

215 return T();

216 }

217 *OffsetPtr += bytes_read;

218 return result;

219}

220

223}

224

227}

228

232 return;

233

234 if (prepareRead(C.Offset, Length, &C.Err))

236}

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

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

size_t size() const

size - Get the array size.

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