Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
9.0 KiB

  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. #ifdef __cplusplus
  121. extern "C" {
  122. #endif /* !defined(__cplusplus) */
  123. /**
  124. * Create a disassembler for the TripleName. Symbolic disassembly is supported
  125. * by passing a block of information in the DisInfo parameter and specifying the
  126. * TagType and callback functions as described above. These can all be passed
  127. * as NULL. If successful, this returns a disassembler context. If not, it
  128. * returns NULL. This function is equivalent to calling LLVMCreateDisasmCPU()
  129. * with an empty CPU name.
  130. */
  131. LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo,
  132. int TagType, LLVMOpInfoCallback GetOpInfo,
  133. LLVMSymbolLookupCallback SymbolLookUp);
  134. /**
  135. * Create a disassembler for the TripleName and a specific CPU. Symbolic
  136. * disassembly is supported by passing a block of information in the DisInfo
  137. * parameter and specifying the TagType and callback functions as described
  138. * above. These can all be passed * as NULL. If successful, this returns a
  139. * disassembler context. If not, it returns NULL.
  140. */
  141. LLVMDisasmContextRef LLVMCreateDisasmCPU(const char *Triple, const char *CPU,
  142. void *DisInfo, int TagType,
  143. LLVMOpInfoCallback GetOpInfo,
  144. LLVMSymbolLookupCallback SymbolLookUp);
  145. /**
  146. * Set the disassembler's options. Returns 1 if it can set the Options and 0
  147. * otherwise.
  148. */
  149. int LLVMSetDisasmOptions(LLVMDisasmContextRef DC, uint64_t Options);
  150. /* The option to produce marked up assembly. */
  151. #define LLVMDisassembler_Option_UseMarkup 1
  152. /* The option to print immediates as hex. */
  153. #define LLVMDisassembler_Option_PrintImmHex 2
  154. /* The option use the other assembler printer variant */
  155. #define LLVMDisassembler_Option_AsmPrinterVariant 4
  156. /**
  157. * Dispose of a disassembler context.
  158. */
  159. void LLVMDisasmDispose(LLVMDisasmContextRef DC);
  160. /**
  161. * Disassemble a single instruction using the disassembler context specified in
  162. * the parameter DC. The bytes of the instruction are specified in the
  163. * parameter Bytes, and contains at least BytesSize number of bytes. The
  164. * instruction is at the address specified by the PC parameter. If a valid
  165. * instruction can be disassembled, its string is returned indirectly in
  166. * OutString whose size is specified in the parameter OutStringSize. This
  167. * function returns the number of bytes in the instruction or zero if there was
  168. * no valid instruction.
  169. */
  170. size_t LLVMDisasmInstruction(LLVMDisasmContextRef DC, uint8_t *Bytes,
  171. uint64_t BytesSize, uint64_t PC,
  172. char *OutString, size_t OutStringSize);
  173. /**
  174. * @}
  175. */
  176. #ifdef __cplusplus
  177. }
  178. #endif /* !defined(__cplusplus) */
  179. #endif /* !defined(LLVM_C_DISASSEMBLER_H) */