diff options
author | Lang Hames <lhames@gmail.com> | 2016-04-25 19:56:45 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-04-25 19:56:45 +0000 |
commit | ef5a0ee2c3dad1c0e2fc51cf260a76d2acadf063 (patch) | |
tree | b64ecf2ee46a302e33d6348b66917baf1bec1f2d /llvm/tools/lli | |
parent | 074ea2851c4a4c5afeba2390d905eca062d66096 (diff) | |
download | bcm5719-llvm-ef5a0ee2c3dad1c0e2fc51cf260a76d2acadf063.tar.gz bcm5719-llvm-ef5a0ee2c3dad1c0e2fc51cf260a76d2acadf063.zip |
[ORC] Thread Error/Expected through the RPC library.
This replaces use of std::error_code and ErrorOr in the ORC RPC support library
with Error and Expected. This required updating the OrcRemoteTarget API, Client,
and server code, as well as updating the Orc C API.
This patch also fixes several instances where Errors were dropped.
llvm-svn: 267457
Diffstat (limited to 'llvm/tools/lli')
-rw-r--r-- | llvm/tools/lli/ChildTarget/ChildTarget.cpp | 17 | ||||
-rw-r--r-- | llvm/tools/lli/RemoteJITUtils.h | 42 | ||||
-rw-r--r-- | llvm/tools/lli/lli.cpp | 33 |
3 files changed, 51 insertions, 41 deletions
diff --git a/llvm/tools/lli/ChildTarget/ChildTarget.cpp b/llvm/tools/lli/ChildTarget/ChildTarget.cpp index b7dcaaa3ea9..1a6cd4211d0 100644 --- a/llvm/tools/lli/ChildTarget/ChildTarget.cpp +++ b/llvm/tools/lli/ChildTarget/ChildTarget.cpp @@ -17,6 +17,8 @@ typedef OrcX86_64 HostOrcArch; typedef OrcGenericArchitecture HostOrcArch; #endif +ExitOnError ExitOnErr; + int main(int argc, char *argv[]) { if (argc != 3) { @@ -24,6 +26,8 @@ int main(int argc, char *argv[]) { return 1; } + ExitOnErr.setBanner(std::string(argv[0]) + ":"); + int InFD; int OutFD; { @@ -55,20 +59,15 @@ int main(int argc, char *argv[]) { while (1) { uint32_t RawId; - if (auto EC = Server.startReceivingFunction(Channel, RawId)) { - errs() << "Error: " << EC.message() << "\n"; - return 1; - } + ExitOnErr(Server.startReceivingFunction(Channel, RawId)); auto Id = static_cast<JITServer::JITFuncId>(RawId); switch (Id) { case JITServer::TerminateSessionId: - Server.handleTerminateSession(); + ExitOnErr(Server.handleTerminateSession()); return 0; default: - if (auto EC = Server.handleKnownFunction(Id)) { - errs() << "Error: " << EC.message() << "\n"; - return 1; - } + ExitOnErr(Server.handleKnownFunction(Id)); + break; } } diff --git a/llvm/tools/lli/RemoteJITUtils.h b/llvm/tools/lli/RemoteJITUtils.h index 63915d13dde..ea6a04e2176 100644 --- a/llvm/tools/lli/RemoteJITUtils.h +++ b/llvm/tools/lli/RemoteJITUtils.h @@ -29,23 +29,43 @@ class FDRPCChannel final : public llvm::orc::remote::RPCChannel { public: FDRPCChannel(int InFD, int OutFD) : InFD(InFD), OutFD(OutFD) {} - std::error_code readBytes(char *Dst, unsigned Size) override { + llvm::Error readBytes(char *Dst, unsigned Size) override { assert(Dst && "Attempt to read into null."); - ssize_t ReadResult = ::read(InFD, Dst, Size); - if (ReadResult != (ssize_t)Size) - return std::error_code(errno, std::generic_category()); - return std::error_code(); + ssize_t Completed = 0; + while (Completed < Size) { + ssize_t Read = ::read(InFD, Dst + Completed, Size - Completed); + if (Read <= 0) { + auto ErrNo = errno; + if (ErrNo == EAGAIN || ErrNo == EINTR) + continue; + else + return llvm::errorCodeToError( + std::error_code(errno, std::generic_category())); + } + Completed += Read; + } + return llvm::Error::success(); } - std::error_code appendBytes(const char *Src, unsigned Size) override { + llvm::Error appendBytes(const char *Src, unsigned Size) override { assert(Src && "Attempt to append from null."); - ssize_t WriteResult = ::write(OutFD, Src, Size); - if (WriteResult != (ssize_t)Size) - std::error_code(errno, std::generic_category()); - return std::error_code(); + ssize_t Completed = 0; + while (Completed < Size) { + ssize_t Written = ::write(OutFD, Src + Completed, Size - Completed); + if (Written < 0) { + auto ErrNo = errno; + if (ErrNo == EAGAIN || ErrNo == EINTR) + continue; + else + return llvm::errorCodeToError( + std::error_code(errno, std::generic_category())); + } + Completed += Written; + } + return llvm::Error::success(); } - std::error_code send() override { return std::error_code(); } + llvm::Error send() override { return llvm::Error::success(); } private: int InFD, OutFD; diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp index f2e210d28dd..1927355e834 100644 --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -235,6 +235,8 @@ namespace { clEnumValN(FloatABI::Hard, "hard", "Hard float ABI (uses FP registers)"), clEnumValEnd)); + + ExitOnError ExitOnErr; } //===----------------------------------------------------------------------===// @@ -373,6 +375,9 @@ int main(int argc, char **argv, char * const *envp) { atexit(llvm_shutdown); // Call llvm_shutdown() on exit. + if (argc > 1) + ExitOnErr.setBanner(std::string(argv[0]) + ": "); + // If we have a native target, initialize it to ensure it is linked in and // usable by the JIT. InitializeNativeTarget(); @@ -648,18 +653,11 @@ int main(int argc, char **argv, char * const *envp) { // Create a remote target client running over the channel. typedef orc::remote::OrcRemoteTargetClient<orc::remote::RPCChannel> MyRemote; - ErrorOr<MyRemote> R = MyRemote::Create(*C); - if (!R) { - errs() << "Could not create remote: " << R.getError().message() << "\n"; - exit(1); - } + MyRemote R = ExitOnErr(MyRemote::Create(*C)); // Create a remote memory manager. std::unique_ptr<MyRemote::RCMemoryManager> RemoteMM; - if (auto EC = R->createRemoteMemoryManager(RemoteMM)) { - errs() << "Could not create remote memory manager: " << EC.message() << "\n"; - exit(1); - } + ExitOnErr(R.createRemoteMemoryManager(RemoteMM)); // Forward MCJIT's memory manager calls to the remote memory manager. static_cast<ForwardingMemoryManager*>(RTDyldMM)->setMemMgr( @@ -669,13 +667,9 @@ int main(int argc, char **argv, char * const *envp) { static_cast<ForwardingMemoryManager*>(RTDyldMM)->setResolver( orc::createLambdaResolver( [&](const std::string &Name) { - if (auto AddrOrErr = R->getSymbolAddress(Name)) - return RuntimeDyld::SymbolInfo(*AddrOrErr, JITSymbolFlags::Exported); - else { - errs() << "Failure during symbol lookup: " - << AddrOrErr.getError().message() << "\n"; - exit(1); - } + if (auto Addr = ExitOnErr(R.getSymbolAddress(Name))) + return RuntimeDyld::SymbolInfo(Addr, JITSymbolFlags::Exported); + return RuntimeDyld::SymbolInfo(nullptr); }, [](const std::string &Name) { return nullptr; } )); @@ -687,10 +681,7 @@ int main(int argc, char **argv, char * const *envp) { EE->finalizeObject(); DEBUG(dbgs() << "Executing '" << EntryFn->getName() << "' at 0x" << format("%llx", Entry) << "\n"); - if (auto ResultOrErr = R->callIntVoid(Entry)) - Result = *ResultOrErr; - else - errs() << "ERROR: " << ResultOrErr.getError().message() << "\n"; + Result = ExitOnErr(R.callIntVoid(Entry)); // Like static constructors, the remote target MCJIT support doesn't handle // this yet. It could. FIXME. @@ -701,7 +692,7 @@ int main(int argc, char **argv, char * const *envp) { EE.reset(); // Signal the remote target that we're done JITing. - R->terminateSession(); + ExitOnErr(R.terminateSession()); } return Result; |