diff options
Diffstat (limited to 'contrib/llvm/tools/lli/Unix')
-rw-r--r-- | contrib/llvm/tools/lli/Unix/RPCChannel.inc (renamed from contrib/llvm/tools/lli/Unix/RemoteTargetExternal.inc) | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/contrib/llvm/tools/lli/Unix/RemoteTargetExternal.inc b/contrib/llvm/tools/lli/Unix/RPCChannel.inc index 9c1a4cc31553..6a9ae14b599f 100644 --- a/contrib/llvm/tools/lli/Unix/RemoteTargetExternal.inc +++ b/contrib/llvm/tools/lli/Unix/RPCChannel.inc @@ -1,4 +1,4 @@ -//=- RemoteTargetExternal.inc - LLVM out-of-process JIT execution for Unix --=// +//=- RPCChannel.inc - LLVM out-of-process JIT execution for Unix --=// // // The LLVM Compiler Infrastructure // @@ -7,15 +7,17 @@ // //===----------------------------------------------------------------------===// // -// Implementation of the Unix-specific parts of the RemoteTargetExternal class +// Implementation of the Unix-specific parts of the RPCChannel class // which executes JITed code in a separate process from where it was built. // //===----------------------------------------------------------------------===// -#include <unistd.h> +#include "llvm/Support/Errno.h" +#include "llvm/Support/raw_ostream.h" #include <stdio.h> #include <stdlib.h> #include <sys/wait.h> +#include <unistd.h> namespace { @@ -30,7 +32,7 @@ struct ConnectionData_t { namespace llvm { -void RemoteTargetExternal::create() { +bool RPCChannel::createServer() { int PipeFD[2][2]; pid_t ChildPID; @@ -58,12 +60,11 @@ void RemoteTargetExternal::create() { } // Execute the child process. - char *args[1] = { NULL }; + char *args[1] = { nullptr }; int rc = execv(ChildName.c_str(), args); if (rc != 0) perror("Error executing child process: "); - } - else { + } else { // In the parent... // Close the child ends of the pipes @@ -71,25 +72,50 @@ void RemoteTargetExternal::create() { close(PipeFD[1][1]); // Store the parent ends of the pipes - ConnectionData = (void*)new ConnectionData_t(PipeFD[1][0], PipeFD[0][1]); - - Receive(LLI_ChildActive); + ConnectionData = (void *)new ConnectionData_t(PipeFD[1][0], PipeFD[0][1]); + return true; } + return false; } -int RemoteTargetExternal::WriteBytes(const void *Data, size_t Size) { - return write(((ConnectionData_t*)ConnectionData)->OutputPipe, Data, Size); +bool RPCChannel::createClient() { + // Store the parent ends of the pipes + ConnectionData = (void *)new ConnectionData_t(STDIN_FILENO, STDOUT_FILENO); + return true; +} + +void RPCChannel::Wait() { wait(nullptr); } + +static bool CheckError(int rc, size_t Size, const char *Desc) { + if (rc < 0) { + llvm::errs() << "IO Error: " << Desc << ": " << sys::StrError() << '\n'; + return false; + } else if ((size_t)rc != Size) { + std::string ErrorMsg; + char Number[10] = { 0 }; + ErrorMsg += "Expecting "; + sprintf(Number, "%d", (uint32_t)Size); + ErrorMsg += Number; + ErrorMsg += " bytes, Got "; + sprintf(Number, "%d", rc); + ErrorMsg += Number; + llvm::errs() << "RPC Error: " << Desc << ": " << ErrorMsg << '\n'; + return false; + } + return true; } -int RemoteTargetExternal::ReadBytes(void *Data, size_t Size) { - return read(((ConnectionData_t*)ConnectionData)->InputPipe, Data, Size); +bool RPCChannel::WriteBytes(const void *Data, size_t Size) { + int rc = write(((ConnectionData_t *)ConnectionData)->OutputPipe, Data, Size); + return CheckError(rc, Size, "WriteBytes"); } -void RemoteTargetExternal::Wait() { - wait(NULL); +bool RPCChannel::ReadBytes(void *Data, size_t Size) { + int rc = read(((ConnectionData_t *)ConnectionData)->InputPipe, Data, Size); + return CheckError(rc, Size, "ReadBytes"); } -RemoteTargetExternal::~RemoteTargetExternal() { +RPCChannel::~RPCChannel() { delete static_cast<ConnectionData_t *>(ConnectionData); } |