[ARM] Generate 8.1-m CSINC, CSNEG and CSINV instructions.
[llvm-core.git] / lib / ExecutionEngine / Orc / OrcCBindings.cpp
blob28c8479abba448be2154b87ec39c9f7a6af90c66
1 //===----------- OrcCBindings.cpp - C bindings for the Orc APIs -----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "OrcCBindingsStack.h"
10 #include "llvm-c/OrcBindings.h"
11 #include "llvm/ExecutionEngine/JITEventListener.h"
13 using namespace llvm;
15 LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM) {
16 TargetMachine *TM2(unwrap(TM));
18 Triple T(TM2->getTargetTriple());
20 auto IndirectStubsMgrBuilder =
21 orc::createLocalIndirectStubsManagerBuilder(T);
23 OrcCBindingsStack *JITStack =
24 new OrcCBindingsStack(*TM2, std::move(IndirectStubsMgrBuilder));
26 return wrap(JITStack);
29 const char *LLVMOrcGetErrorMsg(LLVMOrcJITStackRef JITStack) {
30 OrcCBindingsStack &J = *unwrap(JITStack);
31 return J.getErrorMessage().c_str();
34 void LLVMOrcGetMangledSymbol(LLVMOrcJITStackRef JITStack, char **MangledName,
35 const char *SymbolName) {
36 OrcCBindingsStack &J = *unwrap(JITStack);
37 std::string Mangled = J.mangle(SymbolName);
38 *MangledName = new char[Mangled.size() + 1];
39 strcpy(*MangledName, Mangled.c_str());
42 void LLVMOrcDisposeMangledSymbol(char *MangledName) { delete[] MangledName; }
44 LLVMErrorRef LLVMOrcCreateLazyCompileCallback(
45 LLVMOrcJITStackRef JITStack, LLVMOrcTargetAddress *RetAddr,
46 LLVMOrcLazyCompileCallbackFn Callback, void *CallbackCtx) {
47 OrcCBindingsStack &J = *unwrap(JITStack);
48 if (auto Addr = J.createLazyCompileCallback(Callback, CallbackCtx)) {
49 *RetAddr = *Addr;
50 return LLVMErrorSuccess;
51 } else
52 return wrap(Addr.takeError());
55 LLVMErrorRef LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack,
56 const char *StubName,
57 LLVMOrcTargetAddress InitAddr) {
58 OrcCBindingsStack &J = *unwrap(JITStack);
59 return wrap(J.createIndirectStub(StubName, InitAddr));
62 LLVMErrorRef LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
63 const char *StubName,
64 LLVMOrcTargetAddress NewAddr) {
65 OrcCBindingsStack &J = *unwrap(JITStack);
66 return wrap(J.setIndirectStubPointer(StubName, NewAddr));
69 LLVMErrorRef LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
70 LLVMOrcModuleHandle *RetHandle,
71 LLVMModuleRef Mod,
72 LLVMOrcSymbolResolverFn SymbolResolver,
73 void *SymbolResolverCtx) {
74 OrcCBindingsStack &J = *unwrap(JITStack);
75 std::unique_ptr<Module> M(unwrap(Mod));
76 if (auto Handle =
77 J.addIRModuleEager(std::move(M), SymbolResolver, SymbolResolverCtx)) {
78 *RetHandle = *Handle;
79 return LLVMErrorSuccess;
80 } else
81 return wrap(Handle.takeError());
84 LLVMErrorRef LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
85 LLVMOrcModuleHandle *RetHandle,
86 LLVMModuleRef Mod,
87 LLVMOrcSymbolResolverFn SymbolResolver,
88 void *SymbolResolverCtx) {
89 OrcCBindingsStack &J = *unwrap(JITStack);
90 std::unique_ptr<Module> M(unwrap(Mod));
91 if (auto Handle =
92 J.addIRModuleLazy(std::move(M), SymbolResolver, SymbolResolverCtx)) {
93 *RetHandle = *Handle;
94 return LLVMErrorSuccess;
95 } else
96 return wrap(Handle.takeError());
99 LLVMErrorRef LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
100 LLVMOrcModuleHandle *RetHandle,
101 LLVMMemoryBufferRef Obj,
102 LLVMOrcSymbolResolverFn SymbolResolver,
103 void *SymbolResolverCtx) {
104 OrcCBindingsStack &J = *unwrap(JITStack);
105 std::unique_ptr<MemoryBuffer> O(unwrap(Obj));
106 if (auto Handle =
107 J.addObject(std::move(O), SymbolResolver, SymbolResolverCtx)) {
108 *RetHandle = *Handle;
109 return LLVMErrorSuccess;
110 } else
111 return wrap(Handle.takeError());
114 LLVMErrorRef LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack,
115 LLVMOrcModuleHandle H) {
116 OrcCBindingsStack &J = *unwrap(JITStack);
117 return wrap(J.removeModule(H));
120 LLVMErrorRef LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
121 LLVMOrcTargetAddress *RetAddr,
122 const char *SymbolName) {
123 OrcCBindingsStack &J = *unwrap(JITStack);
124 if (auto Addr = J.findSymbolAddress(SymbolName, true)) {
125 *RetAddr = *Addr;
126 return LLVMErrorSuccess;
127 } else
128 return wrap(Addr.takeError());
131 LLVMErrorRef LLVMOrcGetSymbolAddressIn(LLVMOrcJITStackRef JITStack,
132 LLVMOrcTargetAddress *RetAddr,
133 LLVMOrcModuleHandle H,
134 const char *SymbolName) {
135 OrcCBindingsStack &J = *unwrap(JITStack);
136 if (auto Addr = J.findSymbolAddressIn(H, SymbolName, true)) {
137 *RetAddr = *Addr;
138 return LLVMErrorSuccess;
139 } else
140 return wrap(Addr.takeError());
143 LLVMErrorRef LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack) {
144 auto *J = unwrap(JITStack);
145 auto Err = J->shutdown();
146 delete J;
147 return wrap(std::move(Err));
150 void LLVMOrcRegisterJITEventListener(LLVMOrcJITStackRef JITStack, LLVMJITEventListenerRef L)
152 unwrap(JITStack)->RegisterJITEventListener(unwrap(L));
155 void LLVMOrcUnregisterJITEventListener(LLVMOrcJITStackRef JITStack, LLVMJITEventListenerRef L)
157 unwrap(JITStack)->UnregisterJITEventListener(unwrap(L));