blob: b1cb35da6687a8f4cdcb198cf4e4dc9a85e466b9 [file] [log] [blame]
Kevin Enderbyf3070dc2011-03-28 18:25:07 +00001/*===-- llvm-c/Disassembler.h - Disassembler Public C Interface ---*- C -*-===*\
2|* *|
Chandler Carruth2946cd72019-01-19 08:50:56 +00003|* 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 Enderbyf3070dc2011-03-28 18:25:07 +00007|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
Chris Lattnere8bf2d52011-05-22 04:44:48 +000010|* This header provides a public interface to a disassembler library. *|
Kevin Enderbyf3070dc2011-03-28 18:25:07 +000011|* LLVM provides an implementation of this interface. *|
12|* *|
13\*===----------------------------------------------------------------------===*/
14
15#ifndef LLVM_C_DISASSEMBLER_H
Chris Lattnere8bf2d52011-05-22 04:44:48 +000016#define LLVM_C_DISASSEMBLER_H
Kevin Enderbyf3070dc2011-03-28 18:25:07 +000017
David Blaikie3d94e9f2018-03-29 00:29:44 +000018#include "llvm-c/DisassemblerTypes.h"
Duncan P. N. Exon Smith8c484052019-11-14 13:57:57 -080019#include "llvm-c/ExternC.h"
Kevin Enderbyf3070dc2011-03-28 18:25:07 +000020
21/**
Gregory Szorc34c863a2012-03-21 03:54:29 +000022 * @defgroup LLVMCDisassembler Disassembler
23 * @ingroup LLVMC
24 *
25 * @{
26 */
27
Duncan P. N. Exon Smith8c484052019-11-14 13:57:57 -080028LLVM_C_EXTERN_C_BEGIN
Kevin Enderbyf3070dc2011-03-28 18:25:07 +000029
30/**
31 * Create a disassembler for the TripleName. Symbolic disassembly is supported
Chris Lattnere8bf2d52011-05-22 04:44:48 +000032 * by passing a block of information in the DisInfo parameter and specifying the
33 * TagType and callback functions as described above. These can all be passed
34 * as NULL. If successful, this returns a disassembler context. If not, it
Bradley Smith7a770752014-09-30 16:31:40 +000035 * returns NULL. This function is equivalent to calling
36 * LLVMCreateDisasmCPUFeatures() with an empty CPU name and feature set.
Kevin Enderbyf3070dc2011-03-28 18:25:07 +000037 */
Chris Lattnere8bf2d52011-05-22 04:44:48 +000038LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo,
39 int TagType, LLVMOpInfoCallback GetOpInfo,
40 LLVMSymbolLookupCallback SymbolLookUp);
Kevin Enderbyf3070dc2011-03-28 18:25:07 +000041
42/**
Jim Grosbach0ca9d5b2012-12-07 23:53:27 +000043 * Create a disassembler for the TripleName and a specific CPU. Symbolic
44 * disassembly is supported by passing a block of information in the DisInfo
45 * parameter and specifying the TagType and callback functions as described
46 * above. These can all be passed * as NULL. If successful, this returns a
Bradley Smith7a770752014-09-30 16:31:40 +000047 * disassembler context. If not, it returns NULL. This function is equivalent
48 * to calling LLVMCreateDisasmCPUFeatures() with an empty feature set.
Jim Grosbach0ca9d5b2012-12-07 23:53:27 +000049 */
50LLVMDisasmContextRef LLVMCreateDisasmCPU(const char *Triple, const char *CPU,
51 void *DisInfo, int TagType,
52 LLVMOpInfoCallback GetOpInfo,
53 LLVMSymbolLookupCallback SymbolLookUp);
54
55/**
Bradley Smith7a770752014-09-30 16:31:40 +000056 * Create a disassembler for the TripleName, a specific CPU and specific feature
57 * string. Symbolic disassembly is supported by passing a block of information
58 * in the DisInfo parameter and specifying the TagType and callback functions as
59 * described above. These can all be passed * as NULL. If successful, this
60 * returns a disassembler context. If not, it returns NULL.
61 */
62LLVMDisasmContextRef
63LLVMCreateDisasmCPUFeatures(const char *Triple, const char *CPU,
64 const char *Features, void *DisInfo, int TagType,
65 LLVMOpInfoCallback GetOpInfo,
66 LLVMSymbolLookupCallback SymbolLookUp);
67
68/**
Kevin Enderby62183c42012-10-22 22:31:46 +000069 * Set the disassembler's options. Returns 1 if it can set the Options and 0
70 * otherwise.
71 */
72int LLVMSetDisasmOptions(LLVMDisasmContextRef DC, uint64_t Options);
73
74/* The option to produce marked up assembly. */
75#define LLVMDisassembler_Option_UseMarkup 1
Kevin Enderby168ffb32012-12-05 18:13:19 +000076/* The option to print immediates as hex. */
77#define LLVMDisassembler_Option_PrintImmHex 2
Kevin Enderby85cf5312012-12-18 23:47:28 +000078/* The option use the other assembler printer variant */
79#define LLVMDisassembler_Option_AsmPrinterVariant 4
Quentin Colombet93a98aa2013-10-01 22:14:56 +000080/* The option to set comment on instructions */
81#define LLVMDisassembler_Option_SetInstrComments 8
Quentin Colombet5f09cb02013-10-02 22:07:57 +000082 /* The option to print latency information alongside instructions */
83#define LLVMDisassembler_Option_PrintLatency 16
Kevin Enderby62183c42012-10-22 22:31:46 +000084
85/**
Kevin Enderbyf3070dc2011-03-28 18:25:07 +000086 * Dispose of a disassembler context.
87 */
Chris Lattnere8bf2d52011-05-22 04:44:48 +000088void LLVMDisasmDispose(LLVMDisasmContextRef DC);
Kevin Enderbyf3070dc2011-03-28 18:25:07 +000089
90/**
Chris Lattnere8bf2d52011-05-22 04:44:48 +000091 * Disassemble a single instruction using the disassembler context specified in
92 * the parameter DC. The bytes of the instruction are specified in the
93 * parameter Bytes, and contains at least BytesSize number of bytes. The
94 * instruction is at the address specified by the PC parameter. If a valid
95 * instruction can be disassembled, its string is returned indirectly in
96 * OutString whose size is specified in the parameter OutStringSize. This
97 * function returns the number of bytes in the instruction or zero if there was
98 * no valid instruction.
Kevin Enderbyf3070dc2011-03-28 18:25:07 +000099 */
Chris Lattnere8bf2d52011-05-22 04:44:48 +0000100size_t LLVMDisasmInstruction(LLVMDisasmContextRef DC, uint8_t *Bytes,
101 uint64_t BytesSize, uint64_t PC,
102 char *OutString, size_t OutStringSize);
Kevin Enderbyf3070dc2011-03-28 18:25:07 +0000103
Gregory Szorc34c863a2012-03-21 03:54:29 +0000104/**
105 * @}
106 */
107
Duncan P. N. Exon Smith8c484052019-11-14 13:57:57 -0800108LLVM_C_EXTERN_C_END
Kevin Enderbyf3070dc2011-03-28 18:25:07 +0000109
Eugene Zelenko35623fb2016-03-28 17:40:08 +0000110#endif /* LLVM_C_DISASSEMBLER_H */