]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm-c/OrcBindings.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r306325, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm-c / OrcBindings.h
1 /*===----------- 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"
26 #include "llvm-c/TargetMachine.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
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,
39                                                  void *CallbackCtx);
40
41 typedef enum { LLVMOrcErrSuccess = 0, LLVMOrcErrGeneric } LLVMOrcErrorCode;
42
43 /**
44  * Turn an LLVMModuleRef into an LLVMSharedModuleRef.
45  *
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).
49  *
50  * Calling this method with an LLVMModuleRef creates a shared-pointer to the
51  * module, and returns a reference to this shared pointer.
52  *
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.
56  */
57
58 LLVMSharedModuleRef LLVMOrcMakeSharedModule(LLVMModuleRef Mod);
59
60 /**
61  * Dispose of a shared module.
62  *
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
65  * shared pointers.
66  */
67
68 void LLVMOrcDisposeSharedModuleRef(LLVMSharedModuleRef SharedMod);
69
70 /**
71  * Get an LLVMSharedObjectBufferRef from an LLVMMemoryBufferRef.
72  */
73 LLVMSharedObjectBufferRef
74 LLVMOrcMakeSharedObjectBuffer(LLVMMemoryBufferRef ObjBuffer);
75
76 /**
77  * Dispose of a shared object buffer.
78  */
79 void
80 LLVMOrcDisposeSharedObjectBufferRef(LLVMSharedObjectBufferRef SharedObjBuffer);
81
82 /**
83  * Create an ORC JIT stack.
84  *
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
89  * in a double-free.
90  */
91 LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM);
92
93 /**
94  * Get the error message for the most recent error (if any).
95  *
96  * This message is owned by the ORC JIT Stack and will be freed when the stack
97  * is disposed of by LLVMOrcDisposeInstance.
98  */
99 const char *LLVMOrcGetErrorMsg(LLVMOrcJITStackRef JITStack);
100
101 /**
102  * Mangle the given symbol.
103  * Memory will be allocated for MangledSymbol to hold the result. The client
104  */
105 void LLVMOrcGetMangledSymbol(LLVMOrcJITStackRef JITStack, char **MangledSymbol,
106                              const char *Symbol);
107
108 /**
109  * Dispose of a mangled symbol.
110  */
111 void LLVMOrcDisposeMangledSymbol(char *MangledSymbol);
112
113 /**
114  * Create a lazy compile callback.
115  */
116 LLVMOrcTargetAddress
117 LLVMOrcCreateLazyCompileCallback(LLVMOrcJITStackRef JITStack,
118                                  LLVMOrcLazyCompileCallbackFn Callback,
119                                  void *CallbackCtx);
120
121 /**
122  * Create a named indirect call stub.
123  */
124 LLVMOrcErrorCode LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack,
125                                            const char *StubName,
126                                            LLVMOrcTargetAddress InitAddr);
127
128 /**
129  * Set the pointer for the given indirect stub.
130  */
131 LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
132                                                const char *StubName,
133                                                LLVMOrcTargetAddress NewAddr);
134
135 /**
136  * Add module to be eagerly compiled.
137  */
138 LLVMOrcModuleHandle
139 LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
140                             LLVMSharedModuleRef Mod,
141                             LLVMOrcSymbolResolverFn SymbolResolver,
142                             void *SymbolResolverCtx);
143
144 /**
145  * Add module to be lazily compiled one function at a time.
146  */
147 LLVMOrcModuleHandle
148 LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
149                            LLVMSharedModuleRef Mod,
150                            LLVMOrcSymbolResolverFn SymbolResolver,
151                            void *SymbolResolverCtx);
152
153 /**
154  * Add an object file.
155  */
156 LLVMOrcModuleHandle LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
157                                          LLVMSharedObjectBufferRef Obj,
158                                          LLVMOrcSymbolResolverFn SymbolResolver,
159                                          void *SymbolResolverCtx);
160
161 /**
162  * Remove a module set from the JIT.
163  *
164  * This works for all modules that can be added via OrcAdd*, including object
165  * files.
166  */
167 void LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack, LLVMOrcModuleHandle H);
168
169 /**
170  * Get symbol address from JIT instance.
171  */
172 LLVMOrcTargetAddress LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
173                                              const char *SymbolName);
174
175 /**
176  * Dispose of an ORC JIT stack.
177  */
178 void LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack);
179
180 #ifdef __cplusplus
181 }
182 #endif /* extern "C" */
183
184 #endif /* LLVM_C_ORCBINDINGS_H */