8fae77def443b97e05d27bfc8ef430f9a2e949c1
[oota-llvm.git] / include / llvm-c / ExecutionEngine.h
1 /*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- 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 libLLVMExecutionEngine.o, which    *|
11 |* implements various analyses of the LLVM IR.                                *|
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_EXECUTIONENGINE_H
20 #define LLVM_C_EXECUTIONENGINE_H
21
22 #include "llvm-c/Core.h"
23 #include "llvm-c/Target.h"
24 #include "llvm-c/TargetMachine.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 /**
31  * @defgroup LLVMCExecutionEngine Execution Engine
32  * @ingroup LLVMC
33  *
34  * @{
35  */
36
37 void LLVMLinkInJIT(void);
38 void LLVMLinkInMCJIT(void);
39 void LLVMLinkInInterpreter(void);
40
41 typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
42 typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
43
44 struct LLVMMCJITCompilerOptions {
45   unsigned OptLevel;
46   LLVMCodeModel CodeModel;
47   LLVMBool NoFramePointerElim;
48   LLVMBool EnableFastISel;
49 };
50
51 /*===-- Operations on generic values --------------------------------------===*/
52
53 LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
54                                                 unsigned long long N,
55                                                 LLVMBool IsSigned);
56
57 LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
58
59 LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
60
61 unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
62
63 unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
64                                          LLVMBool IsSigned);
65
66 void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
67
68 double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
69
70 void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
71
72 /*===-- Operations on execution engines -----------------------------------===*/
73
74 LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
75                                             LLVMModuleRef M,
76                                             char **OutError);
77
78 LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
79                                         LLVMModuleRef M,
80                                         char **OutError);
81
82 LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
83                                         LLVMModuleRef M,
84                                         unsigned OptLevel,
85                                         char **OutError);
86
87 void LLVMInitializeMCJITCompilerOptions(
88   struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions);
89
90 /**
91  * Create an MCJIT execution engine for a module, with the given options. It is
92  * the responsibility of the caller to ensure that all fields in Options up to
93  * the given SizeOfOptions are initialized. It is correct to pass a smaller
94  * value of SizeOfOptions that omits some fields. The canonical way of using
95  * this is:
96  *
97  * LLVMMCJITCompilerOptions options;
98  * LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
99  * ... fill in those options you care about
100  * LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
101  *                                  &error);
102  *
103  * Note that this is also correct, though possibly suboptimal:
104  *
105  * LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
106  */
107 LLVMBool LLVMCreateMCJITCompilerForModule(
108   LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
109   struct LLVMMCJITCompilerOptions *Options, size_t SizeOfOptions,
110   char **OutError);
111
112 /** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */
113 LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
114                                    LLVMModuleProviderRef MP,
115                                    char **OutError);
116
117 /** Deprecated: Use LLVMCreateInterpreterForModule instead. */
118 LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
119                                LLVMModuleProviderRef MP,
120                                char **OutError);
121
122 /** Deprecated: Use LLVMCreateJITCompilerForModule instead. */
123 LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
124                                LLVMModuleProviderRef MP,
125                                unsigned OptLevel,
126                                char **OutError);
127
128 void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
129
130 void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
131
132 void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
133
134 int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
135                           unsigned ArgC, const char * const *ArgV,
136                           const char * const *EnvP);
137
138 LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
139                                     unsigned NumArgs,
140                                     LLVMGenericValueRef *Args);
141
142 void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
143
144 void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
145
146 /** Deprecated: Use LLVMAddModule instead. */
147 void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP);
148
149 LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
150                           LLVMModuleRef *OutMod, char **OutError);
151
152 /** Deprecated: Use LLVMRemoveModule instead. */
153 LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
154                                   LLVMModuleProviderRef MP,
155                                   LLVMModuleRef *OutMod, char **OutError);
156
157 LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
158                           LLVMValueRef *OutFn);
159
160 void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
161                                      LLVMValueRef Fn);
162
163 LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
164
165 void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
166                           void* Addr);
167
168 void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
169
170 /**
171  * @}
172  */
173
174 #ifdef __cplusplus
175 }  
176 #endif /* defined(__cplusplus) */
177
178 #endif