//===- llvm/Support/LEB128.h - [SU]LEB128 utility functions -----*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file declares some utility functions for encoding SLEB128 and // ULEB128 values. // //===----------------------------------------------------------------------===// #ifndef LLVM_SUPPORT_LEB128_H #define LLVM_SUPPORT_LEB128_H #include "llvm/Support/raw_ostream.h" namespace llvm { /// Utility function to encode a SLEB128 value to an output stream. Returns /// the length in bytes of the encoded value. inline unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo = 0) { … } /// Utility function to encode a SLEB128 value to a buffer. Returns /// the length in bytes of the encoded value. inline unsigned encodeSLEB128(int64_t Value, uint8_t *p, unsigned PadTo = 0) { … } /// Utility function to encode a ULEB128 value to an output stream. Returns /// the length in bytes of the encoded value. inline unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo = 0) { … } /// Utility function to encode a ULEB128 value to a buffer. Returns /// the length in bytes of the encoded value. inline unsigned encodeULEB128(uint64_t Value, uint8_t *p, unsigned PadTo = 0) { … } /// Utility function to decode a ULEB128 value. /// /// If \p error is non-null, it will point to a static error message, /// if an error occured. It will not be modified on success. inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n = nullptr, const uint8_t *end = nullptr, const char **error = nullptr) { … } /// Utility function to decode a SLEB128 value. /// /// If \p error is non-null, it will point to a static error message, /// if an error occured. It will not be modified on success. inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr, const uint8_t *end = nullptr, const char **error = nullptr) { … } inline uint64_t decodeULEB128AndInc(const uint8_t *&p, const uint8_t *end, const char **error = nullptr) { … } inline int64_t decodeSLEB128AndInc(const uint8_t *&p, const uint8_t *end, const char **error = nullptr) { … } inline uint64_t decodeULEB128AndIncUnsafe(const uint8_t *&p) { … } /// Utility function to get the size of the ULEB128-encoded value. extern unsigned getULEB128Size(uint64_t Value); /// Utility function to get the size of the SLEB128-encoded value. extern unsigned getSLEB128Size(int64_t Value); } // namespace llvm #endif // LLVM_SUPPORT_LEB128_H