1 /*===----------- llvm-c/OrcBindings.h - Orc 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 libLLVMOrcJIT.a, which implements *| 11 |* JIT compilation of 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 |* Note: This interface is experimental. It is *NOT* stable, and may be *| 18 |* changed without warning. *| 19 |* *| 20 \*===----------------------------------------------------------------------===*/ 21 22 module llvm.c.orcBinding; 23 24 import llvm.c.object; 25 import llvm.c.targetMachine; 26 27 extern(C) nothrow: 28 29 struct LLVMOrcOpaqueJITStack {}; 30 alias LLVMOrcJITStackRef = LLVMOrcOpaqueJITStack*; 31 alias LLVMOrcModuleHandle = uint; 32 alias LLVMOrcTargetAddress = ulong; 33 alias LLVMOrcSymbolResolverFn = ulong function(const(char)* Name, 34 void* LookupCtx); 35 alias LLVMOrcLazyCompileCallbackFn = ulong function(LLVMOrcJITStackRef JITStack, 36 void *CallbackCtx); 37 38 enum LLVMOrcErrorCode { 39 Success = 0, 40 Generic, 41 } 42 43 /** 44 * Create an ORC JIT stack. 45 * 46 * The client owns the resulting stack, and must call OrcDisposeInstance(...) 47 * to destroy it and free its memory. The JIT stack will take ownership of the 48 * TargetMachine, which will be destroyed when the stack is destroyed. The 49 * client should not attempt to dispose of the Target Machine, or it will result 50 * in a double-free. 51 */ 52 LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM); 53 54 /** 55 * Get the error message for the most recent error (if any). 56 * 57 * This message is owned by the ORC JIT Stack and will be freed when the stack 58 * is disposed of by LLVMOrcDisposeInstance. 59 */ 60 const(char)* LLVMOrcGetErrorMsg(LLVMOrcJITStackRef JITStack); 61 62 /** 63 * Mangle the given symbol. 64 * Memory will be allocated for MangledSymbol to hold the result. The client 65 */ 66 void LLVMOrcGetMangledSymbol(LLVMOrcJITStackRef JITStack, char** MangledSymbol, 67 const(char)* Symbol); 68 69 /** 70 * Dispose of a mangled symbol. 71 */ 72 void LLVMOrcDisposeMangledSymbol(char* MangledSymbol); 73 74 /** 75 * Create a lazy compile callback. 76 */ 77 LLVMOrcTargetAddress 78 LLVMOrcCreateLazyCompileCallback(LLVMOrcJITStackRef JITStack, 79 LLVMOrcLazyCompileCallbackFn Callback, 80 void* CallbackCtx); 81 82 /** 83 * Create a named indirect call stub. 84 */ 85 LLVMOrcErrorCode LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack, 86 const(char)* StubName, 87 LLVMOrcTargetAddress InitAddr); 88 89 /** 90 * Set the pointer for the given indirect stub. 91 */ 92 LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack, 93 const(char)* StubName, 94 LLVMOrcTargetAddress NewAddr); 95 96 /** 97 * Add module to be eagerly compiled. 98 */ 99 LLVMOrcModuleHandle 100 LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod, 101 LLVMOrcSymbolResolverFn SymbolResolver, 102 void* SymbolResolverCtx); 103 104 /** 105 * Add module to be lazily compiled one function at a time. 106 */ 107 LLVMOrcModuleHandle 108 LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod, 109 LLVMOrcSymbolResolverFn SymbolResolver, 110 void* SymbolResolverCtx); 111 112 /** 113 * Add an object file. 114 */ 115 LLVMOrcModuleHandle 116 LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack, LLVMObjectFileRef Obj, 117 LLVMOrcSymbolResolverFn SymbolResolver, 118 void* SymbolResolverCtx); 119 120 /** 121 * Remove a module set from the JIT. 122 * 123 * This works for all modules that can be added via OrcAdd*, including object 124 * files. 125 */ 126 void LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack, LLVMOrcModuleHandle H); 127 128 /** 129 * Get symbol address from JIT instance. 130 */ 131 LLVMOrcTargetAddress LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack, 132 const(char)* SymbolName); 133 134 /** 135 * Dispose of an ORC JIT stack. 136 */ 137 void LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack);