LLVM API Documentation
00001 /*===-- llvm-c/TargetMachine.h - Target Machine Library C Interface - C++ -*-=*\ 00002 |* *| 00003 |* The LLVM Compiler Infrastructure *| 00004 |* *| 00005 |* This file is distributed under the University of Illinois Open Source *| 00006 |* License. See LICENSE.TXT for details. *| 00007 |* *| 00008 |*===----------------------------------------------------------------------===*| 00009 |* *| 00010 |* This header declares the C interface to the Target and TargetMachine *| 00011 |* classes, which can be used to generate assembly or object files. *| 00012 |* *| 00013 |* Many exotic languages can interoperate with C code but have a harder time *| 00014 |* with C++ due to name mangling. So in addition to C, this interface enables *| 00015 |* tools written in such languages. *| 00016 |* *| 00017 \*===----------------------------------------------------------------------===*/ 00018 00019 #ifndef LLVM_C_TARGETMACHINE_H 00020 #define LLVM_C_TARGETMACHINE_H 00021 00022 #include "llvm-c/Core.h" 00023 #include "llvm-c/Target.h" 00024 00025 #ifdef __cplusplus 00026 extern "C" { 00027 #endif 00028 typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef; 00029 typedef struct LLVMTarget *LLVMTargetRef; 00030 00031 typedef enum { 00032 LLVMCodeGenLevelNone, 00033 LLVMCodeGenLevelLess, 00034 LLVMCodeGenLevelDefault, 00035 LLVMCodeGenLevelAggressive 00036 } LLVMCodeGenOptLevel; 00037 00038 typedef enum { 00039 LLVMRelocDefault, 00040 LLVMRelocStatic, 00041 LLVMRelocPIC, 00042 LLVMRelocDynamicNoPic 00043 } LLVMRelocMode; 00044 00045 typedef enum { 00046 LLVMCodeModelDefault, 00047 LLVMCodeModelJITDefault, 00048 LLVMCodeModelSmall, 00049 LLVMCodeModelKernel, 00050 LLVMCodeModelMedium, 00051 LLVMCodeModelLarge 00052 } LLVMCodeModel; 00053 00054 typedef enum { 00055 LLVMAssemblyFile, 00056 LLVMObjectFile 00057 } LLVMCodeGenFileType; 00058 00059 /** Returns the first llvm::Target in the registered targets list. */ 00060 LLVMTargetRef LLVMGetFirstTarget(void); 00061 /** Returns the next llvm::Target given a previous one (or null if there's none) */ 00062 LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T); 00063 00064 /*===-- Target ------------------------------------------------------------===*/ 00065 /** Finds the target corresponding to the given name and stores it in \p T. 00066 Returns 0 on success. */ 00067 LLVMTargetRef LLVMGetTargetFromName(const char *Name); 00068 00069 /** Finds the target corresponding to the given triple and stores it in \p T. 00070 Returns 0 on success. Optionally returns any error in ErrorMessage. 00071 Use LLVMDisposeMessage to dispose the message. */ 00072 LLVMBool LLVMGetTargetFromTriple(const char* Triple, LLVMTargetRef *T, 00073 char **ErrorMessage); 00074 00075 /** Returns the name of a target. See llvm::Target::getName */ 00076 const char *LLVMGetTargetName(LLVMTargetRef T); 00077 00078 /** Returns the description of a target. See llvm::Target::getDescription */ 00079 const char *LLVMGetTargetDescription(LLVMTargetRef T); 00080 00081 /** Returns if the target has a JIT */ 00082 LLVMBool LLVMTargetHasJIT(LLVMTargetRef T); 00083 00084 /** Returns if the target has a TargetMachine associated */ 00085 LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T); 00086 00087 /** Returns if the target as an ASM backend (required for emitting output) */ 00088 LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T); 00089 00090 /*===-- Target Machine ----------------------------------------------------===*/ 00091 /** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */ 00092 LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, 00093 const char *Triple, const char *CPU, const char *Features, 00094 LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel); 00095 00096 /** Dispose the LLVMTargetMachineRef instance generated by 00097 LLVMCreateTargetMachine. */ 00098 void LLVMDisposeTargetMachine(LLVMTargetMachineRef T); 00099 00100 /** Returns the Target used in a TargetMachine */ 00101 LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T); 00102 00103 /** Returns the triple used creating this target machine. See 00104 llvm::TargetMachine::getTriple. The result needs to be disposed with 00105 LLVMDisposeMessage. */ 00106 char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T); 00107 00108 /** Returns the cpu used creating this target machine. See 00109 llvm::TargetMachine::getCPU. The result needs to be disposed with 00110 LLVMDisposeMessage. */ 00111 char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T); 00112 00113 /** Returns the feature string used creating this target machine. See 00114 llvm::TargetMachine::getFeatureString. The result needs to be disposed with 00115 LLVMDisposeMessage. */ 00116 char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T); 00117 00118 /** Returns the llvm::DataLayout used for this llvm:TargetMachine. */ 00119 LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T); 00120 00121 /** Set the target machine's ASM verbosity. */ 00122 void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, 00123 LLVMBool VerboseAsm); 00124 00125 /** Emits an asm or object file for the given module to the filename. This 00126 wraps several c++ only classes (among them a file stream). Returns any 00127 error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */ 00128 LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M, 00129 char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage); 00130 00131 /** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */ 00132 LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M, 00133 LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf); 00134 00135 /*===-- Triple ------------------------------------------------------------===*/ 00136 /** Get a triple for the host machine as a string. The result needs to be 00137 disposed with LLVMDisposeMessage. */ 00138 char* LLVMGetDefaultTargetTriple(void); 00139 00140 /** Adds the target-specific analysis passes to the pass manager. */ 00141 void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM); 00142 00143 #ifdef __cplusplus 00144 } 00145 #endif 00146 00147 #endif