1 /*===----------- llvm-c/OrcBindings.h - Orc Lib C Iface ---------*- C++ -*-===*\
3 |* The LLVM Compiler Infrastructure *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
8 |*===----------------------------------------------------------------------===*|
10 |* This header declares the C interface to libLLVMOrcJIT.a, which implements *|
11 |* JIT compilation of LLVM IR. *|
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. *|
17 |* Note: This interface is experimental. It is *NOT* stable, and may be *|
18 |* changed without warning. *|
20 \*===----------------------------------------------------------------------===*/
22 #ifndef LLVM_C_ORCBINDINGS_H
23 #define LLVM_C_ORCBINDINGS_H
25 #include "llvm-c/Object.h"
26 #include "llvm-c/TargetMachine.h"
32 typedef struct LLVMOpaqueSharedModule *LLVMSharedModuleRef;
33 typedef struct LLVMOpaqueSharedObjectBuffer *LLVMSharedObjectBufferRef;
34 typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
35 typedef uint32_t LLVMOrcModuleHandle;
36 typedef uint64_t LLVMOrcTargetAddress;
37 typedef uint64_t (*LLVMOrcSymbolResolverFn)(const char *Name, void *LookupCtx);
38 typedef uint64_t (*LLVMOrcLazyCompileCallbackFn)(LLVMOrcJITStackRef JITStack,
41 typedef enum { LLVMOrcErrSuccess = 0, LLVMOrcErrGeneric } LLVMOrcErrorCode;
44 * Turn an LLVMModuleRef into an LLVMSharedModuleRef.
46 * The JIT uses shared ownership for LLVM modules, since it is generally
47 * difficult to know when the JIT will be finished with a module (and the JIT
48 * has no way of knowing when a user may be finished with one).
50 * Calling this method with an LLVMModuleRef creates a shared-pointer to the
51 * module, and returns a reference to this shared pointer.
53 * The shared module should be disposed when finished with by calling
54 * LLVMOrcDisposeSharedModule (not LLVMDisposeModule). The Module will be
55 * deleted when the last shared pointer owner relinquishes it.
58 LLVMSharedModuleRef LLVMOrcMakeSharedModule(LLVMModuleRef Mod);
61 * Dispose of a shared module.
63 * The module should not be accessed after this call. The module will be
64 * deleted once all clients (including the JIT itself) have released their
68 void LLVMOrcDisposeSharedModuleRef(LLVMSharedModuleRef SharedMod);
71 * Get an LLVMSharedObjectBufferRef from an LLVMMemoryBufferRef.
73 LLVMSharedObjectBufferRef
74 LLVMOrcMakeSharedObjectBuffer(LLVMMemoryBufferRef ObjBuffer);
77 * Dispose of a shared object buffer.
80 LLVMOrcDisposeSharedObjectBufferRef(LLVMSharedObjectBufferRef SharedObjBuffer);
83 * Create an ORC JIT stack.
85 * The client owns the resulting stack, and must call OrcDisposeInstance(...)
86 * to destroy it and free its memory. The JIT stack will take ownership of the
87 * TargetMachine, which will be destroyed when the stack is destroyed. The
88 * client should not attempt to dispose of the Target Machine, or it will result
91 LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM);
94 * Get the error message for the most recent error (if any).
96 * This message is owned by the ORC JIT Stack and will be freed when the stack
97 * is disposed of by LLVMOrcDisposeInstance.
99 const char *LLVMOrcGetErrorMsg(LLVMOrcJITStackRef JITStack);
102 * Mangle the given symbol.
103 * Memory will be allocated for MangledSymbol to hold the result. The client
105 void LLVMOrcGetMangledSymbol(LLVMOrcJITStackRef JITStack, char **MangledSymbol,
109 * Dispose of a mangled symbol.
111 void LLVMOrcDisposeMangledSymbol(char *MangledSymbol);
114 * Create a lazy compile callback.
117 LLVMOrcCreateLazyCompileCallback(LLVMOrcJITStackRef JITStack,
118 LLVMOrcTargetAddress *RetAddr,
119 LLVMOrcLazyCompileCallbackFn Callback,
123 * Create a named indirect call stub.
125 LLVMOrcErrorCode LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack,
126 const char *StubName,
127 LLVMOrcTargetAddress InitAddr);
130 * Set the pointer for the given indirect stub.
132 LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
133 const char *StubName,
134 LLVMOrcTargetAddress NewAddr);
137 * Add module to be eagerly compiled.
140 LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
141 LLVMOrcModuleHandle *RetHandle,
142 LLVMSharedModuleRef Mod,
143 LLVMOrcSymbolResolverFn SymbolResolver,
144 void *SymbolResolverCtx);
147 * Add module to be lazily compiled one function at a time.
150 LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
151 LLVMOrcModuleHandle *RetHandle,
152 LLVMSharedModuleRef Mod,
153 LLVMOrcSymbolResolverFn SymbolResolver,
154 void *SymbolResolverCtx);
157 * Add an object file.
159 LLVMOrcErrorCode LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
160 LLVMOrcModuleHandle *RetHandle,
161 LLVMSharedObjectBufferRef Obj,
162 LLVMOrcSymbolResolverFn SymbolResolver,
163 void *SymbolResolverCtx);
166 * Remove a module set from the JIT.
168 * This works for all modules that can be added via OrcAdd*, including object
171 LLVMOrcErrorCode LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack,
172 LLVMOrcModuleHandle H);
175 * Get symbol address from JIT instance.
177 LLVMOrcErrorCode LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
178 LLVMOrcTargetAddress *RetAddr,
179 const char *SymbolName);
182 * Dispose of an ORC JIT stack.
184 LLVMOrcErrorCode LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack);
188 #endif /* extern "C" */
190 #endif /* LLVM_C_ORCBINDINGS_H */