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