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 | 45.0M | { |
26 | 45.0M | const uint8_t *orig_p = p; |
27 | 45.0M | uint64_t Value = 0; |
28 | 45.0M | unsigned Shift = 0; |
29 | 50.1M | do { |
30 | 50.1M | Value += (uint64_t)(*p & 0x7f) << Shift; |
31 | 50.1M | Shift += 7; |
32 | 50.1M | } while (*p++ >= 128); |
33 | 45.0M | if (n) |
34 | 45.0M | *n = (unsigned)(p - orig_p); |
35 | 45.0M | return Value; |
36 | 45.0M | } 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.2M | do { | 30 | 21.2M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 21.2M | Shift += 7; | 32 | 21.2M | } 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 | 7.38M | { | 26 | 7.38M | const uint8_t *orig_p = p; | 27 | 7.38M | uint64_t Value = 0; | 28 | 7.38M | unsigned Shift = 0; | 29 | 8.09M | do { | 30 | 8.09M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 8.09M | Shift += 7; | 32 | 8.09M | } while (*p++ >= 128); | 33 | 7.38M | if (n) | 34 | 7.38M | *n = (unsigned)(p - orig_p); | 35 | 7.38M | return Value; | 36 | 7.38M | } |
MipsDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 2.92M | { | 26 | 2.92M | const uint8_t *orig_p = p; | 27 | 2.92M | uint64_t Value = 0; | 28 | 2.92M | unsigned Shift = 0; | 29 | 3.02M | do { | 30 | 3.02M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 3.02M | Shift += 7; | 32 | 3.02M | } while (*p++ >= 128); | 33 | 2.92M | if (n) | 34 | 2.92M | *n = (unsigned)(p - orig_p); | 35 | 2.92M | return Value; | 36 | 2.92M | } |
PPCDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 5.16M | { | 26 | 5.16M | const uint8_t *orig_p = p; | 27 | 5.16M | uint64_t Value = 0; | 28 | 5.16M | unsigned Shift = 0; | 29 | 5.37M | do { | 30 | 5.37M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 5.37M | Shift += 7; | 32 | 5.37M | } while (*p++ >= 128); | 33 | 5.16M | if (n) | 34 | 5.16M | *n = (unsigned)(p - orig_p); | 35 | 5.16M | return Value; | 36 | 5.16M | } |
SparcDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 1.67M | { | 26 | 1.67M | const uint8_t *orig_p = p; | 27 | 1.67M | uint64_t Value = 0; | 28 | 1.67M | unsigned Shift = 0; | 29 | 1.70M | do { | 30 | 1.70M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 1.70M | Shift += 7; | 32 | 1.70M | } while (*p++ >= 128); | 33 | 1.67M | if (n) | 34 | 1.67M | *n = (unsigned)(p - orig_p); | 35 | 1.67M | return Value; | 36 | 1.67M | } |
SystemZDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 4.77M | { | 26 | 4.77M | const uint8_t *orig_p = p; | 27 | 4.77M | uint64_t Value = 0; | 28 | 4.77M | unsigned Shift = 0; | 29 | 6.57M | do { | 30 | 6.57M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 6.57M | Shift += 7; | 32 | 6.57M | } while (*p++ >= 128); | 33 | 4.77M | if (n) | 34 | 4.77M | *n = (unsigned)(p - orig_p); | 35 | 4.77M | return Value; | 36 | 4.77M | } |
XCoreDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 915k | { | 26 | 915k | const uint8_t *orig_p = p; | 27 | 915k | uint64_t Value = 0; | 28 | 915k | unsigned Shift = 0; | 29 | 1.00M | do { | 30 | 1.00M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 1.00M | Shift += 7; | 32 | 1.00M | } while (*p++ >= 128); | 33 | 915k | if (n) | 34 | 915k | *n = (unsigned)(p - orig_p); | 35 | 915k | return Value; | 36 | 915k | } |
TMS320C64xDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 940k | { | 26 | 940k | const uint8_t *orig_p = p; | 27 | 940k | uint64_t Value = 0; | 28 | 940k | unsigned Shift = 0; | 29 | 963k | do { | 30 | 963k | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 963k | Shift += 7; | 32 | 963k | } while (*p++ >= 128); | 33 | 940k | if (n) | 34 | 940k | *n = (unsigned)(p - orig_p); | 35 | 940k | return Value; | 36 | 940k | } |
RISCVDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 2.11M | { | 26 | 2.11M | const uint8_t *orig_p = p; | 27 | 2.11M | uint64_t Value = 0; | 28 | 2.11M | unsigned Shift = 0; | 29 | 2.20M | do { | 30 | 2.20M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 2.20M | Shift += 7; | 32 | 2.20M | } while (*p++ >= 128); | 33 | 2.11M | if (n) | 34 | 2.11M | *n = (unsigned)(p - orig_p); | 35 | 2.11M | return Value; | 36 | 2.11M | } |
Unexecuted instantiation: TriCoreDisassembler.c:decodeULEB128 |
37 | | |
38 | | #endif // LLVM_SYSTEM_LEB128_H |