blob: cfa6f521bf1be8034209637d43fe780ddcf45330 [file] [log] [blame]
Gordon Henriksen2e855e62007-12-23 16:59:28 +00001/*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
Chris Lattner7ed47a12007-12-29 19:59:42 +00005|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
Gordon Henriksen2e855e62007-12-23 16:59:28 +00007|* *|
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
25extern "C" {
26#endif
27
28typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
29typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
30
31/*===-- Operations on generic values --------------------------------------===*/
32
33LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
34 unsigned long long N,
35 int IsSigned);
36
37LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
38
39LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
40
41unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
42
43unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
44 int IsSigned);
45
46void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
47
48double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
49
50void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
51
52/*===-- Operations on execution engines -----------------------------------===*/
53
54int LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
55 LLVMModuleProviderRef MP,
56 char **OutError);
57
58int LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
59 LLVMModuleProviderRef MP,
60 char **OutError);
61
62int LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
63 LLVMModuleProviderRef MP,
64 char **OutError);
65
66void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
67
68void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
69
70void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
71
72int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
73 unsigned ArgC, const char * const *ArgV,
74 const char * const *EnvP);
75
76LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
77 unsigned NumArgs,
78 LLVMGenericValueRef *Args);
79
80void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
81
82void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP);
83
84int LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
85 LLVMModuleProviderRef MP,
86 LLVMModuleRef *OutMod, char **OutError);
87
88int LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
89 LLVMValueRef *OutFn);
90
91#ifdef __cplusplus
92}
93
94namespace 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