1 /*===-- llvm-c/TargetMachine.h - Target Machine Library C Interface - C++ -*-=*\
3 |* The LLVM Compiler Infrastructure *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
8 |*===----------------------------------------------------------------------===*|
10 |* This header declares the C interface to the Target and TargetMachine *|
11 |* classes, which can be used to generate assembly or object files. *|
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. *|
17 \*===----------------------------------------------------------------------===*/
19 #ifndef LLVM_C_TARGETMACHINE_H
20 #define LLVM_C_TARGETMACHINE_H
22 #include "llvm-c/Core.h"
23 #include "llvm-c/Target.h"
28 typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
29 typedef struct LLVMTarget *LLVMTargetRef;
34 LLVMCodeGenLevelDefault,
35 LLVMCodeGenLevelAggressive
36 } LLVMCodeGenOptLevel;
47 LLVMCodeModelJITDefault,
57 } LLVMCodeGenFileType;
59 /** Returns the first llvm::Target in the registered targets list. */
60 LLVMTargetRef LLVMGetFirstTarget();
61 /** Returns the next llvm::Target given a previous one (or null if there's none) */
62 LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);
64 /*===-- Target ------------------------------------------------------------===*/
65 /** Returns the name of a target. See llvm::Target::getName */
66 const char *LLVMGetTargetName(LLVMTargetRef T);
68 /** Returns the description of a target. See llvm::Target::getDescription */
69 const char *LLVMGetTargetDescription(LLVMTargetRef T);
71 /** Returns if the target has a JIT */
72 LLVMBool LLVMTargetHasJIT(LLVMTargetRef T);
74 /** Returns if the target has a TargetMachine associated */
75 LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T);
77 /** Returns if the target as an ASM backend (required for emitting output) */
78 LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T);
80 /*===-- Target Machine ----------------------------------------------------===*/
81 /** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
82 LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, char *Triple,
83 char *CPU, char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc,
84 LLVMCodeModel CodeModel);
86 /** Dispose the LLVMTargetMachineRef instance generated by
87 LLVMCreateTargetMachine. */
88 void LLVMDisposeTargetMachine(LLVMTargetMachineRef T);
90 /** Returns the Target used in a TargetMachine */
91 LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T);
93 /** Returns the triple used creating this target machine. See
94 llvm::TargetMachine::getTriple. The result needs to be disposed with
95 LLVMDisposeMessage. */
96 char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T);
98 /** Returns the cpu used creating this target machine. See
99 llvm::TargetMachine::getCPU. The result needs to be disposed with
100 LLVMDisposeMessage. */
101 char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T);
103 /** Returns the feature string used creating this target machine. See
104 llvm::TargetMachine::getFeatureString. The result needs to be disposed with
105 LLVMDisposeMessage. */
106 char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
108 /** Returns the llvm::DataLayout used for this llvm:TargetMachine. */
109 LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T);
111 /** Emits an asm or object file for the given module to the filename. This
112 wraps several c++ only classes (among them a file stream). Returns any
113 error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
114 LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
115 char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage);
117 /** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
118 LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,
119 LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);