Line | Count | Source |
1 | | //===- llvm/Support/LEB128.h - [SU]LEB128 utility functions -----*- C++ -*-===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | // |
10 | | // This file declares some utility functions for encoding SLEB128 and |
11 | | // ULEB128 values. |
12 | | // |
13 | | //===----------------------------------------------------------------------===// |
14 | | |
15 | | /* Capstone Disassembly Engine */ |
16 | | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2019 */ |
17 | | |
18 | | #ifndef CS_LLVM_SUPPORT_LEB128_H |
19 | | #define CS_LLVM_SUPPORT_LEB128_H |
20 | | |
21 | | #include "include/capstone/capstone.h" |
22 | | |
23 | | /// Utility function to decode a ULEB128 value. |
24 | | static inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n) |
25 | 32.6M | { |
26 | 32.6M | const uint8_t *orig_p = p; |
27 | 32.6M | uint64_t Value = 0; |
28 | 32.6M | unsigned Shift = 0; |
29 | 36.5M | do { |
30 | 36.5M | Value += (uint64_t)(*p & 0x7f) << Shift; |
31 | 36.5M | Shift += 7; |
32 | 36.5M | } while (*p++ >= 128); |
33 | 32.6M | if (n) |
34 | 32.6M | *n = (unsigned)(p - orig_p); |
35 | 32.6M | return Value; |
36 | 32.6M | } ARMDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 14.3M | { | 26 | 14.3M | const uint8_t *orig_p = p; | 27 | 14.3M | uint64_t Value = 0; | 28 | 14.3M | unsigned Shift = 0; | 29 | 15.9M | do { | 30 | 15.9M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 15.9M | Shift += 7; | 32 | 15.9M | } while (*p++ >= 128); | 33 | 14.3M | if (n) | 34 | 14.3M | *n = (unsigned)(p - orig_p); | 35 | 14.3M | return Value; | 36 | 14.3M | } |
AArch64Disassembler.c:decodeULEB128 Line | Count | Source | 25 | 4.59M | { | 26 | 4.59M | const uint8_t *orig_p = p; | 27 | 4.59M | uint64_t Value = 0; | 28 | 4.59M | unsigned Shift = 0; | 29 | 5.03M | do { | 30 | 5.03M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 5.03M | Shift += 7; | 32 | 5.03M | } while (*p++ >= 128); | 33 | 4.59M | if (n) | 34 | 4.59M | *n = (unsigned)(p - orig_p); | 35 | 4.59M | return Value; | 36 | 4.59M | } |
MipsDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 2.18M | { | 26 | 2.18M | const uint8_t *orig_p = p; | 27 | 2.18M | uint64_t Value = 0; | 28 | 2.18M | unsigned Shift = 0; | 29 | 2.26M | do { | 30 | 2.26M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 2.26M | Shift += 7; | 32 | 2.26M | } while (*p++ >= 128); | 33 | 2.18M | if (n) | 34 | 2.18M | *n = (unsigned)(p - orig_p); | 35 | 2.18M | return Value; | 36 | 2.18M | } |
PPCDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 3.61M | { | 26 | 3.61M | const uint8_t *orig_p = p; | 27 | 3.61M | uint64_t Value = 0; | 28 | 3.61M | unsigned Shift = 0; | 29 | 3.77M | do { | 30 | 3.77M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 3.77M | Shift += 7; | 32 | 3.77M | } while (*p++ >= 128); | 33 | 3.61M | if (n) | 34 | 3.61M | *n = (unsigned)(p - orig_p); | 35 | 3.61M | return Value; | 36 | 3.61M | } |
SparcDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 1.12M | { | 26 | 1.12M | const uint8_t *orig_p = p; | 27 | 1.12M | uint64_t Value = 0; | 28 | 1.12M | unsigned Shift = 0; | 29 | 1.15M | do { | 30 | 1.15M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 1.15M | Shift += 7; | 32 | 1.15M | } while (*p++ >= 128); | 33 | 1.12M | if (n) | 34 | 1.12M | *n = (unsigned)(p - orig_p); | 35 | 1.12M | return Value; | 36 | 1.12M | } |
SystemZDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 3.87M | { | 26 | 3.87M | const uint8_t *orig_p = p; | 27 | 3.87M | uint64_t Value = 0; | 28 | 3.87M | unsigned Shift = 0; | 29 | 5.30M | do { | 30 | 5.30M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 5.30M | Shift += 7; | 32 | 5.30M | } while (*p++ >= 128); | 33 | 3.87M | if (n) | 34 | 3.87M | *n = (unsigned)(p - orig_p); | 35 | 3.87M | return Value; | 36 | 3.87M | } |
XCoreDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 667k | { | 26 | 667k | const uint8_t *orig_p = p; | 27 | 667k | uint64_t Value = 0; | 28 | 667k | unsigned Shift = 0; | 29 | 761k | do { | 30 | 761k | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 761k | Shift += 7; | 32 | 761k | } while (*p++ >= 128); | 33 | 667k | if (n) | 34 | 667k | *n = (unsigned)(p - orig_p); | 35 | 667k | return Value; | 36 | 667k | } |
TMS320C64xDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 766k | { | 26 | 766k | const uint8_t *orig_p = p; | 27 | 766k | uint64_t Value = 0; | 28 | 766k | unsigned Shift = 0; | 29 | 782k | do { | 30 | 782k | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 782k | Shift += 7; | 32 | 782k | } while (*p++ >= 128); | 33 | 766k | if (n) | 34 | 766k | *n = (unsigned)(p - orig_p); | 35 | 766k | return Value; | 36 | 766k | } |
RISCVDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 1.46M | { | 26 | 1.46M | const uint8_t *orig_p = p; | 27 | 1.46M | uint64_t Value = 0; | 28 | 1.46M | unsigned Shift = 0; | 29 | 1.53M | do { | 30 | 1.53M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 1.53M | Shift += 7; | 32 | 1.53M | } while (*p++ >= 128); | 33 | 1.46M | if (n) | 34 | 1.46M | *n = (unsigned)(p - orig_p); | 35 | 1.46M | return Value; | 36 | 1.46M | } |
Unexecuted instantiation: TriCoreDisassembler.c:decodeULEB128 |
37 | | |
38 | | #endif // LLVM_SYSTEM_LEB128_H |