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 | 39.4M | { |
26 | 39.4M | const uint8_t *orig_p = p; |
27 | 39.4M | uint64_t Value = 0; |
28 | 39.4M | unsigned Shift = 0; |
29 | 44.0M | do { |
30 | 44.0M | Value += (uint64_t)(*p & 0x7f) << Shift; |
31 | 44.0M | Shift += 7; |
32 | 44.0M | } while (*p++ >= 128); |
33 | 39.4M | if (n) |
34 | 39.4M | *n = (unsigned)(p - orig_p); |
35 | 39.4M | return Value; |
36 | 39.4M | } ARMDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 16.4M | { | 26 | 16.4M | const uint8_t *orig_p = p; | 27 | 16.4M | uint64_t Value = 0; | 28 | 16.4M | unsigned Shift = 0; | 29 | 18.1M | do { | 30 | 18.1M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 18.1M | Shift += 7; | 32 | 18.1M | } while (*p++ >= 128); | 33 | 16.4M | if (n) | 34 | 16.4M | *n = (unsigned)(p - orig_p); | 35 | 16.4M | return Value; | 36 | 16.4M | } |
AArch64Disassembler.c:decodeULEB128 Line | Count | Source | 25 | 6.31M | { | 26 | 6.31M | const uint8_t *orig_p = p; | 27 | 6.31M | uint64_t Value = 0; | 28 | 6.31M | unsigned Shift = 0; | 29 | 6.90M | do { | 30 | 6.90M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 6.90M | Shift += 7; | 32 | 6.90M | } while (*p++ >= 128); | 33 | 6.31M | if (n) | 34 | 6.31M | *n = (unsigned)(p - orig_p); | 35 | 6.31M | return Value; | 36 | 6.31M | } |
MipsDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 2.81M | { | 26 | 2.81M | const uint8_t *orig_p = p; | 27 | 2.81M | uint64_t Value = 0; | 28 | 2.81M | unsigned Shift = 0; | 29 | 2.92M | do { | 30 | 2.92M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 2.92M | Shift += 7; | 32 | 2.92M | } while (*p++ >= 128); | 33 | 2.81M | if (n) | 34 | 2.81M | *n = (unsigned)(p - orig_p); | 35 | 2.81M | return Value; | 36 | 2.81M | } |
PPCDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 4.50M | { | 26 | 4.50M | const uint8_t *orig_p = p; | 27 | 4.50M | uint64_t Value = 0; | 28 | 4.50M | unsigned Shift = 0; | 29 | 4.69M | do { | 30 | 4.69M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 4.69M | Shift += 7; | 32 | 4.69M | } while (*p++ >= 128); | 33 | 4.50M | if (n) | 34 | 4.50M | *n = (unsigned)(p - orig_p); | 35 | 4.50M | return Value; | 36 | 4.50M | } |
SparcDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 1.41M | { | 26 | 1.41M | const uint8_t *orig_p = p; | 27 | 1.41M | uint64_t Value = 0; | 28 | 1.41M | unsigned Shift = 0; | 29 | 1.45M | do { | 30 | 1.45M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 1.45M | Shift += 7; | 32 | 1.45M | } while (*p++ >= 128); | 33 | 1.41M | if (n) | 34 | 1.41M | *n = (unsigned)(p - orig_p); | 35 | 1.41M | return Value; | 36 | 1.41M | } |
SystemZDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 4.46M | { | 26 | 4.46M | const uint8_t *orig_p = p; | 27 | 4.46M | uint64_t Value = 0; | 28 | 4.46M | unsigned Shift = 0; | 29 | 6.12M | do { | 30 | 6.12M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 6.12M | Shift += 7; | 32 | 6.12M | } while (*p++ >= 128); | 33 | 4.46M | if (n) | 34 | 4.46M | *n = (unsigned)(p - orig_p); | 35 | 4.46M | return Value; | 36 | 4.46M | } |
XCoreDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 719k | { | 26 | 719k | const uint8_t *orig_p = p; | 27 | 719k | uint64_t Value = 0; | 28 | 719k | unsigned Shift = 0; | 29 | 809k | do { | 30 | 809k | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 809k | Shift += 7; | 32 | 809k | } while (*p++ >= 128); | 33 | 719k | if (n) | 34 | 719k | *n = (unsigned)(p - orig_p); | 35 | 719k | return Value; | 36 | 719k | } |
TMS320C64xDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 819k | { | 26 | 819k | const uint8_t *orig_p = p; | 27 | 819k | uint64_t Value = 0; | 28 | 819k | unsigned Shift = 0; | 29 | 835k | do { | 30 | 835k | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 835k | Shift += 7; | 32 | 835k | } while (*p++ >= 128); | 33 | 819k | if (n) | 34 | 819k | *n = (unsigned)(p - orig_p); | 35 | 819k | return Value; | 36 | 819k | } |
RISCVDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 2.01M | { | 26 | 2.01M | const uint8_t *orig_p = p; | 27 | 2.01M | uint64_t Value = 0; | 28 | 2.01M | unsigned Shift = 0; | 29 | 2.09M | do { | 30 | 2.09M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 2.09M | Shift += 7; | 32 | 2.09M | } while (*p++ >= 128); | 33 | 2.01M | if (n) | 34 | 2.01M | *n = (unsigned)(p - orig_p); | 35 | 2.01M | return Value; | 36 | 2.01M | } |
Unexecuted instantiation: TriCoreDisassembler.c:decodeULEB128 |
37 | | |
38 | | #endif // LLVM_SYSTEM_LEB128_H |