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"
27 typedef struct LLVMTargetMachine *LLVMTargetMachineRef;
28 typedef struct LLVMTarget *LLVMTargetRef;
33 LLVMCodeGenLevelDefault,
34 LLVMCodeGenLevelAggressive
35 } LLVMCodeGenOptLevel;
46 LLVMCodeModelJITDefault,
56 } LLVMCodeGenFileType;
58 /** Returns the first llvm::Target in the registered targets list. */
59 LLVMTargetRef LLVMGetFirstTarget();
60 /** Returns the next llvm::Target given a previous one (or null if there's none) */
61 LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);
63 /*===-- Target ------------------------------------------------------------===*/
64 /** Returns the name of a target. See llvm::Target::getName */
65 const char *LLVMGetTargetName(LLVMTargetRef T);
67 /** Returns the description of a target. See llvm::Target::getDescription */
68 const char *LLVMGetTargetDescription(LLVMTargetRef T);
70 /** Returns if the target has a JIT */
71 LLVMBool LLVMTargetHasJIT(LLVMTargetRef T);
73 /** Returns if the target has a TargetMachine associated */
74 LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T);
76 /** Returns if the target as an ASM backend (required for emitting output) */
77 LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T);
79 /*===-- Target Machine ----------------------------------------------------===*/
80 /** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
81 LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, char *Triple,
82 char *CPU, char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc,
83 LLVMCodeModel CodeModel);
85 /** Dispose the LLVMTargetMachineRef instance generated by
86 LLVMCreateTargetMachine. */
87 void LLVMDisposeTargetMachine(LLVMTargetMachineRef T);
89 /** Returns the Target used in a TargetMachine */
90 LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T);
92 /** Returns the triple used creating this target machine. See
93 llvm::TargetMachine::getTriple. The result needs to be disposed with
94 LLVMDisposeMessage. */
95 char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T);
97 /** Returns the cpu used creating this target machine. See
98 llvm::TargetMachine::getCPU. The result needs to be disposed with
99 LLVMDisposeMessage. */
100 char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T);
102 /** Returns the feature string used creating this target machine. See
103 llvm::TargetMachine::getFeatureString. The result needs to be disposed with
104 LLVMDisposeMessage. */
105 char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
107 /** Returns the llvm::TargetData used for this llvm:TargetMachine. */
108 LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T);
110 /** Emits an asm or object file for the given module to the filename. This
111 wraps several c++ only classes (among them a file stream). Returns any
112 error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
113 LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
114 char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage);
126 inline TargetMachine *unwrap(LLVMTargetMachineRef P) {
127 return reinterpret_cast<TargetMachine*>(P);
129 inline Target *unwrap(LLVMTargetRef P) {
130 return reinterpret_cast<Target*>(P);
132 inline LLVMTargetMachineRef wrap(const TargetMachine *P) {
133 return reinterpret_cast<LLVMTargetMachineRef>(
134 const_cast<TargetMachine*>(P));
136 inline LLVMTargetRef wrap(const Target * P) {
137 return reinterpret_cast<LLVMTargetRef>(const_cast<Target*>(P));