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/Support.h"
27 #include "llvm-c/TargetMachine.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
34 typedef uint32_t LLVMOrcModuleHandle;
35 typedef uint64_t LLVMOrcTargetAddress;
36 typedef uint64_t (*LLVMOrcSymbolResolverFn)(const char *Name,
37                                             void *LookupCtx);
38 typedef uint64_t (*LLVMOrcLazyCompileCallbackFn)(LLVMOrcJITStackRef JITStack,
39                                                  void *CallbackCtx);
40 
41 /**
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  */
50 LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM);
51 
52 /**
53  * Mangle the given symbol.
54  * Memory will be allocated for MangledSymbol to hold the result. The client
55  */
56 void LLVMOrcGetMangledSymbol(LLVMOrcJITStackRef JITStack, char **MangledSymbol,
57                              const char *Symbol);
58 
59 /**
60  * Dispose of a mangled symbol.
61  */
62 
63 void LLVMOrcDisposeMangledSymbol(char *MangledSymbol);
64 
65 /**
66  * Create a lazy compile callback.
67  */
68 LLVMOrcTargetAddress
69 LLVMOrcCreateLazyCompileCallback(LLVMOrcJITStackRef JITStack,
70                                  LLVMOrcLazyCompileCallbackFn Callback,
71                                  void *CallbackCtx);
72 
73 /**
74  * Create a named indirect call stub.
75  */
76 void LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack,
77                                const char *StubName,
78                                LLVMOrcTargetAddress InitAddr);
79 
80 /**
81  * Set the pointer for the given indirect stub.
82  */
83 void LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
84                                    const char *StubName,
85                                    LLVMOrcTargetAddress NewAddr);
86 
87 /**
88  * Add module to be eagerly compiled.
89  */
90 LLVMOrcModuleHandle
91 LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
92                             LLVMOrcSymbolResolverFn SymbolResolver,
93                             void *SymbolResolverCtx);
94 
95 /**
96  * Add module to be lazily compiled one function at a time.
97  */
98 LLVMOrcModuleHandle
99 LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
100                            LLVMOrcSymbolResolverFn SymbolResolver,
101                            void *SymbolResolverCtx);
102 
103 /**
104  * Add an object file.
105  */
106 LLVMOrcModuleHandle
107 LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack, LLVMObjectFileRef Obj,
108                      LLVMOrcSymbolResolverFn SymbolResolver,
109                      void *SymbolResolverCtx);
110 
111 /**
112  * Remove a module set from the JIT.
113  *
114  * This works for all modules that can be added via OrcAdd*, including object
115  * files.
116  */
117 void LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack, LLVMOrcModuleHandle H);
118 
119 /**
120  * Get symbol address from JIT instance.
121  */
122 LLVMOrcTargetAddress LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
123                                              const char *SymbolName);
124 
125 /**
126  * Dispose of an ORC JIT stack.
127  */
128 void LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack);
129 
130 #ifdef __cplusplus
131 }
132 #endif /* extern "C" */
133 
134 #endif /* LLVM_C_ORCBINDINGS_H */
135