Target.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- 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 declares the C interface to libLLVMTarget.a, which */
  11. /* implements target information. */
  12. /* */
  13. /* Many exotic languages can interoperate with C code but have a harder time */
  14. /* with C++ due to name mangling. So in addition to C, this interface enables */
  15. /* tools written in such languages. */
  16. /* */
  17. /*===----------------------------------------------------------------------===*/
  18. #ifndef LLVM_C_TARGET_H
  19. #define LLVM_C_TARGET_H
  20. #include "llvm-c/Core.h"
  21. #include "llvm/Config/llvm-config.h"
  22. #if defined(_MSC_VER) && !defined(inline)
  23. #define inline __inline
  24. #endif
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /**
  29. * @defgroup LLVMCTarget Target information
  30. * @ingroup LLVMC
  31. *
  32. * @{
  33. */
  34. enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
  35. typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
  36. typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
  37. /* Declare all of the target-initialization functions that are available. */
  38. #define LLVM_TARGET(TargetName) \
  39. void LLVMInitialize##TargetName##TargetInfo(void);
  40. #include "llvm/Config/Targets.def"
  41. #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
  42. #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
  43. #include "llvm/Config/Targets.def"
  44. #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
  45. #define LLVM_TARGET(TargetName) \
  46. void LLVMInitialize##TargetName##TargetMC(void);
  47. #include "llvm/Config/Targets.def"
  48. #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
  49. /* Declare all of the available assembly printer initialization functions. */
  50. #define LLVM_ASM_PRINTER(TargetName) \
  51. void LLVMInitialize##TargetName##AsmPrinter(void);
  52. #include "llvm/Config/AsmPrinters.def"
  53. #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
  54. /* Declare all of the available assembly parser initialization functions. */
  55. #define LLVM_ASM_PARSER(TargetName) \
  56. void LLVMInitialize##TargetName##AsmParser(void);
  57. #include "llvm/Config/AsmParsers.def"
  58. #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
  59. /* Declare all of the available disassembler initialization functions. */
  60. #define LLVM_DISASSEMBLER(TargetName) \
  61. void LLVMInitialize##TargetName##Disassembler(void);
  62. #include "llvm/Config/Disassemblers.def"
  63. #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
  64. /** LLVMInitializeAllTargetInfos - The main program should call this function if
  65. it wants access to all available targets that LLVM is configured to
  66. support. */
  67. static inline void LLVMInitializeAllTargetInfos(void) {
  68. #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
  69. #include "llvm/Config/Targets.def"
  70. #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
  71. }
  72. /** LLVMInitializeAllTargets - The main program should call this function if it
  73. wants to link in all available targets that LLVM is configured to
  74. support. */
  75. static inline void LLVMInitializeAllTargets(void) {
  76. #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
  77. #include "llvm/Config/Targets.def"
  78. #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
  79. }
  80. /** LLVMInitializeAllTargetMCs - The main program should call this function if
  81. it wants access to all available target MC that LLVM is configured to
  82. support. */
  83. static inline void LLVMInitializeAllTargetMCs(void) {
  84. #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
  85. #include "llvm/Config/Targets.def"
  86. #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
  87. }
  88. /** LLVMInitializeAllAsmPrinters - The main program should call this function if
  89. it wants all asm printers that LLVM is configured to support, to make them
  90. available via the TargetRegistry. */
  91. static inline void LLVMInitializeAllAsmPrinters(void) {
  92. #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
  93. #include "llvm/Config/AsmPrinters.def"
  94. #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
  95. }
  96. /** LLVMInitializeAllAsmParsers - The main program should call this function if
  97. it wants all asm parsers that LLVM is configured to support, to make them
  98. available via the TargetRegistry. */
  99. static inline void LLVMInitializeAllAsmParsers(void) {
  100. #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
  101. #include "llvm/Config/AsmParsers.def"
  102. #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
  103. }
  104. /** LLVMInitializeAllDisassemblers - The main program should call this function
  105. if it wants all disassemblers that LLVM is configured to support, to make
  106. them available via the TargetRegistry. */
  107. static inline void LLVMInitializeAllDisassemblers(void) {
  108. #define LLVM_DISASSEMBLER(TargetName) \
  109. LLVMInitialize##TargetName##Disassembler();
  110. #include "llvm/Config/Disassemblers.def"
  111. #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
  112. }
  113. /** LLVMInitializeNativeTarget - The main program should call this function to
  114. initialize the native target corresponding to the host. This is useful
  115. for JIT applications to ensure that the target gets linked in correctly. */
  116. static inline LLVMBool LLVMInitializeNativeTarget(void) {
  117. /* If we have a native target, initialize it to ensure it is linked in. */
  118. #ifdef LLVM_NATIVE_TARGET
  119. LLVM_NATIVE_TARGETINFO();
  120. LLVM_NATIVE_TARGET();
  121. LLVM_NATIVE_TARGETMC();
  122. return 0;
  123. #else
  124. return 1;
  125. #endif
  126. }
  127. /** LLVMInitializeNativeTargetAsmParser - The main program should call this
  128. function to initialize the parser for the native target corresponding to the
  129. host. */
  130. static inline LLVMBool LLVMInitializeNativeAsmParser(void) {
  131. #ifdef LLVM_NATIVE_ASMPARSER
  132. LLVM_NATIVE_ASMPARSER();
  133. return 0;
  134. #else
  135. return 1;
  136. #endif
  137. }
  138. /** LLVMInitializeNativeTargetAsmPrinter - The main program should call this
  139. function to initialize the printer for the native target corresponding to
  140. the host. */
  141. static inline LLVMBool LLVMInitializeNativeAsmPrinter(void) {
  142. #ifdef LLVM_NATIVE_ASMPRINTER
  143. LLVM_NATIVE_ASMPRINTER();
  144. return 0;
  145. #else
  146. return 1;
  147. #endif
  148. }
  149. /** LLVMInitializeNativeTargetDisassembler - The main program should call this
  150. function to initialize the disassembler for the native target corresponding
  151. to the host. */
  152. static inline LLVMBool LLVMInitializeNativeDisassembler(void) {
  153. #ifdef LLVM_NATIVE_DISASSEMBLER
  154. LLVM_NATIVE_DISASSEMBLER();
  155. return 0;
  156. #else
  157. return 1;
  158. #endif
  159. }
  160. /*===-- Target Data -------------------------------------------------------===*/
  161. /** Creates target data from a target layout string.
  162. See the constructor llvm::DataLayout::DataLayout. */
  163. LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
  164. /** Adds target data information to a pass manager. This does not take ownership
  165. of the target data.
  166. See the method llvm::PassManagerBase::add. */
  167. void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM);
  168. /** Adds target library information to a pass manager. This does not take
  169. ownership of the target library info.
  170. See the method llvm::PassManagerBase::add. */
  171. void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
  172. LLVMPassManagerRef PM);
  173. /** Converts target data to a target layout string. The string must be disposed
  174. with LLVMDisposeMessage.
  175. See the constructor llvm::DataLayout::DataLayout. */
  176. char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);
  177. /** Returns the byte order of a target, either LLVMBigEndian or
  178. LLVMLittleEndian.
  179. See the method llvm::DataLayout::isLittleEndian. */
  180. enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);
  181. /** Returns the pointer size in bytes for a target.
  182. See the method llvm::DataLayout::getPointerSize. */
  183. unsigned LLVMPointerSize(LLVMTargetDataRef TD);
  184. /** Returns the pointer size in bytes for a target for a specified
  185. address space.
  186. See the method llvm::DataLayout::getPointerSize. */
  187. unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
  188. /** Returns the integer type that is the same size as a pointer on a target.
  189. See the method llvm::DataLayout::getIntPtrType. */
  190. LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD);
  191. /** Returns the integer type that is the same size as a pointer on a target.
  192. This version allows the address space to be specified.
  193. See the method llvm::DataLayout::getIntPtrType. */
  194. LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS);
  195. /** Returns the integer type that is the same size as a pointer on a target.
  196. See the method llvm::DataLayout::getIntPtrType. */
  197. LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD);
  198. /** Returns the integer type that is the same size as a pointer on a target.
  199. This version allows the address space to be specified.
  200. See the method llvm::DataLayout::getIntPtrType. */
  201. LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD,
  202. unsigned AS);
  203. /** Computes the size of a type in bytes for a target.
  204. See the method llvm::DataLayout::getTypeSizeInBits. */
  205. unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty);
  206. /** Computes the storage size of a type in bytes for a target.
  207. See the method llvm::DataLayout::getTypeStoreSize. */
  208. unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
  209. /** Computes the ABI size of a type in bytes for a target.
  210. See the method llvm::DataLayout::getTypeAllocSize. */
  211. unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
  212. /** Computes the ABI alignment of a type in bytes for a target.
  213. See the method llvm::DataLayout::getTypeABISize. */
  214. unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
  215. /** Computes the call frame alignment of a type in bytes for a target.
  216. See the method llvm::DataLayout::getTypeABISize. */
  217. unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
  218. /** Computes the preferred alignment of a type in bytes for a target.
  219. See the method llvm::DataLayout::getTypeABISize. */
  220. unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
  221. /** Computes the preferred alignment of a global variable in bytes for a target.
  222. See the method llvm::DataLayout::getPreferredAlignment. */
  223. unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
  224. LLVMValueRef GlobalVar);
  225. /** Computes the structure element that contains the byte offset for a target.
  226. See the method llvm::StructLayout::getElementContainingOffset. */
  227. unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
  228. unsigned long long Offset);
  229. /** Computes the byte offset of the indexed struct element for a target.
  230. See the method llvm::StructLayout::getElementContainingOffset. */
  231. unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
  232. LLVMTypeRef StructTy, unsigned Element);
  233. /** Deallocates a TargetData.
  234. See the destructor llvm::DataLayout::~DataLayout. */
  235. void LLVMDisposeTargetData(LLVMTargetDataRef TD);
  236. /**
  237. * @}
  238. */
  239. #ifdef __cplusplus
  240. }
  241. #endif /* defined(__cplusplus) */
  242. #endif