Reduce sys::Path usage in bugpoint.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183908 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2013-06-13 15:47:11 +00:00
parent 19b30d56b2
commit a4b504abc9

View File

@@ -53,18 +53,19 @@ namespace {
/// RunProgramWithTimeout - This function provides an alternate interface /// RunProgramWithTimeout - This function provides an alternate interface
/// to the sys::Program::ExecuteAndWait interface. /// to the sys::Program::ExecuteAndWait interface.
/// @see sys::Program::ExecuteAndWait /// @see sys::Program::ExecuteAndWait
static int RunProgramWithTimeout(const sys::Path &ProgramPath, static int RunProgramWithTimeout(StringRef ProgramPath,
const char **Args, const char **Args,
const sys::Path &StdInFile, StringRef StdInFile,
const sys::Path &StdOutFile, StringRef StdOutFile,
const sys::Path &StdErrFile, StringRef StdErrFile,
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),
sys::Path(StdErrFile) };
const sys::Path* redirects[3]; const sys::Path* redirects[3];
redirects[0] = &StdInFile; for (int I = 0; I < 3; ++I)
redirects[1] = &StdOutFile; redirects[I] = &P[I];
redirects[2] = &StdErrFile;
#if 0 // For debug purposes #if 0 // For debug purposes
{ {
@@ -75,8 +76,8 @@ static int RunProgramWithTimeout(const sys::Path &ProgramPath,
} }
#endif #endif
return sys::ExecuteAndWait(ProgramPath, Args, 0, redirects, NumSeconds, return sys::ExecuteAndWait(sys::Path(ProgramPath), Args, 0, redirects,
MemoryLimit, ErrMsg); NumSeconds, MemoryLimit, ErrMsg);
} }
/// RunProgramRemotelyWithTimeout - This function runs the given program /// RunProgramRemotelyWithTimeout - This function runs the given program
@@ -85,17 +86,18 @@ static int RunProgramWithTimeout(const sys::Path &ProgramPath,
/// fails. Remote client is required to return 255 if it failed or program exit /// fails. Remote client is required to return 255 if it failed or program exit
/// code otherwise. /// code otherwise.
/// @see sys::Program::ExecuteAndWait /// @see sys::Program::ExecuteAndWait
static int RunProgramRemotelyWithTimeout(const sys::Path &RemoteClientPath, static int RunProgramRemotelyWithTimeout(StringRef RemoteClientPath,
const char **Args, const char **Args,
const sys::Path &StdInFile, StringRef StdInFile,
const sys::Path &StdOutFile, StringRef StdOutFile,
const sys::Path &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),
sys::Path(StdErrFile) };
const sys::Path* redirects[3]; const sys::Path* redirects[3];
redirects[0] = &StdInFile; for (int I = 0; I < 3; ++I)
redirects[1] = &StdOutFile; redirects[I] = &P[I];
redirects[2] = &StdErrFile;
#if 0 // For debug purposes #if 0 // For debug purposes
{ {
@@ -107,8 +109,8 @@ static int RunProgramRemotelyWithTimeout(const sys::Path &RemoteClientPath,
#endif #endif
// Run the program remotely with the remote client // Run the program remotely with the remote client
int ReturnCode = sys::ExecuteAndWait(RemoteClientPath, Args, 0, redirects, int ReturnCode = sys::ExecuteAndWait(sys::Path(RemoteClientPath), Args, 0,
NumSeconds, MemoryLimit); redirects, NumSeconds, MemoryLimit);
// Has the remote client fail? // Has the remote client fail?
if (255 == ReturnCode) { if (255 == ReturnCode) {
@@ -119,7 +121,7 @@ static int RunProgramRemotelyWithTimeout(const sys::Path &RemoteClientPath,
OS << "\n"; OS << "\n";
// The error message is in the output file, let's print it out from there. // The error message is in the output file, let's print it out from there.
std::ifstream ErrorFile(StdOutFile.c_str()); std::ifstream ErrorFile(StdOutFile);
if (ErrorFile) { if (ErrorFile) {
std::copy(std::istreambuf_iterator<char>(ErrorFile), std::copy(std::istreambuf_iterator<char>(ErrorFile),
std::istreambuf_iterator<char>(), std::istreambuf_iterator<char>(),
@@ -133,7 +135,7 @@ static int RunProgramRemotelyWithTimeout(const sys::Path &RemoteClientPath,
return ReturnCode; return ReturnCode;
} }
static std::string ProcessFailure(sys::Path ProgPath, const char** Args, static std::string ProcessFailure(StringRef ProgPath, const char** Args,
unsigned Timeout = 0, unsigned Timeout = 0,
unsigned MemoryLimit = 0) { unsigned MemoryLimit = 0) {
std::ostringstream OS; std::ostringstream OS;
@@ -149,8 +151,8 @@ static std::string ProcessFailure(sys::Path ProgPath, const char** Args,
errs() << "Error making unique filename: " << ErrMsg << "\n"; errs() << "Error making unique filename: " << ErrMsg << "\n";
exit(1); exit(1);
} }
RunProgramWithTimeout(ProgPath, Args, sys::Path(""), ErrorFilename, RunProgramWithTimeout(ProgPath, Args, "", ErrorFilename.str(),
ErrorFilename, Timeout, MemoryLimit); ErrorFilename.str(), Timeout, MemoryLimit);
// FIXME: check return code ? // FIXME: check return code ?
// Print out the error messages generated by GCC if possible... // Print out the error messages generated by GCC if possible...
@@ -228,8 +230,8 @@ int LLI::ExecuteProgram(const std::string &Bitcode,
errs() << " " << LLIArgs[i]; errs() << " " << LLIArgs[i];
errs() << "\n"; errs() << "\n";
); );
return RunProgramWithTimeout(sys::Path(LLIPath), &LLIArgs[0], return RunProgramWithTimeout(LLIPath, &LLIArgs[0],
sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile), InputFile, OutputFile, OutputFile,
Timeout, MemoryLimit, Error); Timeout, MemoryLimit, Error);
} }
@@ -304,10 +306,10 @@ void CustomCompiler::compileProgram(const std::string &Bitcode,
for (unsigned i = 0, e = CompilerArgs.size(); i != e; ++i) for (unsigned i = 0, e = CompilerArgs.size(); i != e; ++i)
ProgramArgs.push_back(CompilerArgs[i].c_str()); ProgramArgs.push_back(CompilerArgs[i].c_str());
if (RunProgramWithTimeout( sys::Path(CompilerCommand), &ProgramArgs[0], if (RunProgramWithTimeout(CompilerCommand, &ProgramArgs[0],
sys::Path(), sys::Path(), sys::Path(), "", "", "",
Timeout, MemoryLimit, Error)) Timeout, MemoryLimit, Error))
*Error = ProcessFailure(sys::Path(CompilerCommand), &ProgramArgs[0], *Error = ProcessFailure(CompilerCommand, &ProgramArgs[0],
Timeout, MemoryLimit); Timeout, MemoryLimit);
} }
@@ -362,9 +364,9 @@ int CustomExecutor::ExecuteProgram(const std::string &Bitcode,
ProgramArgs.push_back(Args[i].c_str()); ProgramArgs.push_back(Args[i].c_str());
return RunProgramWithTimeout( return RunProgramWithTimeout(
sys::Path(ExecutionCommand), ExecutionCommand,
&ProgramArgs[0], sys::Path(InputFile), sys::Path(OutputFile), &ProgramArgs[0], InputFile, OutputFile,
sys::Path(OutputFile), Timeout, MemoryLimit, Error); OutputFile, Timeout, MemoryLimit, Error);
} }
// Tokenize the CommandLine to the command and the args to allow // Tokenize the CommandLine to the command and the args to allow
@@ -476,10 +478,10 @@ GCC::FileType LLC::OutputCode(const std::string &Bitcode,
errs() << " " << LLCArgs[i]; errs() << " " << LLCArgs[i];
errs() << "\n"; errs() << "\n";
); );
if (RunProgramWithTimeout(sys::Path(LLCPath), &LLCArgs[0], if (RunProgramWithTimeout(LLCPath, &LLCArgs[0],
sys::Path(), sys::Path(), sys::Path(), "", "", "",
Timeout, MemoryLimit)) Timeout, MemoryLimit))
Error = ProcessFailure(sys::Path(LLCPath), &LLCArgs[0], Error = ProcessFailure(LLCPath, &LLCArgs[0],
Timeout, MemoryLimit); Timeout, MemoryLimit);
return UseIntegratedAssembler ? GCC::ObjectFile : GCC::AsmFile; return UseIntegratedAssembler ? GCC::ObjectFile : GCC::AsmFile;
} }
@@ -602,8 +604,8 @@ int JIT::ExecuteProgram(const std::string &Bitcode,
errs() << "\n"; errs() << "\n";
); );
DEBUG(errs() << "\nSending output to " << OutputFile << "\n"); DEBUG(errs() << "\nSending output to " << OutputFile << "\n");
return RunProgramWithTimeout(sys::Path(LLIPath), &JITArgs[0], return RunProgramWithTimeout(LLIPath, &JITArgs[0],
sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile), InputFile, OutputFile, OutputFile,
Timeout, MemoryLimit, Error); Timeout, MemoryLimit, Error);
} }
@@ -711,9 +713,8 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
errs() << " " << GCCArgs[i]; errs() << " " << GCCArgs[i];
errs() << "\n"; errs() << "\n";
); );
if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], sys::Path(), sys::Path(), if (RunProgramWithTimeout(GCCPath.str(), &GCCArgs[0], "", "", "")) {
sys::Path())) { *Error = ProcessFailure(GCCPath.str(), &GCCArgs[0]);
*Error = ProcessFailure(GCCPath, &GCCArgs[0]);
return -1; return -1;
} }
@@ -767,9 +768,9 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
if (RemoteClientPath.isEmpty()) { if (RemoteClientPath.isEmpty()) {
DEBUG(errs() << "<run locally>"); DEBUG(errs() << "<run locally>");
int ExitCode = RunProgramWithTimeout(OutputBinary, &ProgramArgs[0], int ExitCode = RunProgramWithTimeout(OutputBinary.str(), &ProgramArgs[0],
sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile), InputFile, OutputFile, OutputFile,
Timeout, MemoryLimit, Error); Timeout, MemoryLimit, Error);
// Treat a signal (usually SIGSEGV) or timeout as part of the program output // Treat a signal (usually SIGSEGV) or timeout as part of the program output
// so that crash-causing miscompilation is handled seamlessly. // so that crash-causing miscompilation is handled seamlessly.
if (ExitCode < -1) { if (ExitCode < -1) {
@@ -781,9 +782,9 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
return ExitCode; return ExitCode;
} else { } else {
outs() << "<run remotely>"; outs().flush(); outs() << "<run remotely>"; outs().flush();
return RunProgramRemotelyWithTimeout(sys::Path(RemoteClientPath), return RunProgramRemotelyWithTimeout(RemoteClientPath.str(),
&ProgramArgs[0], sys::Path(InputFile), sys::Path(OutputFile), &ProgramArgs[0], InputFile, OutputFile,
sys::Path(OutputFile), Timeout, MemoryLimit); OutputFile, Timeout, MemoryLimit);
} }
} }
@@ -861,9 +862,8 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
errs() << " " << GCCArgs[i]; errs() << " " << GCCArgs[i];
errs() << "\n"; errs() << "\n";
); );
if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], sys::Path(), sys::Path(), if (RunProgramWithTimeout(GCCPath.str(), &GCCArgs[0], "", "", "")) {
sys::Path())) { Error = ProcessFailure(GCCPath.str(), &GCCArgs[0]);
Error = ProcessFailure(GCCPath, &GCCArgs[0]);
return 1; return 1;
} }
return 0; return 0;