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 LLVMOrcLazyCompileCallbackFn Callback,
122 * Create a named indirect call stub.
124 LLVMOrcErrorCode LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack,
125 const char *StubName,
126 LLVMOrcTargetAddress InitAddr);
129 * Set the pointer for the given indirect stub.
131 LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
132 const char *StubName,
133 LLVMOrcTargetAddress NewAddr);
136 * Add module to be eagerly compiled.
139 LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
140 LLVMSharedModuleRef Mod,
141 LLVMOrcSymbolResolverFn SymbolResolver,
142 void *SymbolResolverCtx);
145 * Add module to be lazily compiled one function at a time.
148 LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
149 LLVMSharedModuleRef Mod,
150 LLVMOrcSymbolResolverFn SymbolResolver,
151 void *SymbolResolverCtx);
154 * Add an object file.
156 LLVMOrcModuleHandle LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
157 LLVMSharedObjectBufferRef Obj,
158 LLVMOrcSymbolResolverFn SymbolResolver,
159 void *SymbolResolverCtx);
162 * Remove a module set from the JIT.
164 * This works for all modules that can be added via OrcAdd*, including object
167 void LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack, LLVMOrcModuleHandle H);
170 * Get symbol address from JIT instance.
172 LLVMOrcTargetAddress LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
173 const char *SymbolName);
176 * Dispose of an ORC JIT stack.
178 void LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack);
182 #endif /* extern "C" */
184 #endif /* LLVM_C_ORCBINDINGS_H */