blob: d2e2e7de4d3c8223f5dcba548b9b4f0d022fea8b [file] [log] [blame]
Lang Hames130a7c42015-10-28 02:40:04 +00001/*===----------- 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#ifndef LLVM_C_ORCBINDINGS_H
23#define LLVM_C_ORCBINDINGS_H
24
25#include "llvm-c/Object.h"
Lang Hames130a7c42015-10-28 02:40:04 +000026#include "llvm-c/TargetMachine.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
Lang Hames0976cee2018-02-09 02:30:40 +000033typedef uint64_t LLVMOrcModuleHandle;
Lang Hames130a7c42015-10-28 02:40:04 +000034typedef uint64_t LLVMOrcTargetAddress;
Lang Hames1fa0e0e2016-04-25 21:21:20 +000035typedef uint64_t (*LLVMOrcSymbolResolverFn)(const char *Name, void *LookupCtx);
Lang Hamesfd6e8dc2015-10-30 03:20:21 +000036typedef uint64_t (*LLVMOrcLazyCompileCallbackFn)(LLVMOrcJITStackRef JITStack,
37 void *CallbackCtx);
Lang Hames130a7c42015-10-28 02:40:04 +000038
Lang Hames1fa0e0e2016-04-25 21:21:20 +000039typedef enum { LLVMOrcErrSuccess = 0, LLVMOrcErrGeneric } LLVMOrcErrorCode;
Lang Hamesef5a0ee2016-04-25 19:56:45 +000040
Lang Hames130a7c42015-10-28 02:40:04 +000041/**
42 * Create an ORC JIT stack.
43 *
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
48 * in a double-free.
49 */
Rafael Espindolae63e0182015-11-03 16:40:37 +000050LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM);
Lang Hames130a7c42015-10-28 02:40:04 +000051
52/**
Lang Hamesef5a0ee2016-04-25 19:56:45 +000053 * Get the error message for the most recent error (if any).
54 *
55 * This message is owned by the ORC JIT Stack and will be freed when the stack
56 * is disposed of by LLVMOrcDisposeInstance.
57 */
58const char *LLVMOrcGetErrorMsg(LLVMOrcJITStackRef JITStack);
59
60/**
Lang Hames130a7c42015-10-28 02:40:04 +000061 * Mangle the given symbol.
62 * Memory will be allocated for MangledSymbol to hold the result. The client
63 */
64void LLVMOrcGetMangledSymbol(LLVMOrcJITStackRef JITStack, char **MangledSymbol,
65 const char *Symbol);
66
67/**
68 * Dispose of a mangled symbol.
69 */
Lang Hames130a7c42015-10-28 02:40:04 +000070void LLVMOrcDisposeMangledSymbol(char *MangledSymbol);
71
72/**
Lang Hamesfd6e8dc2015-10-30 03:20:21 +000073 * Create a lazy compile callback.
74 */
Lang Hames4ce98662017-07-07 02:59:13 +000075LLVMOrcErrorCode
Lang Hamesfd6e8dc2015-10-30 03:20:21 +000076LLVMOrcCreateLazyCompileCallback(LLVMOrcJITStackRef JITStack,
Lang Hames4ce98662017-07-07 02:59:13 +000077 LLVMOrcTargetAddress *RetAddr,
Lang Hamesfd6e8dc2015-10-30 03:20:21 +000078 LLVMOrcLazyCompileCallbackFn Callback,
79 void *CallbackCtx);
80
81/**
82 * Create a named indirect call stub.
83 */
Lang Hamesef5a0ee2016-04-25 19:56:45 +000084LLVMOrcErrorCode LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack,
85 const char *StubName,
86 LLVMOrcTargetAddress InitAddr);
Lang Hamesfd6e8dc2015-10-30 03:20:21 +000087
88/**
89 * Set the pointer for the given indirect stub.
90 */
Lang Hamesef5a0ee2016-04-25 19:56:45 +000091LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
92 const char *StubName,
93 LLVMOrcTargetAddress NewAddr);
Lang Hamesfd6e8dc2015-10-30 03:20:21 +000094
95/**
Lang Hames130a7c42015-10-28 02:40:04 +000096 * Add module to be eagerly compiled.
97 */
Lang Hames4ce98662017-07-07 02:59:13 +000098LLVMOrcErrorCode
Lang Hamescd9d49b2017-06-23 23:25:28 +000099LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
Lang Hames5721ee42018-03-15 00:30:14 +0000100 LLVMOrcModuleHandle *RetHandle, LLVMModuleRef Mod,
Lang Hames130a7c42015-10-28 02:40:04 +0000101 LLVMOrcSymbolResolverFn SymbolResolver,
102 void *SymbolResolverCtx);
103
104/**
105 * Add module to be lazily compiled one function at a time.
106 */
Lang Hames4ce98662017-07-07 02:59:13 +0000107LLVMOrcErrorCode
Lang Hamescd9d49b2017-06-23 23:25:28 +0000108LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
Lang Hames5721ee42018-03-15 00:30:14 +0000109 LLVMOrcModuleHandle *RetHandle, LLVMModuleRef Mod,
Lang Hames130a7c42015-10-28 02:40:04 +0000110 LLVMOrcSymbolResolverFn SymbolResolver,
111 void *SymbolResolverCtx);
112
113/**
114 * Add an object file.
Lang Hamesec300632017-09-17 03:25:03 +0000115 *
116 * This method takes ownership of the given memory buffer and attempts to add
117 * it to the JIT as an object file.
118 * Clients should *not* dispose of the 'Obj' argument: the JIT will manage it
119 * from this call onwards.
Lang Hames130a7c42015-10-28 02:40:04 +0000120 */
Lang Hames4ce98662017-07-07 02:59:13 +0000121LLVMOrcErrorCode LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
122 LLVMOrcModuleHandle *RetHandle,
Lang Hamesec300632017-09-17 03:25:03 +0000123 LLVMMemoryBufferRef Obj,
Lang Hames4ce98662017-07-07 02:59:13 +0000124 LLVMOrcSymbolResolverFn SymbolResolver,
125 void *SymbolResolverCtx);
Lang Hames130a7c42015-10-28 02:40:04 +0000126
127/**
128 * Remove a module set from the JIT.
129 *
130 * This works for all modules that can be added via OrcAdd*, including object
131 * files.
132 */
Lang Hames4ce98662017-07-07 02:59:13 +0000133LLVMOrcErrorCode LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack,
134 LLVMOrcModuleHandle H);
Lang Hames130a7c42015-10-28 02:40:04 +0000135
136/**
137 * Get symbol address from JIT instance.
138 */
Lang Hames4ce98662017-07-07 02:59:13 +0000139LLVMOrcErrorCode LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
140 LLVMOrcTargetAddress *RetAddr,
141 const char *SymbolName);
Lang Hames130a7c42015-10-28 02:40:04 +0000142
143/**
144 * Dispose of an ORC JIT stack.
145 */
Lang Hames4ce98662017-07-07 02:59:13 +0000146LLVMOrcErrorCode LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack);
Lang Hames130a7c42015-10-28 02:40:04 +0000147
148#ifdef __cplusplus
149}
150#endif /* extern "C" */
151
152#endif /* LLVM_C_ORCBINDINGS_H */