mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-05 13:26:55 +00:00
Remove the program class.
It was only used to implement ExecuteAndWait and ExecuteNoWait. Expose just those two functions and make Execute and Wait implementations details. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183864 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -66,7 +66,7 @@ public:
|
||||
error_code OpenFile(const std::string &Filename) {
|
||||
if (Filename == "-") {
|
||||
Fd = 0;
|
||||
sys::Program::ChangeStdinToBinary();
|
||||
sys::ChangeStdinToBinary();
|
||||
return error_code::success();
|
||||
}
|
||||
|
||||
|
@@ -69,7 +69,7 @@ static bool LLVM_ATTRIBUTE_UNUSED
|
||||
ExecGraphViewer(const sys::Path &ExecPath, std::vector<const char*> &args,
|
||||
const sys::Path &Filename, bool wait, std::string &ErrMsg) {
|
||||
if (wait) {
|
||||
if (sys::Program::ExecuteAndWait(ExecPath, &args[0],0,0,0,0,&ErrMsg)) {
|
||||
if (sys::ExecuteAndWait(ExecPath, &args[0],0,0,0,0,&ErrMsg)) {
|
||||
errs() << "Error: " << ErrMsg << "\n";
|
||||
return false;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ ExecGraphViewer(const sys::Path &ExecPath, std::vector<const char*> &args,
|
||||
errs() << " done. \n";
|
||||
}
|
||||
else {
|
||||
sys::Program::ExecuteNoWait(ExecPath, &args[0],0,0,0,&ErrMsg);
|
||||
sys::ExecuteNoWait(ExecPath, &args[0],0,0,0,&ErrMsg);
|
||||
errs() << "Remember to erase graph file: " << Filename.str() << "\n";
|
||||
}
|
||||
return true;
|
||||
|
@@ -419,7 +419,7 @@ error_code MemoryBuffer::getSTDIN(OwningPtr<MemoryBuffer> &result) {
|
||||
//
|
||||
// FIXME: That isn't necessarily true, we should try to mmap stdin and
|
||||
// fallback if it fails.
|
||||
sys::Program::ChangeStdinToBinary();
|
||||
sys::ChangeStdinToBinary();
|
||||
|
||||
return getMemoryBufferForStream(0, "<stdin>", result);
|
||||
}
|
||||
|
@@ -22,33 +22,31 @@ using namespace sys;
|
||||
//=== independent code.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int
|
||||
Program::ExecuteAndWait(const Path& path,
|
||||
const char** args,
|
||||
const char** envp,
|
||||
const Path** redirects,
|
||||
unsigned secondsToWait,
|
||||
unsigned memoryLimit,
|
||||
std::string* ErrMsg,
|
||||
static bool Execute(void *&Data, const Path &path, const char **args,
|
||||
const char **env, const sys::Path **redirects,
|
||||
unsigned memoryLimit, std::string *ErrMsg);
|
||||
|
||||
static int Wait(void *&Data, const Path &path, unsigned secondsToWait,
|
||||
std::string *ErrMsg);
|
||||
|
||||
int sys::ExecuteAndWait(const Path &path, const char **args, const char **envp,
|
||||
const Path **redirects, unsigned secondsToWait,
|
||||
unsigned memoryLimit, std::string *ErrMsg,
|
||||
bool *ExecutionFailed) {
|
||||
Program prg;
|
||||
if (prg.Execute(path, args, envp, redirects, memoryLimit, ErrMsg)) {
|
||||
void *Data;
|
||||
if (Execute(Data, path, args, envp, redirects, memoryLimit, ErrMsg)) {
|
||||
if (ExecutionFailed) *ExecutionFailed = false;
|
||||
return prg.Wait(path, secondsToWait, ErrMsg);
|
||||
return Wait(Data, path, secondsToWait, ErrMsg);
|
||||
}
|
||||
if (ExecutionFailed) *ExecutionFailed = true;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
Program::ExecuteNoWait(const Path& path,
|
||||
const char** args,
|
||||
const char** envp,
|
||||
const Path** redirects,
|
||||
unsigned memoryLimit,
|
||||
std::string* ErrMsg) {
|
||||
Program prg;
|
||||
prg.Execute(path, args, envp, redirects, memoryLimit, ErrMsg);
|
||||
void sys::ExecuteNoWait(const Path &path, const char **args, const char **envp,
|
||||
const Path **redirects, unsigned memoryLimit,
|
||||
std::string *ErrMsg) {
|
||||
void *Data;
|
||||
Execute(Data, path, args, envp, redirects, memoryLimit, ErrMsg);
|
||||
}
|
||||
|
||||
// Include the platform-specific parts of this class.
|
||||
|
@@ -47,13 +47,9 @@
|
||||
namespace llvm {
|
||||
using namespace sys;
|
||||
|
||||
Program::Program() : Data_(0) {}
|
||||
|
||||
Program::~Program() {}
|
||||
|
||||
// This function just uses the PATH environment variable to find the program.
|
||||
Path
|
||||
Program::FindProgramByName(const std::string& progName) {
|
||||
sys::FindProgramByName(const std::string& progName) {
|
||||
|
||||
// Check some degenerate cases
|
||||
if (progName.length() == 0) // no program
|
||||
@@ -180,10 +176,11 @@ static void SetMemoryLimits (unsigned size)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
Program::Execute(const Path &path, const char **args, const char **envp,
|
||||
const Path **redirects, unsigned memoryLimit,
|
||||
std::string *ErrMsg) {
|
||||
}
|
||||
|
||||
static bool Execute(void *&Data, const Path &path, const char **args,
|
||||
const char **envp, const Path **redirects,
|
||||
unsigned memoryLimit, std::string *ErrMsg) {
|
||||
// If this OS has posix_spawn and there is no memory limit being implied, use
|
||||
// posix_spawn. It is more efficient than fork/exec.
|
||||
#ifdef HAVE_POSIX_SPAWN
|
||||
@@ -231,7 +228,7 @@ Program::Execute(const Path &path, const char **args, const char **envp,
|
||||
if (Err)
|
||||
return !MakeErrMsg(ErrMsg, "posix_spawn failed", Err);
|
||||
|
||||
Data_ = reinterpret_cast<void*>(PID);
|
||||
Data = reinterpret_cast<void*>(PID);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -293,20 +290,17 @@ Program::Execute(const Path &path, const char **args, const char **envp,
|
||||
break;
|
||||
}
|
||||
|
||||
Data_ = reinterpret_cast<void*>(child);
|
||||
Data = reinterpret_cast<void*>(child);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
Program::Wait(const sys::Path &path,
|
||||
unsigned secondsToWait,
|
||||
std::string* ErrMsg)
|
||||
{
|
||||
static int Wait(void *&Data, const sys::Path &path, unsigned secondsToWait,
|
||||
std::string *ErrMsg) {
|
||||
#ifdef HAVE_SYS_WAIT_H
|
||||
struct sigaction Act, Old;
|
||||
|
||||
if (Data_ == 0) {
|
||||
if (Data == 0) {
|
||||
MakeErrMsg(ErrMsg, "Process not started!");
|
||||
return -1;
|
||||
}
|
||||
@@ -324,7 +318,7 @@ Program::Wait(const sys::Path &path,
|
||||
|
||||
// Parent process: Wait for the child process to terminate.
|
||||
int status;
|
||||
uint64_t pid = reinterpret_cast<uint64_t>(Data_);
|
||||
uint64_t pid = reinterpret_cast<uint64_t>(Data);
|
||||
pid_t child = static_cast<pid_t>(pid);
|
||||
while (waitpid(pid, &status, 0) != child)
|
||||
if (secondsToWait && errno == EINTR) {
|
||||
@@ -397,17 +391,19 @@ Program::Wait(const sys::Path &path,
|
||||
#endif
|
||||
}
|
||||
|
||||
error_code Program::ChangeStdinToBinary(){
|
||||
namespace llvm {
|
||||
|
||||
error_code sys::ChangeStdinToBinary(){
|
||||
// Do nothing, as Unix doesn't differentiate between text and binary.
|
||||
return make_error_code(errc::success);
|
||||
}
|
||||
|
||||
error_code Program::ChangeStdoutToBinary(){
|
||||
error_code sys::ChangeStdoutToBinary(){
|
||||
// Do nothing, as Unix doesn't differentiate between text and binary.
|
||||
return make_error_code(errc::success);
|
||||
}
|
||||
|
||||
error_code Program::ChangeStderrToBinary(){
|
||||
error_code sys::ChangeStderrToBinary(){
|
||||
// Do nothing, as Unix doesn't differentiate between text and binary.
|
||||
return make_error_code(errc::success);
|
||||
}
|
||||
|
@@ -442,7 +442,7 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
|
||||
// If user requested binary then put stdout into binary mode if
|
||||
// possible.
|
||||
if (Flags & F_Binary)
|
||||
sys::Program::ChangeStdoutToBinary();
|
||||
sys::ChangeStdoutToBinary();
|
||||
// Close stdout when we're done, to detect any output errors.
|
||||
ShouldClose = true;
|
||||
return;
|
||||
|
Reference in New Issue
Block a user