xref: /freebsd-src/contrib/llvm-project/llvm/include/llvm-c/Disassembler.h (revision 5b27928474e6a4103d65b347544705c40c9618fd)
10b57cec5SDimitry Andric /*===-- llvm-c/Disassembler.h - Disassembler Public C Interface ---*- C -*-===*\
20b57cec5SDimitry Andric |*                                                                            *|
30b57cec5SDimitry Andric |* Part of the LLVM Project, under the Apache License v2.0 with LLVM          *|
40b57cec5SDimitry Andric |* Exceptions.                                                                *|
50b57cec5SDimitry Andric |* See https://llvm.org/LICENSE.txt for license information.                  *|
60b57cec5SDimitry Andric |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    *|
70b57cec5SDimitry Andric |*                                                                            *|
80b57cec5SDimitry Andric |*===----------------------------------------------------------------------===*|
90b57cec5SDimitry Andric |*                                                                            *|
100b57cec5SDimitry Andric |* This header provides a public interface to a disassembler library.         *|
110b57cec5SDimitry Andric |* LLVM provides an implementation of this interface.                         *|
120b57cec5SDimitry Andric |*                                                                            *|
130b57cec5SDimitry Andric \*===----------------------------------------------------------------------===*/
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric #ifndef LLVM_C_DISASSEMBLER_H
160b57cec5SDimitry Andric #define LLVM_C_DISASSEMBLER_H
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric #include "llvm-c/DisassemblerTypes.h"
19*480093f4SDimitry Andric #include "llvm-c/ExternC.h"
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric /**
220b57cec5SDimitry Andric  * @defgroup LLVMCDisassembler Disassembler
230b57cec5SDimitry Andric  * @ingroup LLVMC
240b57cec5SDimitry Andric  *
250b57cec5SDimitry Andric  * @{
260b57cec5SDimitry Andric  */
270b57cec5SDimitry Andric 
28*480093f4SDimitry Andric LLVM_C_EXTERN_C_BEGIN
290b57cec5SDimitry Andric 
300b57cec5SDimitry Andric /**
310b57cec5SDimitry Andric  * Create a disassembler for the TripleName.  Symbolic disassembly is supported
320b57cec5SDimitry Andric  * by passing a block of information in the DisInfo parameter and specifying the
330b57cec5SDimitry Andric  * TagType and callback functions as described above.  These can all be passed
340b57cec5SDimitry Andric  * as NULL.  If successful, this returns a disassembler context.  If not, it
350b57cec5SDimitry Andric  * returns NULL. This function is equivalent to calling
360b57cec5SDimitry Andric  * LLVMCreateDisasmCPUFeatures() with an empty CPU name and feature set.
370b57cec5SDimitry Andric  */
380b57cec5SDimitry Andric LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo,
390b57cec5SDimitry Andric                                       int TagType, LLVMOpInfoCallback GetOpInfo,
400b57cec5SDimitry Andric                                       LLVMSymbolLookupCallback SymbolLookUp);
410b57cec5SDimitry Andric 
420b57cec5SDimitry Andric /**
430b57cec5SDimitry Andric  * Create a disassembler for the TripleName and a specific CPU.  Symbolic
440b57cec5SDimitry Andric  * disassembly is supported by passing a block of information in the DisInfo
450b57cec5SDimitry Andric  * parameter and specifying the TagType and callback functions as described
460b57cec5SDimitry Andric  * above.  These can all be passed * as NULL.  If successful, this returns a
470b57cec5SDimitry Andric  * disassembler context.  If not, it returns NULL. This function is equivalent
480b57cec5SDimitry Andric  * to calling LLVMCreateDisasmCPUFeatures() with an empty feature set.
490b57cec5SDimitry Andric  */
500b57cec5SDimitry Andric LLVMDisasmContextRef LLVMCreateDisasmCPU(const char *Triple, const char *CPU,
510b57cec5SDimitry Andric                                          void *DisInfo, int TagType,
520b57cec5SDimitry Andric                                          LLVMOpInfoCallback GetOpInfo,
530b57cec5SDimitry Andric                                          LLVMSymbolLookupCallback SymbolLookUp);
540b57cec5SDimitry Andric 
550b57cec5SDimitry Andric /**
560b57cec5SDimitry Andric  * Create a disassembler for the TripleName, a specific CPU and specific feature
570b57cec5SDimitry Andric  * string.  Symbolic disassembly is supported by passing a block of information
580b57cec5SDimitry Andric  * in the DisInfo parameter and specifying the TagType and callback functions as
590b57cec5SDimitry Andric  * described above.  These can all be passed * as NULL.  If successful, this
600b57cec5SDimitry Andric  * returns a disassembler context.  If not, it returns NULL.
610b57cec5SDimitry Andric  */
620b57cec5SDimitry Andric LLVMDisasmContextRef
630b57cec5SDimitry Andric LLVMCreateDisasmCPUFeatures(const char *Triple, const char *CPU,
640b57cec5SDimitry Andric                             const char *Features, void *DisInfo, int TagType,
650b57cec5SDimitry Andric                             LLVMOpInfoCallback GetOpInfo,
660b57cec5SDimitry Andric                             LLVMSymbolLookupCallback SymbolLookUp);
670b57cec5SDimitry Andric 
680b57cec5SDimitry Andric /**
690b57cec5SDimitry Andric  * Set the disassembler's options.  Returns 1 if it can set the Options and 0
700b57cec5SDimitry Andric  * otherwise.
710b57cec5SDimitry Andric  */
720b57cec5SDimitry Andric int LLVMSetDisasmOptions(LLVMDisasmContextRef DC, uint64_t Options);
730b57cec5SDimitry Andric 
740b57cec5SDimitry Andric /* The option to produce marked up assembly. */
750b57cec5SDimitry Andric #define LLVMDisassembler_Option_UseMarkup 1
760b57cec5SDimitry Andric /* The option to print immediates as hex. */
770b57cec5SDimitry Andric #define LLVMDisassembler_Option_PrintImmHex 2
780b57cec5SDimitry Andric /* The option use the other assembler printer variant */
790b57cec5SDimitry Andric #define LLVMDisassembler_Option_AsmPrinterVariant 4
800b57cec5SDimitry Andric /* The option to set comment on instructions */
810b57cec5SDimitry Andric #define LLVMDisassembler_Option_SetInstrComments 8
820b57cec5SDimitry Andric   /* The option to print latency information alongside instructions */
830b57cec5SDimitry Andric #define LLVMDisassembler_Option_PrintLatency 16
840b57cec5SDimitry Andric 
850b57cec5SDimitry Andric /**
860b57cec5SDimitry Andric  * Dispose of a disassembler context.
870b57cec5SDimitry Andric  */
880b57cec5SDimitry Andric void LLVMDisasmDispose(LLVMDisasmContextRef DC);
890b57cec5SDimitry Andric 
900b57cec5SDimitry Andric /**
910b57cec5SDimitry Andric  * Disassemble a single instruction using the disassembler context specified in
920b57cec5SDimitry Andric  * the parameter DC.  The bytes of the instruction are specified in the
930b57cec5SDimitry Andric  * parameter Bytes, and contains at least BytesSize number of bytes.  The
940b57cec5SDimitry Andric  * instruction is at the address specified by the PC parameter.  If a valid
950b57cec5SDimitry Andric  * instruction can be disassembled, its string is returned indirectly in
960b57cec5SDimitry Andric  * OutString whose size is specified in the parameter OutStringSize.  This
970b57cec5SDimitry Andric  * function returns the number of bytes in the instruction or zero if there was
980b57cec5SDimitry Andric  * no valid instruction.
990b57cec5SDimitry Andric  */
1000b57cec5SDimitry Andric size_t LLVMDisasmInstruction(LLVMDisasmContextRef DC, uint8_t *Bytes,
1010b57cec5SDimitry Andric                              uint64_t BytesSize, uint64_t PC,
1020b57cec5SDimitry Andric                              char *OutString, size_t OutStringSize);
1030b57cec5SDimitry Andric 
1040b57cec5SDimitry Andric /**
1050b57cec5SDimitry Andric  * @}
1060b57cec5SDimitry Andric  */
1070b57cec5SDimitry Andric 
108*480093f4SDimitry Andric LLVM_C_EXTERN_C_END
1090b57cec5SDimitry Andric 
1100b57cec5SDimitry Andric #endif /* LLVM_C_DISASSEMBLER_H */
111