1 //===- LEB128.cpp - LEB128 utility functions implementation -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements some utility functions for encoding SLEB128 and
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Support/LEB128.h"
19 /// Utility function to get the size of the ULEB128-encoded value.
20 unsigned getULEB128Size(uint64_t Value) {
24 Size += sizeof(int8_t);
29 /// Utility function to get the size of the SLEB128-encoded value.
30 unsigned getSLEB128Size(int64_t Value) {
32 int Sign = Value >> (8 * sizeof(Value) - 1);
36 unsigned Byte = Value & 0x7f;
38 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
39 Size += sizeof(int8_t);