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 | 53.0M | { |
26 | 53.0M | const uint8_t *orig_p = p; |
27 | 53.0M | uint64_t Value = 0; |
28 | 53.0M | unsigned Shift = 0; |
29 | 59.4M | do { |
30 | 59.4M | Value += (uint64_t)(*p & 0x7f) << Shift; |
31 | 59.4M | Shift += 7; |
32 | 59.4M | } while (*p++ >= 128); |
33 | 53.0M | if (n) |
34 | 53.0M | *n = (unsigned)(p - orig_p); |
35 | 53.0M | return Value; |
36 | 53.0M | } ARMDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 18.2M | { | 26 | 18.2M | const uint8_t *orig_p = p; | 27 | 18.2M | uint64_t Value = 0; | 28 | 18.2M | unsigned Shift = 0; | 29 | 20.1M | do { | 30 | 20.1M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 20.1M | Shift += 7; | 32 | 20.1M | } while (*p++ >= 128); | 33 | 18.2M | if (n) | 34 | 18.2M | *n = (unsigned)(p - orig_p); | 35 | 18.2M | return Value; | 36 | 18.2M | } |
AArch64Disassembler.c:decodeULEB128 Line | Count | Source | 25 | 9.84M | { | 26 | 9.84M | const uint8_t *orig_p = p; | 27 | 9.84M | uint64_t Value = 0; | 28 | 9.84M | unsigned Shift = 0; | 29 | 10.7M | do { | 30 | 10.7M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 10.7M | Shift += 7; | 32 | 10.7M | } while (*p++ >= 128); | 33 | 9.84M | if (n) | 34 | 9.84M | *n = (unsigned)(p - orig_p); | 35 | 9.84M | return Value; | 36 | 9.84M | } |
MipsDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 3.52M | { | 26 | 3.52M | const uint8_t *orig_p = p; | 27 | 3.52M | uint64_t Value = 0; | 28 | 3.52M | unsigned Shift = 0; | 29 | 3.65M | do { | 30 | 3.65M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 3.65M | Shift += 7; | 32 | 3.65M | } while (*p++ >= 128); | 33 | 3.52M | if (n) | 34 | 3.52M | *n = (unsigned)(p - orig_p); | 35 | 3.52M | return Value; | 36 | 3.52M | } |
PPCDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 6.13M | { | 26 | 6.13M | const uint8_t *orig_p = p; | 27 | 6.13M | uint64_t Value = 0; | 28 | 6.13M | unsigned Shift = 0; | 29 | 6.38M | do { | 30 | 6.38M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 6.38M | Shift += 7; | 32 | 6.38M | } while (*p++ >= 128); | 33 | 6.13M | if (n) | 34 | 6.13M | *n = (unsigned)(p - orig_p); | 35 | 6.13M | return Value; | 36 | 6.13M | } |
SparcDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 2.02M | { | 26 | 2.02M | const uint8_t *orig_p = p; | 27 | 2.02M | uint64_t Value = 0; | 28 | 2.02M | unsigned Shift = 0; | 29 | 2.06M | do { | 30 | 2.06M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 2.06M | Shift += 7; | 32 | 2.06M | } while (*p++ >= 128); | 33 | 2.02M | if (n) | 34 | 2.02M | *n = (unsigned)(p - orig_p); | 35 | 2.02M | return Value; | 36 | 2.02M | } |
SystemZDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 7.33M | { | 26 | 7.33M | const uint8_t *orig_p = p; | 27 | 7.33M | uint64_t Value = 0; | 28 | 7.33M | unsigned Shift = 0; | 29 | 10.2M | do { | 30 | 10.2M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 10.2M | Shift += 7; | 32 | 10.2M | } while (*p++ >= 128); | 33 | 7.33M | if (n) | 34 | 7.33M | *n = (unsigned)(p - orig_p); | 35 | 7.33M | return Value; | 36 | 7.33M | } |
XCoreDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 797k | { | 26 | 797k | const uint8_t *orig_p = p; | 27 | 797k | uint64_t Value = 0; | 28 | 797k | unsigned Shift = 0; | 29 | 880k | do { | 30 | 880k | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 880k | Shift += 7; | 32 | 880k | } while (*p++ >= 128); | 33 | 797k | if (n) | 34 | 797k | *n = (unsigned)(p - orig_p); | 35 | 797k | return Value; | 36 | 797k | } |
TMS320C64xDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 1.01M | { | 26 | 1.01M | const uint8_t *orig_p = p; | 27 | 1.01M | uint64_t Value = 0; | 28 | 1.01M | unsigned Shift = 0; | 29 | 1.03M | do { | 30 | 1.03M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 1.03M | Shift += 7; | 32 | 1.03M | } while (*p++ >= 128); | 33 | 1.01M | if (n) | 34 | 1.01M | *n = (unsigned)(p - orig_p); | 35 | 1.01M | return Value; | 36 | 1.01M | } |
RISCVDisassembler.c:decodeULEB128 Line | Count | Source | 25 | 4.10M | { | 26 | 4.10M | const uint8_t *orig_p = p; | 27 | 4.10M | uint64_t Value = 0; | 28 | 4.10M | unsigned Shift = 0; | 29 | 4.28M | do { | 30 | 4.28M | Value += (uint64_t)(*p & 0x7f) << Shift; | 31 | 4.28M | Shift += 7; | 32 | 4.28M | } while (*p++ >= 128); | 33 | 4.10M | if (n) | 34 | 4.10M | *n = (unsigned)(p - orig_p); | 35 | 4.10M | return Value; | 36 | 4.10M | } |
Unexecuted instantiation: TriCoreDisassembler.c:decodeULEB128 |
37 | | |
38 | | #endif // LLVM_SYSTEM_LEB128_H |