f501086818a78b25f596056b27d572d249045d00
[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 was developed by Gordon Henriksen and is distributed under the   *|
6 |* University of Illinois Open Source 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
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
29 typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
30
31 /*===-- Operations on generic values --------------------------------------===*/
32
33 LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
34                                                 unsigned long long N,
35                                                 int IsSigned);
36
37 LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
38
39 LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
40
41 unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
42
43 unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
44                                          int IsSigned);
45
46 void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
47
48 double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
49
50 void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
51
52 /*===-- Operations on execution engines -----------------------------------===*/
53
54 int LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
55                               LLVMModuleProviderRef MP,
56                               char **OutError);
57
58 int LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
59                           LLVMModuleProviderRef MP,
60                           char **OutError);
61
62 int LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
63                           LLVMModuleProviderRef MP,
64                           char **OutError);
65
66 void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
67
68 void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
69
70 void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
71
72 int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
73                           unsigned ArgC, const char * const *ArgV,
74                           const char * const *EnvP);
75
76 LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
77                                     unsigned NumArgs,
78                                     LLVMGenericValueRef *Args);
79
80 void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
81
82 void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP);
83
84 int LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
85                              LLVMModuleProviderRef MP,
86                              LLVMModuleRef *OutMod, char **OutError);
87
88 int LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
89                      LLVMValueRef *OutFn);
90
91 #ifdef __cplusplus
92 }
93
94 namespace llvm {
95   class GenericValue;
96   class ExecutionEngine;
97   
98   #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
99     inline ty *unwrap(ref P) {                          \
100       return reinterpret_cast<ty*>(P);                  \
101     }                                                   \
102                                                         \
103     inline ref wrap(const ty *P) {                      \
104       return reinterpret_cast<ref>(const_cast<ty*>(P)); \
105     }
106   
107   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(GenericValue,    LLVMGenericValueRef   )
108   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine, LLVMExecutionEngineRef)
109   
110   #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
111 }
112   
113 #endif /* defined(__cplusplus) */
114
115 #endif