ExecutionEngine.h revision d2755af8bda2e0fd80efb46556485c4cdbe8704a
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 26extern "C" { 27#endif 28 29/** 30 * @defgroup LLVMCExecutionEngine Execution Engine 31 * @ingroup LLVMC 32 * 33 * @{ 34 */ 35 36void LLVMLinkInJIT(void); 37void LLVMLinkInMCJIT(void); 38void LLVMLinkInInterpreter(void); 39 40typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef; 41typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef; 42 43struct LLVMMCJITCompilerOptions { 44 unsigned OptLevel; 45 LLVMBool NoFramePointerElim; 46}; 47 48/*===-- Operations on generic values --------------------------------------===*/ 49 50LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty, 51 unsigned long long N, 52 LLVMBool IsSigned); 53 54LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P); 55 56LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N); 57 58unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef); 59 60unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal, 61 LLVMBool IsSigned); 62 63void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal); 64 65double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal); 66 67void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal); 68 69/*===-- Operations on execution engines -----------------------------------===*/ 70 71LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE, 72 LLVMModuleRef M, 73 char **OutError); 74 75LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp, 76 LLVMModuleRef M, 77 char **OutError); 78 79LLVMBool 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 */ 100LLVMBool LLVMCreateMCJITCompilerForModule(LLVMExecutionEngineRef *OutJIT, 101 LLVMModuleRef M, 102 struct LLVMMCJITCompilerOptions *Options, 103 size_t SizeOfOptions, 104 char **OutError); 105 106/** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */ 107LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE, 108 LLVMModuleProviderRef MP, 109 char **OutError); 110 111/** Deprecated: Use LLVMCreateInterpreterForModule instead. */ 112LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp, 113 LLVMModuleProviderRef MP, 114 char **OutError); 115 116/** Deprecated: Use LLVMCreateJITCompilerForModule instead. */ 117LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT, 118 LLVMModuleProviderRef MP, 119 unsigned OptLevel, 120 char **OutError); 121 122void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE); 123 124void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE); 125 126void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE); 127 128int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F, 129 unsigned ArgC, const char * const *ArgV, 130 const char * const *EnvP); 131 132LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F, 133 unsigned NumArgs, 134 LLVMGenericValueRef *Args); 135 136void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F); 137 138void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M); 139 140/** Deprecated: Use LLVMAddModule instead. */ 141void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP); 142 143LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M, 144 LLVMModuleRef *OutMod, char **OutError); 145 146/** Deprecated: Use LLVMRemoveModule instead. */ 147LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE, 148 LLVMModuleProviderRef MP, 149 LLVMModuleRef *OutMod, char **OutError); 150 151LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name, 152 LLVMValueRef *OutFn); 153 154void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE, LLVMValueRef Fn); 155 156LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE); 157 158void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global, 159 void* Addr); 160 161void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global); 162 163/** 164 * @} 165 */ 166 167#ifdef __cplusplus 168} 169#endif /* defined(__cplusplus) */ 170 171#endif 172