809
[darwin-xtools.git] / cctools / include / llvm-c / Disassembler.h
blob32d68c6cc5c4de0b6e8532cad302e0d958a8af65
1 /*===-- llvm-c/Disassembler.h - Disassembler Public C Interface ---*- 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 header provides public interface to a disassembler library. *|
11 |* LLVM provides an implementation of this interface. *|
12 |* *|
13 \*===----------------------------------------------------------------------===*/
15 #ifndef LLVM_C_DISASSEMBLER_H
16 #define LLVM_C_DISASSEMBLER_H 1
18 #include <stddef.h>
20 /**
21 * An opaque reference to a disassembler context.
23 typedef void *LLVMDisasmContextRef;
25 /**
26 * The type for the operand information call back function. This is called to
27 * get the symbolic information for an operand of an instruction. Typically
28 * this is from the relocation information, symbol table, etc. That block of
29 * information is saved when the disassembler context is created and passed to
30 * the call back in the DisInfo parameter. The instruction containing operand
31 * is at the PC parameter. For some instruction sets, there can be more than
32 * one operand with symbolic information. To determine the symbolic operand
33 * infomation for each operand, the bytes for the specific operand in the
34 * instruction are specified by the Offset parameter and its byte widith is the
35 * size parameter. For instructions sets with fixed widths and one symbolic
36 * operand per instruction, the Offset parameter will be zero and Size parameter
37 * will be the instruction width. The information is returned in TagBuf and is
38 * Triple specific with its specific information defined by the value of
39 * TagType for that Triple. If symbolic information is returned the function
40 * returns 1 else it returns 0.
42 typedef int (*LLVMOpInfoCallback)(void *DisInfo,
43 uint64_t Pc,
44 uint64_t Offset,
45 uint64_t Size,
46 int TagType,
47 void *TagBuf);
49 /**
50 * The initial support in LLVM MC for the most general form of a relocatable
51 * expression is "AddSymbol - SubtractSymbol + Offset". For some Darwin targets
52 * this full form is encoded in the relocation information so that AddSymbol and
53 * SubtractSymbol can be link edited independent of each other. Many other
54 * platforms only allow a relocatable expression of the form AddSymbol + Offset
55 * to be encoded.
57 * The LLVMOpInfoCallback() for the TagType value of 1 uses the struct
58 * LLVMOpInfo1. The value of the relocatable expression for the operand,
59 * including any PC adjustment, is passed in to the call back in the Value
60 * field. The symbolic information about the operand is returned using all
61 * the fields of the structure with the Offset of the relocatable expression
62 * returned in the Value field. It is possible that some symbols in the
63 * relocatable expression were assembly temporary symbols, for example
64 * "Ldata - LpicBase + constant", and only the Values of the symbols without
65 * symbol names are present in the relocation information. The VariantKind
66 * type is one of the Target specific #defines below and is used to print
67 * operands like "_foo@GOT", ":lower16:_foo", etc.
69 struct LLVMOpInfoSymbol1 {
70 uint64_t Present; /* 1 if this symbol is present */
71 const char *Name; /* symbol name if not NULL */
72 uint64_t Value; /* symbol value if name is NULL */
74 struct LLVMOpInfo1 {
75 struct LLVMOpInfoSymbol1 AddSymbol;
76 struct LLVMOpInfoSymbol1 SubtractSymbol;
77 uint64_t Value;
78 uint64_t VariantKind;
81 /**
82 * The operand VariantKinds for symbolic disassembly.
84 #define LLVMDisassembler_VariantKind_None 0 /* all targets */
86 /**
87 * The ARM target VariantKinds.
89 #define LLVMDisassembler_VariantKind_ARM_HI16 1 /* :upper16: */
90 #define LLVMDisassembler_VariantKind_ARM_LO16 2 /* :lower16: */
92 /**
93 * The type for the symbol lookup function. This may be called by the
94 * disassembler for such things like adding a comment for a PC plus a constant
95 * offset load instruction to use a symbol name instead of a load address value.
96 * It is passed the block information is saved when the disassembler context is
97 * created and a value of a symbol to look up. If no symbol is found NULL is
98 * to be returned.
100 typedef const char *(*LLVMSymbolLookupCallback)(void *DisInfo,
101 uint64_t SymbolValue);
103 #ifdef __cplusplus
104 extern "C" {
105 #endif /* !defined(__cplusplus) */
108 * Create a disassembler for the TripleName. Symbolic disassembly is supported
109 * by passing a block of information in the DisInfo parameter and specifing the
110 * TagType and call back functions as described above. These can all be passed
111 * as NULL. If successfull this returns a disassembler context if not it
112 * returns NULL.
114 extern LLVMDisasmContextRef
115 LLVMCreateDisasm(const char *TripleName,
116 void *DisInfo,
117 int TagType,
118 LLVMOpInfoCallback GetOpInfo,
119 LLVMSymbolLookupCallback SymbolLookUp);
122 * Dispose of a disassembler context.
124 extern void
125 LLVMDisasmDispose(LLVMDisasmContextRef DC);
128 * Disassmble a single instruction using the disassembler context specified in
129 * the parameter DC. The bytes of the instuction are specified in the parameter
130 * Bytes, and contains at least BytesSize number of bytes. The instruction is
131 * at the address specified by the PC parameter. If a valid instruction can be
132 * disassembled its string is returned indirectly in OutString which whos size
133 * is specified in the parameter OutStringSize. This function returns the
134 * number of bytes in the instruction or zero if there was no valid instruction.
136 extern size_t
137 LLVMDisasmInstruction(LLVMDisasmContextRef DC,
138 uint8_t *Bytes,
139 uint64_t BytesSize,
140 uint64_t Pc,
141 char *OutString,
142 size_t OutStringSize);
144 #ifdef __cplusplus
146 #endif /* !defined(__cplusplus) */
148 #endif /* !defined(LLVM_C_DISASSEMBLER_H) */