[llvm] r342828 - [ORC] Update ORC C bindings to use the new llvm::Error C API.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 22 19:09:18 PDT 2018
Author: lhames
Date: Sat Sep 22 19:09:18 2018
New Revision: 342828
URL: http://llvm.org/viewvc/llvm-project?rev=342828&view=rev
Log:
[ORC] Update ORC C bindings to use the new llvm::Error C API.
This replaces instances of the LLVMOrcErrorCode type with LLVMErrorRef,
simplifying the implementation of the OrcCBindingsStack class and ORC
C API bindings and making it possible to return arbitrary (wrapped)
llvm::Errors.
Modified:
llvm/trunk/include/llvm-c/Error.h
llvm/trunk/include/llvm-c/OrcBindings.h
llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindings.cpp
llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h
Modified: llvm/trunk/include/llvm-c/Error.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Error.h?rev=342828&r1=342827&r2=342828&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/Error.h (original)
+++ llvm/trunk/include/llvm-c/Error.h Sat Sep 22 19:09:18 2018
@@ -18,6 +18,8 @@
extern "C" {
#endif
+#define LLVMErrorSuccess 0
+
/**
* Opaque reference to an error instance. Null serves as the 'success' value.
*/
Modified: llvm/trunk/include/llvm-c/OrcBindings.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/OrcBindings.h?rev=342828&r1=342827&r2=342828&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/OrcBindings.h (original)
+++ llvm/trunk/include/llvm-c/OrcBindings.h Sat Sep 22 19:09:18 2018
@@ -22,6 +22,7 @@
#ifndef LLVM_C_ORCBINDINGS_H
#define LLVM_C_ORCBINDINGS_H
+#include "llvm-c/Error.h"
#include "llvm-c/Object.h"
#include "llvm-c/TargetMachine.h"
@@ -36,8 +37,6 @@ typedef uint64_t (*LLVMOrcSymbolResolver
typedef uint64_t (*LLVMOrcLazyCompileCallbackFn)(LLVMOrcJITStackRef JITStack,
void *CallbackCtx);
-typedef enum { LLVMOrcErrSuccess = 0, LLVMOrcErrGeneric } LLVMOrcErrorCode;
-
/**
* Create an ORC JIT stack.
*
@@ -72,43 +71,41 @@ void LLVMOrcDisposeMangledSymbol(char *M
/**
* Create a lazy compile callback.
*/
-LLVMOrcErrorCode
-LLVMOrcCreateLazyCompileCallback(LLVMOrcJITStackRef JITStack,
- LLVMOrcTargetAddress *RetAddr,
- LLVMOrcLazyCompileCallbackFn Callback,
- void *CallbackCtx);
+LLVMErrorRef LLVMOrcCreateLazyCompileCallback(
+ LLVMOrcJITStackRef JITStack, LLVMOrcTargetAddress *RetAddr,
+ LLVMOrcLazyCompileCallbackFn Callback, void *CallbackCtx);
/**
* Create a named indirect call stub.
*/
-LLVMOrcErrorCode LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack,
- const char *StubName,
- LLVMOrcTargetAddress InitAddr);
+LLVMErrorRef LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack,
+ const char *StubName,
+ LLVMOrcTargetAddress InitAddr);
/**
* Set the pointer for the given indirect stub.
*/
-LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
- const char *StubName,
- LLVMOrcTargetAddress NewAddr);
+LLVMErrorRef LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
+ const char *StubName,
+ LLVMOrcTargetAddress NewAddr);
/**
* Add module to be eagerly compiled.
*/
-LLVMOrcErrorCode
-LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
- LLVMOrcModuleHandle *RetHandle, LLVMModuleRef Mod,
- LLVMOrcSymbolResolverFn SymbolResolver,
- void *SymbolResolverCtx);
+LLVMErrorRef LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
+ LLVMOrcModuleHandle *RetHandle,
+ LLVMModuleRef Mod,
+ LLVMOrcSymbolResolverFn SymbolResolver,
+ void *SymbolResolverCtx);
/**
* Add module to be lazily compiled one function at a time.
*/
-LLVMOrcErrorCode
-LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
- LLVMOrcModuleHandle *RetHandle, LLVMModuleRef Mod,
- LLVMOrcSymbolResolverFn SymbolResolver,
- void *SymbolResolverCtx);
+LLVMErrorRef LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
+ LLVMOrcModuleHandle *RetHandle,
+ LLVMModuleRef Mod,
+ LLVMOrcSymbolResolverFn SymbolResolver,
+ void *SymbolResolverCtx);
/**
* Add an object file.
@@ -118,11 +115,11 @@ LLVMOrcAddLazilyCompiledIR(LLVMOrcJITSta
* Clients should *not* dispose of the 'Obj' argument: the JIT will manage it
* from this call onwards.
*/
-LLVMOrcErrorCode LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
- LLVMOrcModuleHandle *RetHandle,
- LLVMMemoryBufferRef Obj,
- LLVMOrcSymbolResolverFn SymbolResolver,
- void *SymbolResolverCtx);
+LLVMErrorRef LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
+ LLVMOrcModuleHandle *RetHandle,
+ LLVMMemoryBufferRef Obj,
+ LLVMOrcSymbolResolverFn SymbolResolver,
+ void *SymbolResolverCtx);
/**
* Remove a module set from the JIT.
@@ -130,29 +127,29 @@ LLVMOrcErrorCode LLVMOrcAddObjectFile(LL
* This works for all modules that can be added via OrcAdd*, including object
* files.
*/
-LLVMOrcErrorCode LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack,
- LLVMOrcModuleHandle H);
+LLVMErrorRef LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack,
+ LLVMOrcModuleHandle H);
/**
* Get symbol address from JIT instance.
*/
-LLVMOrcErrorCode LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
- LLVMOrcTargetAddress *RetAddr,
- const char *SymbolName);
+LLVMErrorRef LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
+ LLVMOrcTargetAddress *RetAddr,
+ const char *SymbolName);
/**
* Get symbol address from JIT instance, searching only the specified
* handle.
*/
-LLVMOrcErrorCode LLVMOrcGetSymbolAddressIn(LLVMOrcJITStackRef JITStack,
- LLVMOrcTargetAddress *RetAddr,
- LLVMOrcModuleHandle H,
- const char *SymbolName);
+LLVMErrorRef LLVMOrcGetSymbolAddressIn(LLVMOrcJITStackRef JITStack,
+ LLVMOrcTargetAddress *RetAddr,
+ LLVMOrcModuleHandle H,
+ const char *SymbolName);
/**
* Dispose of an ORC JIT stack.
*/
-LLVMOrcErrorCode LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack);
+LLVMErrorRef LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack);
/**
* Register a JIT Event Listener.
Modified: llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindings.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindings.cpp?rev=342828&r1=342827&r2=342828&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindings.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindings.cpp Sat Sep 22 19:09:18 2018
@@ -42,89 +42,110 @@ void LLVMOrcGetMangledSymbol(LLVMOrcJITS
void LLVMOrcDisposeMangledSymbol(char *MangledName) { delete[] MangledName; }
-LLVMOrcErrorCode
-LLVMOrcCreateLazyCompileCallback(LLVMOrcJITStackRef JITStack,
- LLVMOrcTargetAddress *RetAddr,
- LLVMOrcLazyCompileCallbackFn Callback,
- void *CallbackCtx) {
+LLVMErrorRef LLVMOrcCreateLazyCompileCallback(
+ LLVMOrcJITStackRef JITStack, LLVMOrcTargetAddress *RetAddr,
+ LLVMOrcLazyCompileCallbackFn Callback, void *CallbackCtx) {
OrcCBindingsStack &J = *unwrap(JITStack);
- return J.createLazyCompileCallback(*RetAddr, Callback, CallbackCtx);
+ if (auto Addr = J.createLazyCompileCallback(Callback, CallbackCtx)) {
+ *RetAddr = *Addr;
+ return LLVMErrorSuccess;
+ } else
+ return wrap(Addr.takeError());
}
-LLVMOrcErrorCode LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack,
- const char *StubName,
- LLVMOrcTargetAddress InitAddr) {
+LLVMErrorRef LLVMOrcCreateIndirectStub(LLVMOrcJITStackRef JITStack,
+ const char *StubName,
+ LLVMOrcTargetAddress InitAddr) {
OrcCBindingsStack &J = *unwrap(JITStack);
- return J.createIndirectStub(StubName, InitAddr);
+ return wrap(J.createIndirectStub(StubName, InitAddr));
}
-LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
- const char *StubName,
- LLVMOrcTargetAddress NewAddr) {
+LLVMErrorRef LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
+ const char *StubName,
+ LLVMOrcTargetAddress NewAddr) {
OrcCBindingsStack &J = *unwrap(JITStack);
- return J.setIndirectStubPointer(StubName, NewAddr);
+ return wrap(J.setIndirectStubPointer(StubName, NewAddr));
}
-LLVMOrcErrorCode
-LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
- LLVMOrcModuleHandle *RetHandle, LLVMModuleRef Mod,
- LLVMOrcSymbolResolverFn SymbolResolver,
- void *SymbolResolverCtx) {
+LLVMErrorRef LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
+ LLVMOrcModuleHandle *RetHandle,
+ LLVMModuleRef Mod,
+ LLVMOrcSymbolResolverFn SymbolResolver,
+ void *SymbolResolverCtx) {
OrcCBindingsStack &J = *unwrap(JITStack);
std::unique_ptr<Module> M(unwrap(Mod));
- return J.addIRModuleEager(*RetHandle, std::move(M), SymbolResolver,
- SymbolResolverCtx);
+ if (auto Handle =
+ J.addIRModuleEager(std::move(M), SymbolResolver, SymbolResolverCtx)) {
+ *RetHandle = *Handle;
+ return LLVMErrorSuccess;
+ } else
+ return wrap(Handle.takeError());
}
-LLVMOrcErrorCode
-LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
- LLVMOrcModuleHandle *RetHandle, LLVMModuleRef Mod,
- LLVMOrcSymbolResolverFn SymbolResolver,
- void *SymbolResolverCtx) {
+LLVMErrorRef LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
+ LLVMOrcModuleHandle *RetHandle,
+ LLVMModuleRef Mod,
+ LLVMOrcSymbolResolverFn SymbolResolver,
+ void *SymbolResolverCtx) {
OrcCBindingsStack &J = *unwrap(JITStack);
std::unique_ptr<Module> M(unwrap(Mod));
- return J.addIRModuleLazy(*RetHandle, std::move(M), SymbolResolver,
- SymbolResolverCtx);
+ if (auto Handle =
+ J.addIRModuleLazy(std::move(M), SymbolResolver, SymbolResolverCtx)) {
+ *RetHandle = *Handle;
+ return LLVMErrorSuccess;
+ } else
+ return wrap(Handle.takeError());
}
-LLVMOrcErrorCode
-LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
- LLVMOrcModuleHandle *RetHandle,
- LLVMMemoryBufferRef Obj,
- LLVMOrcSymbolResolverFn SymbolResolver,
- void *SymbolResolverCtx) {
+LLVMErrorRef LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
+ LLVMOrcModuleHandle *RetHandle,
+ LLVMMemoryBufferRef Obj,
+ LLVMOrcSymbolResolverFn SymbolResolver,
+ void *SymbolResolverCtx) {
OrcCBindingsStack &J = *unwrap(JITStack);
std::unique_ptr<MemoryBuffer> O(unwrap(Obj));
- return J.addObject(*RetHandle, std::move(O), SymbolResolver,
- SymbolResolverCtx);
+ if (auto Handle =
+ J.addObject(std::move(O), SymbolResolver, SymbolResolverCtx)) {
+ *RetHandle = *Handle;
+ return LLVMErrorSuccess;
+ } else
+ return wrap(Handle.takeError());
}
-LLVMOrcErrorCode LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack,
- LLVMOrcModuleHandle H) {
+LLVMErrorRef LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack,
+ LLVMOrcModuleHandle H) {
OrcCBindingsStack &J = *unwrap(JITStack);
- return J.removeModule(H);
+ return wrap(J.removeModule(H));
}
-LLVMOrcErrorCode LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
- LLVMOrcTargetAddress *RetAddr,
- const char *SymbolName) {
+LLVMErrorRef LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
+ LLVMOrcTargetAddress *RetAddr,
+ const char *SymbolName) {
OrcCBindingsStack &J = *unwrap(JITStack);
- return J.findSymbolAddress(*RetAddr, SymbolName, true);
+ if (auto Addr = J.findSymbolAddress(SymbolName, true)) {
+ *RetAddr = *Addr;
+ return LLVMErrorSuccess;
+ } else
+ return wrap(Addr.takeError());
}
-LLVMOrcErrorCode LLVMOrcGetSymbolAddressIn(LLVMOrcJITStackRef JITStack,
- LLVMOrcTargetAddress *RetAddr,
- LLVMOrcModuleHandle H,
- const char *SymbolName) {
+LLVMErrorRef LLVMOrcGetSymbolAddressIn(LLVMOrcJITStackRef JITStack,
+ LLVMOrcTargetAddress *RetAddr,
+ LLVMOrcModuleHandle H,
+ const char *SymbolName) {
OrcCBindingsStack &J = *unwrap(JITStack);
- return J.findSymbolAddressIn(*RetAddr, H, SymbolName, true);
+ if (auto Addr = J.findSymbolAddressIn(H, SymbolName, true)) {
+ *RetAddr = *Addr;
+ return LLVMErrorSuccess;
+ } else
+ return wrap(Addr.takeError());
}
-LLVMOrcErrorCode LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack) {
+LLVMErrorRef LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack) {
auto *J = unwrap(JITStack);
auto Err = J->shutdown();
delete J;
- return Err;
+ return wrap(std::move(Err));
}
void LLVMOrcRegisterJITEventListener(LLVMOrcJITStackRef JITStack, LLVMJITEventListenerRef L)
Modified: llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h?rev=342828&r1=342827&r2=342828&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h Sat Sep 22 19:09:18 2018
@@ -244,14 +244,14 @@ public:
CXXRuntimeOverrides(
[this](const std::string &S) { return mangle(S); }) {}
- LLVMOrcErrorCode shutdown() {
+ Error shutdown() {
// Run any destructors registered with __cxa_atexit.
CXXRuntimeOverrides.runDestructors();
// Run any IR destructors.
for (auto &DtorRunner : IRStaticDestructorRunners)
if (auto Err = DtorRunner.runViaLayer(*this))
- return mapError(std::move(Err));
- return LLVMOrcErrSuccess;
+ return Err;
+ return Error::success();
}
std::string mangle(StringRef Name) {
@@ -268,35 +268,27 @@ public:
return reinterpret_cast<PtrTy>(static_cast<uintptr_t>(Addr));
}
-
- LLVMOrcErrorCode
- createLazyCompileCallback(JITTargetAddress &RetAddr,
- LLVMOrcLazyCompileCallbackFn Callback,
+ Expected<JITTargetAddress>
+ createLazyCompileCallback(LLVMOrcLazyCompileCallbackFn Callback,
void *CallbackCtx) {
auto WrappedCallback = [=]() -> JITTargetAddress {
return Callback(wrap(this), CallbackCtx);
};
- if (auto CCAddr = CCMgr->getCompileCallback(std::move(WrappedCallback))) {
- RetAddr = *CCAddr;
- return LLVMOrcErrSuccess;
- } else
- return mapError(CCAddr.takeError());
+ return CCMgr->getCompileCallback(std::move(WrappedCallback));
}
- LLVMOrcErrorCode createIndirectStub(StringRef StubName,
- JITTargetAddress Addr) {
- return mapError(
- IndirectStubsMgr->createStub(StubName, Addr, JITSymbolFlags::Exported));
+ Error createIndirectStub(StringRef StubName, JITTargetAddress Addr) {
+ return IndirectStubsMgr->createStub(StubName, Addr,
+ JITSymbolFlags::Exported);
}
- LLVMOrcErrorCode setIndirectStubPointer(StringRef Name,
- JITTargetAddress Addr) {
- return mapError(IndirectStubsMgr->updatePointer(Name, Addr));
+ Error setIndirectStubPointer(StringRef Name, JITTargetAddress Addr) {
+ return IndirectStubsMgr->updatePointer(Name, Addr);
}
template <typename LayerT>
- LLVMOrcErrorCode
- addIRModule(orc::VModuleKey &RetKey, LayerT &Layer, std::unique_ptr<Module> M,
+ Expected<orc::VModuleKey>
+ addIRModule(LayerT &Layer, std::unique_ptr<Module> M,
std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr,
LLVMOrcSymbolResolverFn ExternalResolver,
void *ExternalResolverCtx) {
@@ -314,72 +306,70 @@ public:
DtorNames.push_back(mangle(Dtor.Func->getName()));
// Add the module to the JIT.
- RetKey = ES.allocateVModule();
- Resolvers[RetKey] = std::make_shared<CBindingsResolver>(
- *this, ExternalResolver, ExternalResolverCtx);
- if (auto Err = Layer.addModule(RetKey, std::move(M)))
- return mapError(std::move(Err));
+ auto K = ES.allocateVModule();
+ Resolvers[K] = std::make_shared<CBindingsResolver>(*this, ExternalResolver,
+ ExternalResolverCtx);
+ if (auto Err = Layer.addModule(K, std::move(M)))
+ return std::move(Err);
- KeyLayers[RetKey] = detail::createGenericLayer(Layer);
+ KeyLayers[K] = detail::createGenericLayer(Layer);
// Run the static constructors, and save the static destructor runner for
// execution when the JIT is torn down.
- orc::CtorDtorRunner<OrcCBindingsStack> CtorRunner(std::move(CtorNames),
- RetKey);
+ orc::CtorDtorRunner<OrcCBindingsStack> CtorRunner(std::move(CtorNames), K);
if (auto Err = CtorRunner.runViaLayer(*this))
- return mapError(std::move(Err));
+ return std::move(Err);
- IRStaticDestructorRunners.emplace_back(std::move(DtorNames), RetKey);
+ IRStaticDestructorRunners.emplace_back(std::move(DtorNames), K);
- return LLVMOrcErrSuccess;
+ return K;
}
- LLVMOrcErrorCode addIRModuleEager(orc::VModuleKey &RetKey,
- std::unique_ptr<Module> M,
- LLVMOrcSymbolResolverFn ExternalResolver,
- void *ExternalResolverCtx) {
- return addIRModule(RetKey, CompileLayer, std::move(M),
+ Expected<orc::VModuleKey>
+ addIRModuleEager(std::unique_ptr<Module> M,
+ LLVMOrcSymbolResolverFn ExternalResolver,
+ void *ExternalResolverCtx) {
+ return addIRModule(CompileLayer, std::move(M),
llvm::make_unique<SectionMemoryManager>(),
std::move(ExternalResolver), ExternalResolverCtx);
}
- LLVMOrcErrorCode addIRModuleLazy(orc::VModuleKey &RetKey,
- std::unique_ptr<Module> M,
- LLVMOrcSymbolResolverFn ExternalResolver,
- void *ExternalResolverCtx) {
- return addIRModule(RetKey, CODLayer, std::move(M),
+ Expected<orc::VModuleKey>
+ addIRModuleLazy(std::unique_ptr<Module> M,
+ LLVMOrcSymbolResolverFn ExternalResolver,
+ void *ExternalResolverCtx) {
+ return addIRModule(CODLayer, std::move(M),
llvm::make_unique<SectionMemoryManager>(),
std::move(ExternalResolver), ExternalResolverCtx);
}
- LLVMOrcErrorCode removeModule(orc::VModuleKey K) {
+ Error removeModule(orc::VModuleKey K) {
// FIXME: Should error release the module key?
if (auto Err = KeyLayers[K]->removeModule(K))
- return mapError(std::move(Err));
+ return Err;
ES.releaseVModule(K);
KeyLayers.erase(K);
- return LLVMOrcErrSuccess;
+ return Error::success();
}
- LLVMOrcErrorCode addObject(orc::VModuleKey &RetKey,
- std::unique_ptr<MemoryBuffer> ObjBuffer,
- LLVMOrcSymbolResolverFn ExternalResolver,
- void *ExternalResolverCtx) {
+ Expected<orc::VModuleKey> addObject(std::unique_ptr<MemoryBuffer> ObjBuffer,
+ LLVMOrcSymbolResolverFn ExternalResolver,
+ void *ExternalResolverCtx) {
if (auto Obj = object::ObjectFile::createObjectFile(
ObjBuffer->getMemBufferRef())) {
- RetKey = ES.allocateVModule();
- Resolvers[RetKey] = std::make_shared<CBindingsResolver>(
+ auto K = ES.allocateVModule();
+ Resolvers[K] = std::make_shared<CBindingsResolver>(
*this, ExternalResolver, ExternalResolverCtx);
- if (auto Err = ObjectLayer.addObject(RetKey, std::move(ObjBuffer)))
- return mapError(std::move(Err));
+ if (auto Err = ObjectLayer.addObject(K, std::move(ObjBuffer)))
+ return std::move(Err);
- KeyLayers[RetKey] = detail::createGenericLayer(ObjectLayer);
+ KeyLayers[K] = detail::createGenericLayer(ObjectLayer);
- return LLVMOrcErrSuccess;
+ return K;
} else
- return mapError(Obj.takeError());
+ return Obj.takeError();
}
JITSymbol findSymbol(const std::string &Name,
@@ -395,45 +385,39 @@ public:
return KeyLayers[K]->findSymbolIn(K, mangle(Name), ExportedSymbolsOnly);
}
- LLVMOrcErrorCode findSymbolAddress(JITTargetAddress &RetAddr,
- const std::string &Name,
- bool ExportedSymbolsOnly) {
- RetAddr = 0;
+ Expected<JITTargetAddress> findSymbolAddress(const std::string &Name,
+ bool ExportedSymbolsOnly) {
if (auto Sym = findSymbol(Name, ExportedSymbolsOnly)) {
// Successful lookup, non-null symbol:
- if (auto AddrOrErr = Sym.getAddress()) {
- RetAddr = *AddrOrErr;
- return LLVMOrcErrSuccess;
- } else
- return mapError(AddrOrErr.takeError());
+ if (auto AddrOrErr = Sym.getAddress())
+ return *AddrOrErr;
+ else
+ return AddrOrErr.takeError();
} else if (auto Err = Sym.takeError()) {
// Lookup failure - report error.
- return mapError(std::move(Err));
+ return std::move(Err);
}
- // Otherwise we had a successful lookup but got a null result. We already
- // set RetAddr to '0' above, so just return success.
- return LLVMOrcErrSuccess;
+
+ // No symbol not found. Return 0.
+ return 0;
}
- LLVMOrcErrorCode findSymbolAddressIn(JITTargetAddress &RetAddr,
- orc::VModuleKey K,
- const std::string &Name,
- bool ExportedSymbolsOnly) {
- RetAddr = 0;
+ Expected<JITTargetAddress> findSymbolAddressIn(orc::VModuleKey K,
+ const std::string &Name,
+ bool ExportedSymbolsOnly) {
if (auto Sym = findSymbolIn(K, Name, ExportedSymbolsOnly)) {
// Successful lookup, non-null symbol:
- if (auto AddrOrErr = Sym.getAddress()) {
- RetAddr = *AddrOrErr;
- return LLVMOrcErrSuccess;
- } else
- return mapError(AddrOrErr.takeError());
+ if (auto AddrOrErr = Sym.getAddress())
+ return *AddrOrErr;
+ else
+ return AddrOrErr.takeError();
} else if (auto Err = Sym.takeError()) {
// Lookup failure - report error.
- return mapError(std::move(Err));
+ return std::move(Err);
}
- // Otherwise we had a successful lookup but got a null result. We already
- // set RetAddr to '0' above, so just return success.
- return LLVMOrcErrSuccess;
+
+ // Symbol not found. Return 0.
+ return 0;
}
const std::string &getErrorMessage() const { return ErrMsg; }
@@ -457,18 +441,6 @@ public:
private:
- LLVMOrcErrorCode mapError(Error Err) {
- LLVMOrcErrorCode Result = LLVMOrcErrSuccess;
- handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) {
- // Handler of last resort.
- Result = LLVMOrcErrGeneric;
- ErrMsg = "";
- raw_string_ostream ErrStream(ErrMsg);
- EIB.log(ErrStream);
- });
- return Result;
- }
-
void reportError(Error Err) {
// FIXME: Report errors on the execution session.
logAllUnhandledErrors(std::move(Err), errs(), "ORC error: ");
More information about the llvm-commits
mailing list