/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Support/LEB128.cpp
Line | Count | Source |
1 | | //===- LEB128.cpp - LEB128 utility functions implementation -----*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This file implements some utility functions for encoding SLEB128 and |
10 | | // ULEB128 values. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #include "llvm/Support/LEB128.h" |
15 | | |
16 | | namespace llvm { |
17 | | |
18 | | /// Utility function to get the size of the ULEB128-encoded value. |
19 | 400k | unsigned getULEB128Size(uint64_t Value) { |
20 | 400k | unsigned Size = 0; |
21 | 401k | do { |
22 | 401k | Value >>= 7; |
23 | 401k | Size += sizeof(int8_t); |
24 | 401k | } while (Value); |
25 | 400k | return Size; |
26 | 400k | } |
27 | | |
28 | | /// Utility function to get the size of the SLEB128-encoded value. |
29 | 5.26k | unsigned getSLEB128Size(int64_t Value) { |
30 | 5.26k | unsigned Size = 0; |
31 | 5.26k | int Sign = Value >> (8 * sizeof(Value) - 1); |
32 | 5.26k | bool IsMore; |
33 | 5.26k | |
34 | 6.11k | do { |
35 | 6.11k | unsigned Byte = Value & 0x7f; |
36 | 6.11k | Value >>= 7; |
37 | 6.11k | IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 05.42k ; |
38 | 6.11k | Size += sizeof(int8_t); |
39 | 6.11k | } while (IsMore); |
40 | 5.26k | return Size; |
41 | 5.26k | } |
42 | | |
43 | | } // namespace llvm |