Make it possible to include llvm-c without including C++ headers. Patch by Filip...
[oota-llvm.git] / include / llvm-c / TargetMachine.h
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
19 #ifndef LLVM_C_TARGETMACHINE_H
20 #define LLVM_C_TARGETMACHINE_H
21
22 #include "llvm-c/Core.h"
23 #include "llvm-c/Target.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 typedef struct LLVMTargetMachine *LLVMTargetMachineRef;
29 typedef struct LLVMTarget *LLVMTargetRef;
30
31 typedef enum {
32     LLVMCodeGenLevelNone,
33     LLVMCodeGenLevelLess,
34     LLVMCodeGenLevelDefault,
35     LLVMCodeGenLevelAggressive
36 } LLVMCodeGenOptLevel;
37
38 typedef enum {
39     LLVMRelocDefault,
40     LLVMRelocStatic,
41     LLVMRelocPIC,
42     LLVMRelocDynamicNoPic
43 } LLVMRelocMode;
44
45 typedef enum {
46     LLVMCodeModelDefault,
47     LLVMCodeModelJITDefault,
48     LLVMCodeModelSmall,
49     LLVMCodeModelKernel,
50     LLVMCodeModelMedium,
51     LLVMCodeModelLarge
52 } LLVMCodeModel;
53
54 typedef enum {
55     LLVMAssemblyFile,
56     LLVMObjectFile
57 } LLVMCodeGenFileType;
58
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);
63
64 /*===-- Target ------------------------------------------------------------===*/
65 /** Returns the name of a target. See llvm::Target::getName */
66 const char *LLVMGetTargetName(LLVMTargetRef T);
67
68 /** Returns the description  of a target. See llvm::Target::getDescription */
69 const char *LLVMGetTargetDescription(LLVMTargetRef T);
70
71 /** Returns if the target has a JIT */
72 LLVMBool LLVMTargetHasJIT(LLVMTargetRef T);
73
74 /** Returns if the target has a TargetMachine associated */
75 LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T);
76
77 /** Returns if the target as an ASM backend (required for emitting output) */
78 LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T);
79
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);
85
86 /** Dispose the LLVMTargetMachineRef instance generated by
87   LLVMCreateTargetMachine. */
88 void LLVMDisposeTargetMachine(LLVMTargetMachineRef T);
89
90 /** Returns the Target used in a TargetMachine */
91 LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T);
92
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);
97
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);
102
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);
107
108 /** Returns the llvm::DataLayout used for this llvm:TargetMachine. */
109 LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T);
110
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);
116
117
118
119
120 #ifdef __cplusplus
121 }
122 #endif
123
124 #if defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS)
125 namespace llvm {
126   class TargetMachine;
127   class Target;
128
129   inline TargetMachine *unwrap(LLVMTargetMachineRef P) {
130     return reinterpret_cast<TargetMachine*>(P);
131   }
132   inline Target *unwrap(LLVMTargetRef P) {
133     return reinterpret_cast<Target*>(P);
134   }
135   inline LLVMTargetMachineRef wrap(const TargetMachine *P) {
136     return reinterpret_cast<LLVMTargetMachineRef>(
137       const_cast<TargetMachine*>(P));
138   }
139   inline LLVMTargetRef wrap(const Target * P) {
140     return reinterpret_cast<LLVMTargetRef>(const_cast<Target*>(P));
141   }
142 }
143 #endif /* defined(__cplusplus) && !defined(LLVM_DO_NOT_INCLUDE_CPP_HEADERS) */
144
145 #endif