TargetMachine.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*===-- llvm-c/TargetMachine.h - Target Machine Library 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 declares the C interface to the Target and TargetMachine *|
  11. |* classes, which can be used to generate assembly or object files. *|
  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_TARGETMACHINE_H
  19. #define LLVM_C_TARGETMACHINE_H
  20. #include "llvm-c/Core.h"
  21. #include "llvm-c/Target.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
  26. typedef struct LLVMTarget *LLVMTargetRef;
  27. typedef enum {
  28. LLVMCodeGenLevelNone,
  29. LLVMCodeGenLevelLess,
  30. LLVMCodeGenLevelDefault,
  31. LLVMCodeGenLevelAggressive
  32. } LLVMCodeGenOptLevel;
  33. typedef enum {
  34. LLVMRelocDefault,
  35. LLVMRelocStatic,
  36. LLVMRelocPIC,
  37. LLVMRelocDynamicNoPic
  38. } LLVMRelocMode;
  39. typedef enum {
  40. LLVMCodeModelDefault,
  41. LLVMCodeModelJITDefault,
  42. LLVMCodeModelSmall,
  43. LLVMCodeModelKernel,
  44. LLVMCodeModelMedium,
  45. LLVMCodeModelLarge
  46. } LLVMCodeModel;
  47. typedef enum {
  48. LLVMAssemblyFile,
  49. LLVMObjectFile
  50. } LLVMCodeGenFileType;
  51. /** Returns the first llvm::Target in the registered targets list. */
  52. LLVMTargetRef LLVMGetFirstTarget(void);
  53. /** Returns the next llvm::Target given a previous one (or null if there's none) */
  54. LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);
  55. /*===-- Target ------------------------------------------------------------===*/
  56. /** Finds the target corresponding to the given name and stores it in \p T.
  57. Returns 0 on success. */
  58. LLVMTargetRef LLVMGetTargetFromName(const char *Name);
  59. /** Finds the target corresponding to the given triple and stores it in \p T.
  60. Returns 0 on success. Optionally returns any error in ErrorMessage.
  61. Use LLVMDisposeMessage to dispose the message. */
  62. LLVMBool LLVMGetTargetFromTriple(
  63. const char* Triple,
  64. LLVMTargetRef *T,
  65. _Out_opt_ char **ErrorMessage);
  66. /** Returns the name of a target. See llvm::Target::getName */
  67. const char *LLVMGetTargetName(LLVMTargetRef T);
  68. /** Returns the description of a target. See llvm::Target::getDescription */
  69. const char *LLVMGetTargetDescription(LLVMTargetRef T);
  70. /** Returns if the target has a JIT */
  71. LLVMBool LLVMTargetHasJIT(LLVMTargetRef T);
  72. /** Returns if the target has a TargetMachine associated */
  73. LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T);
  74. /** Returns if the target as an ASM backend (required for emitting output) */
  75. LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T);
  76. /*===-- Target Machine ----------------------------------------------------===*/
  77. /** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
  78. LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,
  79. const char *Triple, const char *CPU, const char *Features,
  80. LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel);
  81. /** Dispose the LLVMTargetMachineRef instance generated by
  82. LLVMCreateTargetMachine. */
  83. void LLVMDisposeTargetMachine(LLVMTargetMachineRef T);
  84. /** Returns the Target used in a TargetMachine */
  85. LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T);
  86. /** Returns the triple used creating this target machine. See
  87. llvm::TargetMachine::getTriple. The result needs to be disposed with
  88. LLVMDisposeMessage. */
  89. char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T);
  90. /** Returns the cpu used creating this target machine. See
  91. llvm::TargetMachine::getCPU. The result needs to be disposed with
  92. LLVMDisposeMessage. */
  93. char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T);
  94. /** Returns the feature string used creating this target machine. See
  95. llvm::TargetMachine::getFeatureString. The result needs to be disposed with
  96. LLVMDisposeMessage. */
  97. char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
  98. /** Deprecated: use LLVMGetDataLayout(LLVMModuleRef M) instead. */
  99. LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T);
  100. /** Set the target machine's ASM verbosity. */
  101. void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
  102. LLVMBool VerboseAsm);
  103. /** Emits an asm or object file for the given module to the filename. This
  104. wraps several c++ only classes (among them a file stream). Returns any
  105. error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
  106. LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
  107. _In_ char *Filename, LLVMCodeGenFileType codegen,
  108. _Out_opt_ char **ErrorMessage);
  109. /** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
  110. LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,
  111. LLVMCodeGenFileType codegen,
  112. _Out_opt_ char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
  113. /*===-- Triple ------------------------------------------------------------===*/
  114. /** Get a triple for the host machine as a string. The result needs to be
  115. disposed with LLVMDisposeMessage. */
  116. char* LLVMGetDefaultTargetTriple(void);
  117. /** Adds the target-specific analysis passes to the pass manager. */
  118. void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM);
  119. #ifdef __cplusplus
  120. }
  121. #endif
  122. #endif