Home | History | Annotate | Download | only in llvm-c
      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 LLVMLinkInInterpreter(void);
     38 
     39 typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
     40 typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;
     41 
     42 /*===-- Operations on generic values --------------------------------------===*/
     43 
     44 LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
     45                                                 unsigned long long N,
     46                                                 LLVMBool IsSigned);
     47 
     48 LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);
     49 
     50 LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);
     51 
     52 unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
     53 
     54 unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
     55                                          LLVMBool IsSigned);
     56 
     57 void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
     58 
     59 double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);
     60 
     61 void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
     62 
     63 /*===-- Operations on execution engines -----------------------------------===*/
     64 
     65 LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
     66                                             LLVMModuleRef M,
     67                                             char **OutError);
     68 
     69 LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
     70                                         LLVMModuleRef M,
     71                                         char **OutError);
     72 
     73 LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
     74                                         LLVMModuleRef M,
     75                                         unsigned OptLevel,
     76                                         char **OutError);
     77 
     78 /** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */
     79 LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
     80                                    LLVMModuleProviderRef MP,
     81                                    char **OutError);
     82 
     83 /** Deprecated: Use LLVMCreateInterpreterForModule instead. */
     84 LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
     85                                LLVMModuleProviderRef MP,
     86                                char **OutError);
     87 
     88 /** Deprecated: Use LLVMCreateJITCompilerForModule instead. */
     89 LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
     90                                LLVMModuleProviderRef MP,
     91                                unsigned OptLevel,
     92                                char **OutError);
     93 
     94 void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);
     95 
     96 void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
     97 
     98 void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);
     99 
    100 int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
    101                           unsigned ArgC, const char * const *ArgV,
    102                           const char * const *EnvP);
    103 
    104 LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
    105                                     unsigned NumArgs,
    106                                     LLVMGenericValueRef *Args);
    107 
    108 void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
    109 
    110 void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
    111 
    112 /** Deprecated: Use LLVMAddModule instead. */
    113 void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP);
    114 
    115 LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
    116                           LLVMModuleRef *OutMod, char **OutError);
    117 
    118 /** Deprecated: Use LLVMRemoveModule instead. */
    119 LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
    120                                   LLVMModuleProviderRef MP,
    121                                   LLVMModuleRef *OutMod, char **OutError);
    122 
    123 LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
    124                           LLVMValueRef *OutFn);
    125 
    126 void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE, LLVMValueRef Fn);
    127 
    128 LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
    129 
    130 void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
    131                           void* Addr);
    132 
    133 void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
    134 
    135 /**
    136  * @}
    137  */
    138 
    139 #ifdef __cplusplus
    140 }
    141 
    142 namespace llvm {
    143   struct GenericValue;
    144   class ExecutionEngine;
    145 
    146   #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
    147     inline ty *unwrap(ref P) {                          \
    148       return reinterpret_cast<ty*>(P);                  \
    149     }                                                   \
    150                                                         \
    151     inline ref wrap(const ty *P) {                      \
    152       return reinterpret_cast<ref>(const_cast<ty*>(P)); \
    153     }
    154 
    155   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(GenericValue,    LLVMGenericValueRef   )
    156   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine, LLVMExecutionEngineRef)
    157 
    158   #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
    159 }
    160 
    161 #endif /* defined(__cplusplus) */
    162 
    163 #endif
    164