15 #ifndef LLVM_SUPPORT_LEB128_H
16 #define LLVM_SUPPORT_LEB128_H
24 unsigned Padding = 0) {
27 uint8_t Byte = Value & 0x7f;
30 More = !((((Value == 0 ) && ((Byte & 0x40) == 0)) ||
31 ((Value == -1) && ((Byte & 0x40) != 0))));
32 if (More || Padding != 0)
39 uint8_t PadValue = Value < 0 ? 0x7f : 0x00;
40 for (; Padding != 1; --Padding)
41 OS <<
char(PadValue | 0x80);
52 uint8_t Byte = Value & 0x7f;
55 More = !((((Value == 0 ) && ((Byte & 0x40) == 0)) ||
56 ((Value == -1) && ((Byte & 0x40) != 0))));
57 if (More || Padding != 0)
64 uint8_t PadValue = Value < 0 ? 0x7f : 0x00;
65 for (; Padding != 1; --Padding)
66 *p++ = (PadValue | 0x80);
69 return (
unsigned)(p - orig_p);
74 unsigned Padding = 0) {
76 uint8_t Byte = Value & 0x7f;
78 if (Value != 0 || Padding != 0)
85 for (; Padding != 1; --Padding)
94 unsigned Padding = 0) {
97 uint8_t Byte = Value & 0x7f;
99 if (Value != 0 || Padding != 0)
102 }
while (Value != 0);
106 for (; Padding != 1; --Padding)
110 return (
unsigned)(p - orig_p);
115 const uint8_t *
end =
nullptr,
116 const char **
error =
nullptr) {
117 const uint8_t *orig_p = p;
125 *
error =
"malformed uleb128, extends past end";
130 uint64_t Slice = *p & 0x7f;
131 if (Shift >= 64 || Slice << Shift >> Shift != Slice) {
133 *
error =
"uleb128 too big for uint64";
138 Value += uint64_t(*p & 0x7f) << Shift;
140 }
while (*p++ >= 128);
148 const uint8_t *
end =
nullptr,
149 const char **
error =
nullptr) {
150 const uint8_t *orig_p = p;
157 *
error =
"malformed sleb128, extends past end";
163 Value |= (int64_t(Byte & 0x7f) << Shift);
165 }
while (Byte >= 128);
168 Value |= (-1ULL) << Shift;
182 #endif // LLVM_SYSTEM_LEB128_H
const_iterator end(StringRef path)
Get end iterator over path.
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 getSLEB128Size(int64_t Value)
Utility function to get the size of the SLEB128-encoded value.
void encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned Padding=0)
Utility function to encode a SLEB128 value to an output stream.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
void encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned Padding=0)
Utility function to encode a ULEB128 value to an output stream.