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";
145 if ((Shift >= 64 && Slice != 0) || Slice << Shift >> Shift != Slice) {
147 *
error =
"uleb128 too big for uint64";
152 Value += Slice << 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";
180 if ((Shift >= 64 && Slice != (
Value < 0 ? 0x7f : 0x00)) ||
181 (Shift == 63 && Slice != 0 && Slice != 0x7f)) {
183 *
error =
"sleb128 too big for int64";
188 Value |= Slice << Shift;
191 }
while (Byte >= 128);
193 if (Shift < 64 && (Byte & 0x40))
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
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.
unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
unsigned getSLEB128Size(int64_t Value)
Utility function to get the size of the SLEB128-encoded value.