mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
Avoid using PathV1.h in Program.h.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183940 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#include "llvm/ADT/ArrayRef.h"
|
#include "llvm/ADT/ArrayRef.h"
|
||||||
#include "llvm/Support/Path.h"
|
#include "llvm/Support/Path.h"
|
||||||
#include "llvm/Support/PathV1.h"
|
|
||||||
#include "llvm/Support/system_error.h"
|
#include "llvm/Support/system_error.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@@ -48,21 +47,20 @@ namespace sys {
|
|||||||
/// -1 indicates failure to execute
|
/// -1 indicates failure to execute
|
||||||
/// -2 indicates a crash during execution or timeout
|
/// -2 indicates a crash during execution or timeout
|
||||||
int ExecuteAndWait(
|
int ExecuteAndWait(
|
||||||
const Path &path, ///< sys::Path object providing the path of the
|
StringRef Program, ///< Path of the program to be executed. It is
|
||||||
///< program to be executed. It is presumed this is the result of
|
/// presumed this is the result of the FindProgramByName method.
|
||||||
///< the FindProgramByName method.
|
|
||||||
const char **args, ///< A vector of strings that are passed to the
|
const char **args, ///< A vector of strings that are passed to the
|
||||||
///< program. The first element should be the name of the program.
|
///< program. The first element should be the name of the program.
|
||||||
///< The list *must* be terminated by a null char* entry.
|
///< The list *must* be terminated by a null char* entry.
|
||||||
const char **env = 0, ///< An optional vector of strings to use for
|
const char **env = 0, ///< An optional vector of strings to use for
|
||||||
///< the program's environment. If not provided, the current program's
|
///< the program's environment. If not provided, the current program's
|
||||||
///< environment will be used.
|
///< environment will be used.
|
||||||
const sys::Path **redirects = 0, ///< An optional array of pointers to
|
const StringRef **redirects = 0, ///< An optional array of pointers to
|
||||||
///< Paths. If the array is null, no redirection is done. The array
|
///< paths. If the array is null, no redirection is done. The array
|
||||||
///< should have a size of at least three. If the pointer in the array
|
///< should have a size of at least three. The inferior process's
|
||||||
///< are not null, then the inferior process's stdin(0), stdout(1),
|
///< stdin(0), stdout(1), and stderr(2) will be redirected to the
|
||||||
///< and stderr(2) will be redirected to the corresponding Paths.
|
///< corresponding paths.
|
||||||
///< When an empty Path is passed in, the corresponding file
|
///< When an empty path is passed in, the corresponding file
|
||||||
///< descriptor will be disconnected (ie, /dev/null'd) in a portable
|
///< descriptor will be disconnected (ie, /dev/null'd) in a portable
|
||||||
///< way.
|
///< way.
|
||||||
unsigned secondsToWait = 0, ///< If non-zero, this specifies the amount
|
unsigned secondsToWait = 0, ///< If non-zero, this specifies the amount
|
||||||
@@ -80,14 +78,9 @@ namespace sys {
|
|||||||
///< program.
|
///< program.
|
||||||
bool *ExecutionFailed = 0);
|
bool *ExecutionFailed = 0);
|
||||||
|
|
||||||
int ExecuteAndWait(StringRef path, const char **args, const char **env = 0,
|
|
||||||
const StringRef **redirects = 0,
|
|
||||||
unsigned secondsToWait = 0, unsigned memoryLimit = 0,
|
|
||||||
std::string *ErrMsg = 0, bool *ExecutionFailed = 0);
|
|
||||||
|
|
||||||
/// Similar to ExecuteAndWait, but return immediately.
|
/// Similar to ExecuteAndWait, but return immediately.
|
||||||
void ExecuteNoWait(const Path &path, const char **args, const char **env = 0,
|
void ExecuteNoWait(StringRef Program, const char **args, const char **env = 0,
|
||||||
const sys::Path **redirects = 0, unsigned memoryLimit = 0,
|
const StringRef **redirects = 0, unsigned memoryLimit = 0,
|
||||||
std::string *ErrMsg = 0);
|
std::string *ErrMsg = 0);
|
||||||
|
|
||||||
// Return true if the given arguments fit within system-specific
|
// Return true if the given arguments fit within system-specific
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
#include "llvm/Support/Path.h"
|
#include "llvm/Support/Path.h"
|
||||||
|
#include "llvm/Support/PathV1.h"
|
||||||
#include "llvm/Support/Program.h"
|
#include "llvm/Support/Program.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@@ -85,7 +86,7 @@ static bool LLVM_ATTRIBUTE_UNUSED
|
|||||||
ExecGraphViewer(StringRef ExecPath, std::vector<const char*> &args,
|
ExecGraphViewer(StringRef ExecPath, std::vector<const char*> &args,
|
||||||
StringRef Filename, bool wait, std::string &ErrMsg) {
|
StringRef Filename, bool wait, std::string &ErrMsg) {
|
||||||
if (wait) {
|
if (wait) {
|
||||||
if (sys::ExecuteAndWait(sys::Path(ExecPath), &args[0],0,0,0,0,&ErrMsg)) {
|
if (sys::ExecuteAndWait(ExecPath, &args[0],0,0,0,0,&ErrMsg)) {
|
||||||
errs() << "Error: " << ErrMsg << "\n";
|
errs() << "Error: " << ErrMsg << "\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -94,7 +95,7 @@ ExecGraphViewer(StringRef ExecPath, std::vector<const char*> &args,
|
|||||||
errs() << " done. \n";
|
errs() << " done. \n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sys::ExecuteNoWait(sys::Path(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";
|
errs() << "Remember to erase graph file: " << Filename.str() << "\n";
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Support/Program.h"
|
#include "llvm/Support/Program.h"
|
||||||
|
#include "llvm/Support/PathV1.h"
|
||||||
#include "llvm/Config/config.h"
|
#include "llvm/Config/config.h"
|
||||||
#include "llvm/Support/system_error.h"
|
#include "llvm/Support/system_error.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@@ -29,46 +30,50 @@ static bool Execute(void **Data, const Path &path, const char **args,
|
|||||||
static int Wait(void *&Data, const Path &path, unsigned secondsToWait,
|
static int Wait(void *&Data, const Path &path, unsigned secondsToWait,
|
||||||
std::string *ErrMsg);
|
std::string *ErrMsg);
|
||||||
|
|
||||||
int sys::ExecuteAndWait(StringRef path, const char **args, const char **env,
|
|
||||||
const StringRef **redirects, unsigned secondsToWait,
|
static bool Execute(void **Data, StringRef Program, const char **args,
|
||||||
unsigned memoryLimit, std::string *ErrMsg,
|
const char **env, const StringRef **Redirects,
|
||||||
bool *ExecutionFailed) {
|
unsigned memoryLimit, std::string *ErrMsg) {
|
||||||
Path P(path);
|
Path P(Program);
|
||||||
if (!redirects)
|
if (!Redirects)
|
||||||
return ExecuteAndWait(P, args, env, 0, secondsToWait, memoryLimit, ErrMsg,
|
return Execute(Data, P, args, env, 0, memoryLimit, ErrMsg);
|
||||||
ExecutionFailed);
|
|
||||||
Path IO[3];
|
Path IO[3];
|
||||||
const Path *IOP[3];
|
const Path *IOP[3];
|
||||||
for (int I = 0; I < 3; ++I) {
|
for (int I = 0; I < 3; ++I) {
|
||||||
if (redirects[I]) {
|
if (Redirects[I]) {
|
||||||
IO[I] = *redirects[I];
|
IO[I] = *Redirects[I];
|
||||||
IOP[I] = &IO[I];
|
IOP[I] = &IO[I];
|
||||||
} else {
|
} else {
|
||||||
IOP[I] = 0;
|
IOP[I] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ExecuteAndWait(P, args, env, IOP, secondsToWait, memoryLimit, ErrMsg,
|
return Execute(Data, P, args, env, IOP, memoryLimit, ErrMsg);
|
||||||
ExecutionFailed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int sys::ExecuteAndWait(const Path &path, const char **args, const char **envp,
|
static int Wait(void *&Data, StringRef Program, unsigned secondsToWait,
|
||||||
const Path **redirects, unsigned secondsToWait,
|
std::string *ErrMsg) {
|
||||||
|
Path P(Program);
|
||||||
|
return Wait(Data, P, secondsToWait, ErrMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp,
|
||||||
|
const StringRef **redirects, unsigned secondsToWait,
|
||||||
unsigned memoryLimit, std::string *ErrMsg,
|
unsigned memoryLimit, std::string *ErrMsg,
|
||||||
bool *ExecutionFailed) {
|
bool *ExecutionFailed) {
|
||||||
void *Data = 0;
|
void *Data = 0;
|
||||||
if (Execute(&Data, path, args, envp, redirects, memoryLimit, ErrMsg)) {
|
if (Execute(&Data, Program, args, envp, redirects, memoryLimit, ErrMsg)) {
|
||||||
if (ExecutionFailed) *ExecutionFailed = false;
|
if (ExecutionFailed) *ExecutionFailed = false;
|
||||||
return Wait(Data, path, secondsToWait, ErrMsg);
|
return Wait(Data, Program, secondsToWait, ErrMsg);
|
||||||
}
|
}
|
||||||
if (ExecutionFailed) *ExecutionFailed = true;
|
if (ExecutionFailed) *ExecutionFailed = true;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sys::ExecuteNoWait(const Path &path, const char **args, const char **envp,
|
void sys::ExecuteNoWait(StringRef Program, const char **args, const char **envp,
|
||||||
const Path **redirects, unsigned memoryLimit,
|
const StringRef **redirects, unsigned memoryLimit,
|
||||||
std::string *ErrMsg) {
|
std::string *ErrMsg) {
|
||||||
Execute(/*Data*/ 0, path, args, envp, redirects, memoryLimit, ErrMsg);
|
Execute(/*Data*/ 0, Program, args, envp, redirects, memoryLimit, ErrMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include the platform-specific parts of this class.
|
// Include the platform-specific parts of this class.
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Support/SystemUtils.h"
|
#include "llvm/Support/SystemUtils.h"
|
||||||
|
#include "llvm/Support/PathV1.h"
|
||||||
#include "llvm/Support/Process.h"
|
#include "llvm/Support/Process.h"
|
||||||
#include "llvm/Support/Program.h"
|
#include "llvm/Support/Program.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
@@ -200,12 +200,12 @@ bool BugDriver::runPasses(Module *Program,
|
|||||||
prog = tool;
|
prog = tool;
|
||||||
|
|
||||||
// Redirect stdout and stderr to nowhere if SilencePasses is given
|
// Redirect stdout and stderr to nowhere if SilencePasses is given
|
||||||
sys::Path Nowhere;
|
StringRef Nowhere;
|
||||||
const sys::Path *Redirects[3] = {0, &Nowhere, &Nowhere};
|
const StringRef *Redirects[3] = {0, &Nowhere, &Nowhere};
|
||||||
|
|
||||||
int result =
|
int result = sys::ExecuteAndWait(prog.str(), Args.data(), 0,
|
||||||
sys::ExecuteAndWait(prog, Args.data(), 0, (SilencePasses ? Redirects : 0),
|
(SilencePasses ? Redirects : 0), Timeout,
|
||||||
Timeout, MemoryLimit, &ErrMsg);
|
MemoryLimit, &ErrMsg);
|
||||||
|
|
||||||
// If we are supposed to delete the bitcode file or if the passes crashed,
|
// If we are supposed to delete the bitcode file or if the passes crashed,
|
||||||
// remove it now. This may fail if the file was never created, but that's ok.
|
// remove it now. This may fail if the file was never created, but that's ok.
|
||||||
|
@@ -61,11 +61,7 @@ static int RunProgramWithTimeout(StringRef ProgramPath,
|
|||||||
unsigned NumSeconds = 0,
|
unsigned NumSeconds = 0,
|
||||||
unsigned MemoryLimit = 0,
|
unsigned MemoryLimit = 0,
|
||||||
std::string *ErrMsg = 0) {
|
std::string *ErrMsg = 0) {
|
||||||
const sys::Path P[3] = { sys::Path(StdInFile), sys::Path(StdOutFile),
|
const StringRef *Redirects[3] = { &StdInFile, &StdOutFile, &StdErrFile };
|
||||||
sys::Path(StdErrFile) };
|
|
||||||
const sys::Path* redirects[3];
|
|
||||||
for (int I = 0; I < 3; ++I)
|
|
||||||
redirects[I] = &P[I];
|
|
||||||
|
|
||||||
#if 0 // For debug purposes
|
#if 0 // For debug purposes
|
||||||
{
|
{
|
||||||
@@ -76,7 +72,7 @@ static int RunProgramWithTimeout(StringRef ProgramPath,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return sys::ExecuteAndWait(sys::Path(ProgramPath), Args, 0, redirects,
|
return sys::ExecuteAndWait(ProgramPath, Args, 0, Redirects,
|
||||||
NumSeconds, MemoryLimit, ErrMsg);
|
NumSeconds, MemoryLimit, ErrMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,11 +89,7 @@ static int RunProgramRemotelyWithTimeout(StringRef RemoteClientPath,
|
|||||||
StringRef StdErrFile,
|
StringRef StdErrFile,
|
||||||
unsigned NumSeconds = 0,
|
unsigned NumSeconds = 0,
|
||||||
unsigned MemoryLimit = 0) {
|
unsigned MemoryLimit = 0) {
|
||||||
const sys::Path P[3] = { sys::Path(StdInFile), sys::Path(StdOutFile),
|
const StringRef *Redirects[3] = { &StdInFile, &StdOutFile, &StdErrFile };
|
||||||
sys::Path(StdErrFile) };
|
|
||||||
const sys::Path* redirects[3];
|
|
||||||
for (int I = 0; I < 3; ++I)
|
|
||||||
redirects[I] = &P[I];
|
|
||||||
|
|
||||||
#if 0 // For debug purposes
|
#if 0 // For debug purposes
|
||||||
{
|
{
|
||||||
@@ -109,8 +101,8 @@ static int RunProgramRemotelyWithTimeout(StringRef RemoteClientPath,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Run the program remotely with the remote client
|
// Run the program remotely with the remote client
|
||||||
int ReturnCode = sys::ExecuteAndWait(sys::Path(RemoteClientPath), Args, 0,
|
int ReturnCode = sys::ExecuteAndWait(RemoteClientPath, Args, 0,
|
||||||
redirects, NumSeconds, MemoryLimit);
|
Redirects, NumSeconds, MemoryLimit);
|
||||||
|
|
||||||
// Has the remote client fail?
|
// Has the remote client fail?
|
||||||
if (255 == ReturnCode) {
|
if (255 == ReturnCode) {
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include "llvm/Support/Errno.h"
|
#include "llvm/Support/Errno.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
#include "llvm/Support/Path.h"
|
#include "llvm/Support/Path.h"
|
||||||
|
#include "llvm/Support/PathV1.h"
|
||||||
#include "llvm/Support/Program.h"
|
#include "llvm/Support/Program.h"
|
||||||
#include "llvm/Support/ToolOutputFile.h"
|
#include "llvm/Support/ToolOutputFile.h"
|
||||||
#include "llvm/Support/system_error.h"
|
#include "llvm/Support/system_error.h"
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/Path.h"
|
#include "llvm/Support/Path.h"
|
||||||
|
#include "llvm/Support/PathV1.h"
|
||||||
#include "llvm/Support/Program.h"
|
#include "llvm/Support/Program.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
@@ -74,14 +75,14 @@ TEST(ProgramTest, CreateProcessTrailingSlash) {
|
|||||||
bool ExecutionFailed;
|
bool ExecutionFailed;
|
||||||
// Redirect stdout and stdin to NUL, but let stderr through.
|
// Redirect stdout and stdin to NUL, but let stderr through.
|
||||||
#ifdef LLVM_ON_WIN32
|
#ifdef LLVM_ON_WIN32
|
||||||
Path nul("NUL");
|
StringRef nul("NUL");
|
||||||
#else
|
#else
|
||||||
Path nul("/dev/null");
|
StringRef nul("/dev/null");
|
||||||
#endif
|
#endif
|
||||||
const Path *redirects[] = { &nul, &nul, 0 };
|
const StringRef *redirects[] = { &nul, &nul, 0 };
|
||||||
int rc =
|
int rc = ExecuteAndWait(my_exe.str(), argv, &envp[0], redirects,
|
||||||
ExecuteAndWait(my_exe, argv, &envp[0], redirects, /*secondsToWait=*/ 10,
|
/*secondsToWait=*/ 10, /*memoryLimit=*/ 0, &error,
|
||||||
/*memoryLimit=*/ 0, &error, &ExecutionFailed);
|
&ExecutionFailed);
|
||||||
EXPECT_FALSE(ExecutionFailed) << error;
|
EXPECT_FALSE(ExecutionFailed) << error;
|
||||||
EXPECT_EQ(0, rc);
|
EXPECT_EQ(0, rc);
|
||||||
}
|
}
|
||||||
|
@@ -16,8 +16,7 @@ int main(int argc, const char **argv) {
|
|||||||
std::string Program = sys::FindProgramByName(argv[1]);
|
std::string Program = sys::FindProgramByName(argv[1]);
|
||||||
|
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
int Result =
|
int Result = sys::ExecuteAndWait(Program, argv + 1, 0, 0, 0, 0, &ErrMsg);
|
||||||
sys::ExecuteAndWait(sys::Path(Program), argv + 1, 0, 0, 0, 0, &ErrMsg);
|
|
||||||
if (Result < 0) {
|
if (Result < 0) {
|
||||||
errs() << "Error: " << ErrMsg << "\n";
|
errs() << "Error: " << ErrMsg << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
Reference in New Issue
Block a user