15 #ifndef LLVM_SUPPORT_LEB128_H 16 #define LLVM_SUPPORT_LEB128_H 29 uint8_t Byte = Value & 0x7f;
32 More = !((((Value == 0 ) && ((Byte & 0x40) == 0)) ||
33 ((Value == -1) && ((Byte & 0x40) != 0))));
35 if (More || Count < PadTo)
42 uint8_t PadValue = Value < 0 ? 0x7f : 0x00;
43 for (; Count < PadTo - 1; ++Count)
44 OS <<
char(PadValue | 0x80);
58 uint8_t Byte = Value & 0x7f;
61 More = !((((Value == 0 ) && ((Byte & 0x40) == 0)) ||
62 ((Value == -1) && ((Byte & 0x40) != 0))));
64 if (More || Count < PadTo)
71 uint8_t PadValue = Value < 0 ? 0x7f : 0x00;
72 for (; Count < PadTo - 1; ++Count)
73 *p++ = (PadValue | 0x80);
76 return (
unsigned)(p - orig_p);
85 uint8_t Byte = Value & 0x7f;
88 if (Value != 0 || Count < PadTo)
95 for (; Count < PadTo - 1; ++Count)
106 unsigned PadTo = 0) {
110 uint8_t Byte = Value & 0x7f;
113 if (Value != 0 || Count < PadTo)
116 }
while (Value != 0);
120 for (; Count < PadTo - 1; ++Count)
125 return (
unsigned)(p - orig_p);
130 const uint8_t *
end =
nullptr,
131 const char **
error =
nullptr) {
132 const uint8_t *orig_p = p;
140 *
error =
"malformed uleb128, extends past end";
145 uint64_t Slice = *p & 0x7f;
146 if (Shift >= 64 || Slice << Shift >> Shift != Slice) {
148 *
error =
"uleb128 too big for uint64";
153 Value += uint64_t(*p & 0x7f) << Shift;
155 }
while (*p++ >= 128);
163 const uint8_t *
end =
nullptr,
164 const char **
error =
nullptr) {
165 const uint8_t *orig_p = p;
172 *
error =
"malformed sleb128, extends past end";
178 Value |= (int64_t(Byte & 0x7f) << Shift);
180 }
while (Byte >= 128);
183 Value |= (-1ULL) << Shift;
197 #endif // LLVM_SYSTEM_LEB128_H const_iterator end(StringRef path)
Get end iterator over path.
This class represents lattice values for constants.
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.
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.
unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
unsigned getSLEB128Size(int64_t Value)
Utility function to get the size of the SLEB128-encoded value.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...