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