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 | 49.2M | { |
26 | 49.2M | const uint8_t *orig_p = p; |
27 | 49.2M | uint64_t Value = 0; |
28 | 49.2M | unsigned Shift = 0; |
29 | 55.1M | do { |
30 | 55.1M | Value += (uint64_t)(*p & 0x7f) << Shift; |
31 | 55.1M | Shift += 7; |
32 | 55.1M | } while (*p++ >= 128); |
33 | 49.2M | if (n) |
34 | 49.2M | *n = (unsigned)(p - orig_p); |
35 | 49.2M | return Value; |
36 | 49.2M | } ARMDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 19.1M | { | 26 | 19.1M | const uint8_t *orig_p = p; | 27 | 19.1M | uint64_t Value = 0; | 28 | 19.1M | unsigned Shift = 0; | 29 | 21.1M | do { | 30 | 21.1M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 21.1M | Shift += 7; | 32 | 21.1M | } while (*p++ >= 128); | 33 | 19.1M | if (n) | 34 | 19.1M | *n = (unsigned)(p - orig_p); | 35 | 19.1M | return Value; | 36 | 19.1M | } |
AArch64Disassembler.c:decodeULEB128 Line | Count | Source | 25 | 8.31M | { | 26 | 8.31M | const uint8_t *orig_p = p; | 27 | 8.31M | uint64_t Value = 0; | 28 | 8.31M | unsigned Shift = 0; | 29 | 9.10M | do { | 30 | 9.10M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 9.10M | Shift += 7; | 32 | 9.10M | } while (*p++ >= 128); | 33 | 8.31M | if (n) | 34 | 8.31M | *n = (unsigned)(p - orig_p); | 35 | 8.31M | return Value; | 36 | 8.31M | } |
MipsDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 3.25M | { | 26 | 3.25M | const uint8_t *orig_p = p; | 27 | 3.25M | uint64_t Value = 0; | 28 | 3.25M | unsigned Shift = 0; | 29 | 3.37M | do { | 30 | 3.37M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 3.37M | Shift += 7; | 32 | 3.37M | } while (*p++ >= 128); | 33 | 3.25M | if (n) | 34 | 3.25M | *n = (unsigned)(p - orig_p); | 35 | 3.25M | return Value; | 36 | 3.25M | } |
PPCDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 5.71M | { | 26 | 5.71M | const uint8_t *orig_p = p; | 27 | 5.71M | uint64_t Value = 0; | 28 | 5.71M | unsigned Shift = 0; | 29 | 5.93M | do { | 30 | 5.93M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 5.93M | Shift += 7; | 32 | 5.93M | } while (*p++ >= 128); | 33 | 5.71M | if (n) | 34 | 5.71M | *n = (unsigned)(p - orig_p); | 35 | 5.71M | return Value; | 36 | 5.71M | } |
SparcDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 1.90M | { | 26 | 1.90M | const uint8_t *orig_p = p; | 27 | 1.90M | uint64_t Value = 0; | 28 | 1.90M | unsigned Shift = 0; | 29 | 1.94M | do { | 30 | 1.94M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 1.94M | Shift += 7; | 32 | 1.94M | } while (*p++ >= 128); | 33 | 1.90M | if (n) | 34 | 1.90M | *n = (unsigned)(p - orig_p); | 35 | 1.90M | return Value; | 36 | 1.90M | } |
SystemZDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 6.29M | { | 26 | 6.29M | const uint8_t *orig_p = p; | 27 | 6.29M | uint64_t Value = 0; | 28 | 6.29M | unsigned Shift = 0; | 29 | 8.65M | do { | 30 | 8.65M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 8.65M | Shift += 7; | 32 | 8.65M | } while (*p++ >= 128); | 33 | 6.29M | if (n) | 34 | 6.29M | *n = (unsigned)(p - orig_p); | 35 | 6.29M | return Value; | 36 | 6.29M | } |
XCoreDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 727k | { | 26 | 727k | const uint8_t *orig_p = p; | 27 | 727k | uint64_t Value = 0; | 28 | 727k | unsigned Shift = 0; | 29 | 809k | do { | 30 | 809k | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 809k | Shift += 7; | 32 | 809k | } while (*p++ >= 128); | 33 | 727k | if (n) | 34 | 727k | *n = (unsigned)(p - orig_p); | 35 | 727k | return Value; | 36 | 727k | } |
TMS320C64xDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 1.07M | { | 26 | 1.07M | const uint8_t *orig_p = p; | 27 | 1.07M | uint64_t Value = 0; | 28 | 1.07M | unsigned Shift = 0; | 29 | 1.09M | do { | 30 | 1.09M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 1.09M | Shift += 7; | 32 | 1.09M | } while (*p++ >= 128); | 33 | 1.07M | if (n) | 34 | 1.07M | *n = (unsigned)(p - orig_p); | 35 | 1.07M | return Value; | 36 | 1.07M | } |
RISCVDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 2.87M | { | 26 | 2.87M | const uint8_t *orig_p = p; | 27 | 2.87M | uint64_t Value = 0; | 28 | 2.87M | unsigned Shift = 0; | 29 | 3.00M | do { | 30 | 3.00M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 3.00M | Shift += 7; | 32 | 3.00M | } while (*p++ >= 128); | 33 | 2.87M | if (n) | 34 | 2.87M | *n = (unsigned)(p - orig_p); | 35 | 2.87M | return Value; | 36 | 2.87M | } |
Unexecuted instantiation: TriCoreDisassembler.c:decodeULEB128 |
37 | | |
38 | | #endif // LLVM_SYSTEM_LEB128_H |