14 #ifndef LLVM_SUPPORT_LEB128_H 15 #define LLVM_SUPPORT_LEB128_H 28 uint8_t Byte = Value & 0x7f;
31 More = !((((Value == 0 ) && ((Byte & 0x40) == 0)) ||
32 ((Value == -1) && ((Byte & 0x40) != 0))));
34 if (More || Count < PadTo)
41 uint8_t PadValue = Value < 0 ? 0x7f : 0x00;
42 for (; Count < PadTo - 1; ++Count)
43 OS <<
char(PadValue | 0x80);
57 uint8_t Byte = Value & 0x7f;
60 More = !((((Value == 0 ) && ((Byte & 0x40) == 0)) ||
61 ((Value == -1) && ((Byte & 0x40) != 0))));
63 if (More || Count < PadTo)
70 uint8_t PadValue = Value < 0 ? 0x7f : 0x00;
71 for (; Count < PadTo - 1; ++Count)
72 *p++ = (PadValue | 0x80);
75 return (
unsigned)(p - orig_p);
84 uint8_t Byte = Value & 0x7f;
87 if (Value != 0 || Count < PadTo)
94 for (; Count < PadTo - 1; ++Count)
105 unsigned PadTo = 0) {
109 uint8_t Byte = Value & 0x7f;
112 if (Value != 0 || Count < PadTo)
115 }
while (Value != 0);
119 for (; Count < PadTo - 1; ++Count)
124 return (
unsigned)(p - orig_p);
129 const uint8_t *
end =
nullptr,
130 const char **
error =
nullptr) {
131 const uint8_t *orig_p = p;
139 *
error =
"malformed uleb128, extends past end";
144 uint64_t Slice = *p & 0x7f;
145 if (Shift >= 64 || Slice << Shift >> Shift != Slice) {
147 *
error =
"uleb128 too big for uint64";
152 Value += uint64_t(*p & 0x7f) << Shift;
154 }
while (*p++ >= 128);
162 const uint8_t *
end =
nullptr,
163 const char **
error =
nullptr) {
164 const uint8_t *orig_p = p;
173 *
error =
"malformed sleb128, extends past end";
179 Value |= (uint64_t(Byte & 0x7f) << Shift);
181 }
while (Byte >= 128);
183 if (Shift < 64 && (Byte & 0x40))
184 Value |= (-1ULL) << Shift;
198 #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...