/3rd_party/llvm/include/llvm-c/Disassembler.h

https://code.google.com/p/softart/ · C Header · 216 lines · 62 code · 23 blank · 131 comment · 0 complexity · 003915490597298aa308027172ab3e8e MD5 · raw file

  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 a public interface to a disassembler library. *|
  11. |* LLVM provides an implementation of this interface. *|
  12. |* *|
  13. \*===----------------------------------------------------------------------===*/
  14. #ifndef LLVM_C_DISASSEMBLER_H
  15. #define LLVM_C_DISASSEMBLER_H
  16. #include "llvm/Support/DataTypes.h"
  17. #include <stddef.h>
  18. /**
  19. * @defgroup LLVMCDisassembler Disassembler
  20. * @ingroup LLVMC
  21. *
  22. * @{
  23. */
  24. /**
  25. * An opaque reference to a disassembler context.
  26. */
  27. typedef void *LLVMDisasmContextRef;
  28. /**
  29. * The type for the operand information call back function. This is called to
  30. * get the symbolic information for an operand of an instruction. Typically
  31. * this is from the relocation information, symbol table, etc. That block of
  32. * information is saved when the disassembler context is created and passed to
  33. * the call back in the DisInfo parameter. The instruction containing operand
  34. * is at the PC parameter. For some instruction sets, there can be more than
  35. * one operand with symbolic information. To determine the symbolic operand
  36. * information for each operand, the bytes for the specific operand in the
  37. * instruction are specified by the Offset parameter and its byte widith is the
  38. * size parameter. For instructions sets with fixed widths and one symbolic
  39. * operand per instruction, the Offset parameter will be zero and Size parameter
  40. * will be the instruction width. The information is returned in TagBuf and is
  41. * Triple specific with its specific information defined by the value of
  42. * TagType for that Triple. If symbolic information is returned the function
  43. * returns 1, otherwise it returns 0.
  44. */
  45. typedef int (*LLVMOpInfoCallback)(void *DisInfo, uint64_t PC,
  46. uint64_t Offset, uint64_t Size,
  47. int TagType, void *TagBuf);
  48. /**
  49. * The initial support in LLVM MC for the most general form of a relocatable
  50. * expression is "AddSymbol - SubtractSymbol + Offset". For some Darwin targets
  51. * this full form is encoded in the relocation information so that AddSymbol and
  52. * SubtractSymbol can be link edited independent of each other. Many other
  53. * platforms only allow a relocatable expression of the form AddSymbol + Offset
  54. * to be encoded.
  55. *
  56. * The LLVMOpInfoCallback() for the TagType value of 1 uses the struct
  57. * LLVMOpInfo1. The value of the relocatable expression for the operand,
  58. * including any PC adjustment, is passed in to the call back in the Value
  59. * field. The symbolic information about the operand is returned using all
  60. * the fields of the structure with the Offset of the relocatable expression
  61. * returned in the Value field. It is possible that some symbols in the
  62. * relocatable expression were assembly temporary symbols, for example
  63. * "Ldata - LpicBase + constant", and only the Values of the symbols without
  64. * symbol names are present in the relocation information. The VariantKind
  65. * type is one of the Target specific #defines below and is used to print
  66. * operands like "_foo@GOT", ":lower16:_foo", etc.
  67. */
  68. struct LLVMOpInfoSymbol1 {
  69. uint64_t Present; /* 1 if this symbol is present */
  70. const char *Name; /* symbol name if not NULL */
  71. uint64_t Value; /* symbol value if name is NULL */
  72. };
  73. struct LLVMOpInfo1 {
  74. struct LLVMOpInfoSymbol1 AddSymbol;
  75. struct LLVMOpInfoSymbol1 SubtractSymbol;
  76. uint64_t Value;
  77. uint64_t VariantKind;
  78. };
  79. /**
  80. * The operand VariantKinds for symbolic disassembly.
  81. */
  82. #define LLVMDisassembler_VariantKind_None 0 /* all targets */
  83. /**
  84. * The ARM target VariantKinds.
  85. */
  86. #define LLVMDisassembler_VariantKind_ARM_HI16 1 /* :upper16: */
  87. #define LLVMDisassembler_VariantKind_ARM_LO16 2 /* :lower16: */
  88. /**
  89. * The type for the symbol lookup function. This may be called by the
  90. * disassembler for things like adding a comment for a PC plus a constant
  91. * offset load instruction to use a symbol name instead of a load address value.
  92. * It is passed the block information is saved when the disassembler context is
  93. * created and the ReferenceValue to look up as a symbol. If no symbol is found
  94. * for the ReferenceValue NULL is returned. The ReferenceType of the
  95. * instruction is passed indirectly as is the PC of the instruction in
  96. * ReferencePC. If the output reference can be determined its type is returned
  97. * indirectly in ReferenceType along with ReferenceName if any, or that is set
  98. * to NULL.
  99. */
  100. typedef const char *(*LLVMSymbolLookupCallback)(void *DisInfo,
  101. uint64_t ReferenceValue,
  102. uint64_t *ReferenceType,
  103. uint64_t ReferencePC,
  104. const char **ReferenceName);
  105. /**
  106. * The reference types on input and output.
  107. */
  108. /* No input reference type or no output reference type. */
  109. #define LLVMDisassembler_ReferenceType_InOut_None 0
  110. /* The input reference is from a branch instruction. */
  111. #define LLVMDisassembler_ReferenceType_In_Branch 1
  112. /* The input reference is from a PC relative load instruction. */
  113. #define LLVMDisassembler_ReferenceType_In_PCrel_Load 2
  114. /* The output reference is to as symbol stub. */
  115. #define LLVMDisassembler_ReferenceType_Out_SymbolStub 1
  116. /* The output reference is to a symbol address in a literal pool. */
  117. #define LLVMDisassembler_ReferenceType_Out_LitPool_SymAddr 2
  118. /* The output reference is to a cstring address in a literal pool. */
  119. #define LLVMDisassembler_ReferenceType_Out_LitPool_CstrAddr 3
  120. /* The output reference is to a Objective-C CoreFoundation string. */
  121. #define LLVMDisassembler_ReferenceType_Out_Objc_CFString_Ref 4
  122. /* The output reference is to a Objective-C message. */
  123. #define LLVMDisassembler_ReferenceType_Out_Objc_Message 5
  124. /* The output reference is to a Objective-C message ref. */
  125. #define LLVMDisassembler_ReferenceType_Out_Objc_Message_Ref 6
  126. /* The output reference is to a Objective-C selector ref. */
  127. #define LLVMDisassembler_ReferenceType_Out_Objc_Selector_Ref 7
  128. /* The output reference is to a Objective-C class ref. */
  129. #define LLVMDisassembler_ReferenceType_Out_Objc_Class_Ref 8
  130. #ifdef __cplusplus
  131. extern "C" {
  132. #endif /* !defined(__cplusplus) */
  133. /**
  134. * Create a disassembler for the TripleName. Symbolic disassembly is supported
  135. * by passing a block of information in the DisInfo parameter and specifying the
  136. * TagType and callback functions as described above. These can all be passed
  137. * as NULL. If successful, this returns a disassembler context. If not, it
  138. * returns NULL. This function is equivalent to calling LLVMCreateDisasmCPU()
  139. * with an empty CPU name.
  140. */
  141. LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo,
  142. int TagType, LLVMOpInfoCallback GetOpInfo,
  143. LLVMSymbolLookupCallback SymbolLookUp);
  144. /**
  145. * Create a disassembler for the TripleName and a specific CPU. Symbolic
  146. * disassembly is supported by passing a block of information in the DisInfo
  147. * parameter and specifying the TagType and callback functions as described
  148. * above. These can all be passed * as NULL. If successful, this returns a
  149. * disassembler context. If not, it returns NULL.
  150. */
  151. LLVMDisasmContextRef LLVMCreateDisasmCPU(const char *Triple, const char *CPU,
  152. void *DisInfo, int TagType,
  153. LLVMOpInfoCallback GetOpInfo,
  154. LLVMSymbolLookupCallback SymbolLookUp);
  155. /**
  156. * Set the disassembler's options. Returns 1 if it can set the Options and 0
  157. * otherwise.
  158. */
  159. int LLVMSetDisasmOptions(LLVMDisasmContextRef DC, uint64_t Options);
  160. /* The option to produce marked up assembly. */
  161. #define LLVMDisassembler_Option_UseMarkup 1
  162. /* The option to print immediates as hex. */
  163. #define LLVMDisassembler_Option_PrintImmHex 2
  164. /* The option use the other assembler printer variant */
  165. #define LLVMDisassembler_Option_AsmPrinterVariant 4
  166. /* The option to set comment on instructions */
  167. #define LLVMDisassembler_Option_SetInstrComments 8
  168. /* The option to print latency information alongside instructions */
  169. #define LLVMDisassembler_Option_PrintLatency 16
  170. /**
  171. * Dispose of a disassembler context.
  172. */
  173. void LLVMDisasmDispose(LLVMDisasmContextRef DC);
  174. /**
  175. * Disassemble a single instruction using the disassembler context specified in
  176. * the parameter DC. The bytes of the instruction are specified in the
  177. * parameter Bytes, and contains at least BytesSize number of bytes. The
  178. * instruction is at the address specified by the PC parameter. If a valid
  179. * instruction can be disassembled, its string is returned indirectly in
  180. * OutString whose size is specified in the parameter OutStringSize. This
  181. * function returns the number of bytes in the instruction or zero if there was
  182. * no valid instruction.
  183. */
  184. size_t LLVMDisasmInstruction(LLVMDisasmContextRef DC, uint8_t *Bytes,
  185. uint64_t BytesSize, uint64_t PC,
  186. char *OutString, size_t OutStringSize);
  187. /**
  188. * @}
  189. */
  190. #ifdef __cplusplus
  191. }
  192. #endif /* !defined(__cplusplus) */
  193. #endif /* !defined(LLVM_C_DISASSEMBLER_H) */