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 LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
33 typedef uint32_t LLVMOrcModuleHandle;
34 typedef uint64_t LLVMOrcTargetAddress;
35 typedef uint64_t (*LLVMOrcSymbolResolverFn)(const char *Name, void *LookupCtx);
36 typedef uint64_t (*LLVMOrcLazyCompileCallbackFn)(LLVMOrcJITStackRef JITStack,
39 typedef enum { LLVMOrcErrSuccess = 0, LLVMOrcErrGeneric } LLVMOrcErrorCode;
42 * Create an ORC JIT stack.
44 * The client owns the resulting stack, and must call OrcDisposeInstance(...)
45 * to destroy it and free its memory. The JIT stack will take ownership of the
46 * TargetMachine, which will be destroyed when the stack is destroyed. The
47 * client should not attempt to dispose of the Target Machine, or it will result
50 LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM);
53 * Get the error message for the most recent error (if any).
55 * This message is owned by the ORC JIT Stack and will be freed when the stack
56 * is disposed of by LLVMOrcDisposeInstance.
58 const char *LLVMOrcGetErrorMsg(LLVMOrcJITStackRef JITStack);
61 * Mangle the given symbol.
62 * Memory will be allocated for MangledSymbol to hold the result. The client
64 void LLVMOrcGetMangledSymbol(LLVMOrcJITStackRef JITStack, char **MangledSymbol,
68 * Dispose of a mangled symbol.
70 void LLVMOrcDisposeMangledSymbol(char *MangledSymbol);
73 * Create a lazy compile callback.
76 LLVMOrcCreateLazyCompileCallback(LLVMOrcJITStackRef JITStack,
77 LLVMOrcLazyCompileCallbackFn Callback,
81 * Create a named indirect call stub.
83 LLVMOrcErrorCode LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack,
85 LLVMOrcTargetAddress InitAddr);
88 * Set the pointer for the given indirect stub.
90 LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
92 LLVMOrcTargetAddress NewAddr);
95 * Add module to be eagerly compiled.
98 LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
99 LLVMOrcSymbolResolverFn SymbolResolver,
100 void *SymbolResolverCtx);
103 * Add module to be lazily compiled one function at a time.
106 LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
107 LLVMOrcSymbolResolverFn SymbolResolver,
108 void *SymbolResolverCtx);
111 * Add an object file.
113 LLVMOrcModuleHandle LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
114 LLVMObjectFileRef Obj,
115 LLVMOrcSymbolResolverFn SymbolResolver,
116 void *SymbolResolverCtx);
119 * Remove a module set from the JIT.
121 * This works for all modules that can be added via OrcAdd*, including object
124 void LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack, LLVMOrcModuleHandle H);
127 * Get symbol address from JIT instance.
129 LLVMOrcTargetAddress LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
130 const char *SymbolName);
133 * Dispose of an ORC JIT stack.
135 void LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack);
139 #endif /* extern "C" */
141 #endif /* LLVM_C_ORCBINDINGS_H */