X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FLEB128.h;h=6eb34eec8a6c545395e636f6582fea756e7f23b8;hp=ec23d5747becfd497ccb7f78858c0526f706900b;hb=80668d18e8064560bb6c227cde4e2a01d32e683e;hpb=f01742d03fb034e50f2a7717fb1325644e02ca72 diff --git a/include/llvm/Support/LEB128.h b/include/llvm/Support/LEB128.h index ec23d5747be..6eb34eec8a6 100644 --- a/include/llvm/Support/LEB128.h +++ b/include/llvm/Support/LEB128.h @@ -20,7 +20,7 @@ namespace llvm { /// Utility function to encode a SLEB128 value to an output stream. -static inline void encodeSLEB128(int64_t Value, raw_ostream &OS) { +inline void encodeSLEB128(int64_t Value, raw_ostream &OS) { bool More; do { uint8_t Byte = Value & 0x7f; @@ -35,8 +35,8 @@ static inline void encodeSLEB128(int64_t Value, raw_ostream &OS) { } /// Utility function to encode a ULEB128 value to an output stream. -static inline void encodeULEB128(uint64_t Value, raw_ostream &OS, - unsigned Padding = 0) { +inline void encodeULEB128(uint64_t Value, raw_ostream &OS, + unsigned Padding = 0) { do { uint8_t Byte = Value & 0x7f; Value >>= 7; @@ -55,8 +55,8 @@ static inline void encodeULEB128(uint64_t Value, raw_ostream &OS, /// Utility function to encode a ULEB128 value to a buffer. Returns /// the length in bytes of the encoded value. -static inline unsigned encodeULEB128(uint64_t Value, uint8_t *p, - unsigned Padding = 0) { +inline unsigned encodeULEB128(uint64_t Value, uint8_t *p, + unsigned Padding = 0) { uint8_t *orig_p = p; do { uint8_t Byte = Value & 0x7f; @@ -77,7 +77,7 @@ static inline unsigned encodeULEB128(uint64_t Value, uint8_t *p, /// Utility function to decode a ULEB128 value. -static inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n = 0) { +inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n = 0) { const uint8_t *orig_p = p; uint64_t Value = 0; unsigned Shift = 0; @@ -90,6 +90,31 @@ static inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n = 0) { return Value; } +/// Utility function to get the size of the ULEB128-encoded value. +inline unsigned getULEB128Size(uint64_t Value) { + unsigned Size = 0; + do { + Value >>= 7; + Size += sizeof(int8_t); + } while (Value); + return Size; +} + +/// Utility function to get the size of the SLEB128-encoded value. +inline unsigned getSLEB128Size(int64_t Value) { + unsigned Size = 0; + int Sign = Value >> (8 * sizeof(Value) - 1); + bool IsMore; + + do { + unsigned Byte = Value & 0x7f; + Value >>= 7; + IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; + Size += sizeof(int8_t); + } while (IsMore); + return Size; +} + } // namespace llvm #endif // LLVM_SYSTEM_LEB128_H