Kevin Enderby | f3070dc | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 1 | /*===-- llvm-c/Disassembler.h - Disassembler Public C Interface ---*- C -*-===*\ |
| 2 | |* *| |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 3 | |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| |
| 4 | |* Exceptions. *| |
| 5 | |* See https://llvm.org/LICENSE.txt for license information. *| |
| 6 | |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| |
Kevin Enderby | f3070dc | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 7 | |* *| |
| 8 | |*===----------------------------------------------------------------------===*| |
| 9 | |* *| |
Chris Lattner | e8bf2d5 | 2011-05-22 04:44:48 +0000 | [diff] [blame] | 10 | |* This header provides a public interface to a disassembler library. *| |
Kevin Enderby | f3070dc | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 11 | |* LLVM provides an implementation of this interface. *| |
| 12 | |* *| |
| 13 | \*===----------------------------------------------------------------------===*/ |
| 14 | |
| 15 | #ifndef LLVM_C_DISASSEMBLER_H |
Chris Lattner | e8bf2d5 | 2011-05-22 04:44:48 +0000 | [diff] [blame] | 16 | #define LLVM_C_DISASSEMBLER_H |
Kevin Enderby | f3070dc | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 17 | |
David Blaikie | 3d94e9f | 2018-03-29 00:29:44 +0000 | [diff] [blame] | 18 | #include "llvm-c/DisassemblerTypes.h" |
Kevin Enderby | f3070dc | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 19 | |
| 20 | /** |
Gregory Szorc | 34c863a | 2012-03-21 03:54:29 +0000 | [diff] [blame] | 21 | * @defgroup LLVMCDisassembler Disassembler |
| 22 | * @ingroup LLVMC |
| 23 | * |
| 24 | * @{ |
| 25 | */ |
| 26 | |
Kevin Enderby | f3070dc | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 27 | #ifdef __cplusplus |
| 28 | extern "C" { |
| 29 | #endif /* !defined(__cplusplus) */ |
| 30 | |
| 31 | /** |
| 32 | * Create a disassembler for the TripleName. Symbolic disassembly is supported |
Chris Lattner | e8bf2d5 | 2011-05-22 04:44:48 +0000 | [diff] [blame] | 33 | * by passing a block of information in the DisInfo parameter and specifying the |
| 34 | * TagType and callback functions as described above. These can all be passed |
| 35 | * as NULL. If successful, this returns a disassembler context. If not, it |
Bradley Smith | 7a77075 | 2014-09-30 16:31:40 +0000 | [diff] [blame] | 36 | * returns NULL. This function is equivalent to calling |
| 37 | * LLVMCreateDisasmCPUFeatures() with an empty CPU name and feature set. |
Kevin Enderby | f3070dc | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 38 | */ |
Chris Lattner | e8bf2d5 | 2011-05-22 04:44:48 +0000 | [diff] [blame] | 39 | LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo, |
| 40 | int TagType, LLVMOpInfoCallback GetOpInfo, |
| 41 | LLVMSymbolLookupCallback SymbolLookUp); |
Kevin Enderby | f3070dc | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 42 | |
| 43 | /** |
Jim Grosbach | 0ca9d5b | 2012-12-07 23:53:27 +0000 | [diff] [blame] | 44 | * Create a disassembler for the TripleName and a specific CPU. Symbolic |
| 45 | * disassembly is supported by passing a block of information in the DisInfo |
| 46 | * parameter and specifying the TagType and callback functions as described |
| 47 | * above. These can all be passed * as NULL. If successful, this returns a |
Bradley Smith | 7a77075 | 2014-09-30 16:31:40 +0000 | [diff] [blame] | 48 | * disassembler context. If not, it returns NULL. This function is equivalent |
| 49 | * to calling LLVMCreateDisasmCPUFeatures() with an empty feature set. |
Jim Grosbach | 0ca9d5b | 2012-12-07 23:53:27 +0000 | [diff] [blame] | 50 | */ |
| 51 | LLVMDisasmContextRef LLVMCreateDisasmCPU(const char *Triple, const char *CPU, |
| 52 | void *DisInfo, int TagType, |
| 53 | LLVMOpInfoCallback GetOpInfo, |
| 54 | LLVMSymbolLookupCallback SymbolLookUp); |
| 55 | |
| 56 | /** |
Bradley Smith | 7a77075 | 2014-09-30 16:31:40 +0000 | [diff] [blame] | 57 | * Create a disassembler for the TripleName, a specific CPU and specific feature |
| 58 | * string. Symbolic disassembly is supported by passing a block of information |
| 59 | * in the DisInfo parameter and specifying the TagType and callback functions as |
| 60 | * described above. These can all be passed * as NULL. If successful, this |
| 61 | * returns a disassembler context. If not, it returns NULL. |
| 62 | */ |
| 63 | LLVMDisasmContextRef |
| 64 | LLVMCreateDisasmCPUFeatures(const char *Triple, const char *CPU, |
| 65 | const char *Features, void *DisInfo, int TagType, |
| 66 | LLVMOpInfoCallback GetOpInfo, |
| 67 | LLVMSymbolLookupCallback SymbolLookUp); |
| 68 | |
| 69 | /** |
Kevin Enderby | 62183c4 | 2012-10-22 22:31:46 +0000 | [diff] [blame] | 70 | * Set the disassembler's options. Returns 1 if it can set the Options and 0 |
| 71 | * otherwise. |
| 72 | */ |
| 73 | int LLVMSetDisasmOptions(LLVMDisasmContextRef DC, uint64_t Options); |
| 74 | |
| 75 | /* The option to produce marked up assembly. */ |
| 76 | #define LLVMDisassembler_Option_UseMarkup 1 |
Kevin Enderby | 168ffb3 | 2012-12-05 18:13:19 +0000 | [diff] [blame] | 77 | /* The option to print immediates as hex. */ |
| 78 | #define LLVMDisassembler_Option_PrintImmHex 2 |
Kevin Enderby | 85cf531 | 2012-12-18 23:47:28 +0000 | [diff] [blame] | 79 | /* The option use the other assembler printer variant */ |
| 80 | #define LLVMDisassembler_Option_AsmPrinterVariant 4 |
Quentin Colombet | 93a98aa | 2013-10-01 22:14:56 +0000 | [diff] [blame] | 81 | /* The option to set comment on instructions */ |
| 82 | #define LLVMDisassembler_Option_SetInstrComments 8 |
Quentin Colombet | 5f09cb0 | 2013-10-02 22:07:57 +0000 | [diff] [blame] | 83 | /* The option to print latency information alongside instructions */ |
| 84 | #define LLVMDisassembler_Option_PrintLatency 16 |
Kevin Enderby | 62183c4 | 2012-10-22 22:31:46 +0000 | [diff] [blame] | 85 | |
| 86 | /** |
Kevin Enderby | f3070dc | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 87 | * Dispose of a disassembler context. |
| 88 | */ |
Chris Lattner | e8bf2d5 | 2011-05-22 04:44:48 +0000 | [diff] [blame] | 89 | void LLVMDisasmDispose(LLVMDisasmContextRef DC); |
Kevin Enderby | f3070dc | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 90 | |
| 91 | /** |
Chris Lattner | e8bf2d5 | 2011-05-22 04:44:48 +0000 | [diff] [blame] | 92 | * Disassemble a single instruction using the disassembler context specified in |
| 93 | * the parameter DC. The bytes of the instruction are specified in the |
| 94 | * parameter Bytes, and contains at least BytesSize number of bytes. The |
| 95 | * instruction is at the address specified by the PC parameter. If a valid |
| 96 | * instruction can be disassembled, its string is returned indirectly in |
| 97 | * OutString whose size is specified in the parameter OutStringSize. This |
| 98 | * function returns the number of bytes in the instruction or zero if there was |
| 99 | * no valid instruction. |
Kevin Enderby | f3070dc | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 100 | */ |
Chris Lattner | e8bf2d5 | 2011-05-22 04:44:48 +0000 | [diff] [blame] | 101 | size_t LLVMDisasmInstruction(LLVMDisasmContextRef DC, uint8_t *Bytes, |
| 102 | uint64_t BytesSize, uint64_t PC, |
| 103 | char *OutString, size_t OutStringSize); |
Kevin Enderby | f3070dc | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 104 | |
Gregory Szorc | 34c863a | 2012-03-21 03:54:29 +0000 | [diff] [blame] | 105 | /** |
| 106 | * @} |
| 107 | */ |
| 108 | |
Kevin Enderby | f3070dc | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 109 | #ifdef __cplusplus |
| 110 | } |
| 111 | #endif /* !defined(__cplusplus) */ |
| 112 | |
Eugene Zelenko | 35623fb | 2016-03-28 17:40:08 +0000 | [diff] [blame] | 113 | #endif /* LLVM_C_DISASSEMBLER_H */ |