//===- llvm/Support/LEB128.h - [SU]LEB128 utility functions -----*- C++ -*-===//1//2// The LLVM Compiler Infrastructure3//4// This file is distributed under the University of Illinois Open Source5// License. See LICENSE.TXT for details.6//7//===----------------------------------------------------------------------===//8//9// This file declares some utility functions for encoding SLEB128 and10// ULEB128 values.11//12//===----------------------------------------------------------------------===//1314/* Capstone Disassembly Engine */15/* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */1617#ifndef CS_LLVM_SUPPORT_LEB128_H18#define CS_LLVM_SUPPORT_LEB128_H1920#include "include/capstone/capstone.h"2122/// Utility function to decode a ULEB128 value.23static inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n)24{25const uint8_t *orig_p = p;26uint64_t Value = 0;27unsigned Shift = 0;28do {29Value += (uint64_t)(*p & 0x7f) << Shift;30Shift += 7;31} while (*p++ >= 128);32if (n)33*n = (unsigned)(p - orig_p);34return Value;35}3637#endif // LLVM_SYSTEM_LEB128_H383940