1 /*===----------- llvm-c/OrcBindings.h - Orc Lib C Iface ---------*- C++ -*-===*\
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
5 |* See https://llvm.org/LICENSE.txt for license information. *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
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/Error.h"
26 #include "llvm-c/Object.h"
27 #include "llvm-c/TargetMachine.h"
33 typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
34 typedef uint64_t LLVMOrcModuleHandle;
35 typedef uint64_t LLVMOrcTargetAddress;
36 typedef uint64_t (*LLVMOrcSymbolResolverFn)(const char *Name, void *LookupCtx);
37 typedef uint64_t (*LLVMOrcLazyCompileCallbackFn)(LLVMOrcJITStackRef JITStack,
41 * Create an ORC JIT stack.
43 * The client owns the resulting stack, and must call OrcDisposeInstance(...)
44 * to destroy it and free its memory. The JIT stack will take ownership of the
45 * TargetMachine, which will be destroyed when the stack is destroyed. The
46 * client should not attempt to dispose of the Target Machine, or it will result
49 LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM);
52 * Get the error message for the most recent error (if any).
54 * This message is owned by the ORC JIT Stack and will be freed when the stack
55 * is disposed of by LLVMOrcDisposeInstance.
57 const char *LLVMOrcGetErrorMsg(LLVMOrcJITStackRef JITStack);
60 * Mangle the given symbol.
61 * Memory will be allocated for MangledSymbol to hold the result. The client
63 void LLVMOrcGetMangledSymbol(LLVMOrcJITStackRef JITStack, char **MangledSymbol,
67 * Dispose of a mangled symbol.
69 void LLVMOrcDisposeMangledSymbol(char *MangledSymbol);
72 * Create a lazy compile callback.
74 LLVMErrorRef LLVMOrcCreateLazyCompileCallback(
75 LLVMOrcJITStackRef JITStack, LLVMOrcTargetAddress *RetAddr,
76 LLVMOrcLazyCompileCallbackFn Callback, void *CallbackCtx);
79 * Create a named indirect call stub.
81 LLVMErrorRef LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack,
83 LLVMOrcTargetAddress InitAddr);
86 * Set the pointer for the given indirect stub.
88 LLVMErrorRef LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
90 LLVMOrcTargetAddress NewAddr);
93 * Add module to be eagerly compiled.
95 LLVMErrorRef LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
96 LLVMOrcModuleHandle *RetHandle,
98 LLVMOrcSymbolResolverFn SymbolResolver,
99 void *SymbolResolverCtx);
102 * Add module to be lazily compiled one function at a time.
104 LLVMErrorRef LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
105 LLVMOrcModuleHandle *RetHandle,
107 LLVMOrcSymbolResolverFn SymbolResolver,
108 void *SymbolResolverCtx);
111 * Add an object file.
113 * This method takes ownership of the given memory buffer and attempts to add
114 * it to the JIT as an object file.
115 * Clients should *not* dispose of the 'Obj' argument: the JIT will manage it
116 * from this call onwards.
118 LLVMErrorRef LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
119 LLVMOrcModuleHandle *RetHandle,
120 LLVMMemoryBufferRef Obj,
121 LLVMOrcSymbolResolverFn SymbolResolver,
122 void *SymbolResolverCtx);
125 * Remove a module set from the JIT.
127 * This works for all modules that can be added via OrcAdd*, including object
130 LLVMErrorRef LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack,
131 LLVMOrcModuleHandle H);
134 * Get symbol address from JIT instance.
136 LLVMErrorRef LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
137 LLVMOrcTargetAddress *RetAddr,
138 const char *SymbolName);
141 * Get symbol address from JIT instance, searching only the specified
144 LLVMErrorRef LLVMOrcGetSymbolAddressIn(LLVMOrcJITStackRef JITStack,
145 LLVMOrcTargetAddress *RetAddr,
146 LLVMOrcModuleHandle H,
147 const char *SymbolName);
150 * Dispose of an ORC JIT stack.
152 LLVMErrorRef LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack);
155 * Register a JIT Event Listener.
157 * A NULL listener is ignored.
159 void LLVMOrcRegisterJITEventListener(LLVMOrcJITStackRef JITStack, LLVMJITEventListenerRef L);
162 * Unegister a JIT Event Listener.
164 * A NULL listener is ignored.
166 void LLVMOrcUnregisterJITEventListener(LLVMOrcJITStackRef JITStack, LLVMJITEventListenerRef L);
170 #endif /* extern "C" */
172 #endif /* LLVM_C_ORCBINDINGS_H */