mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
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:
parent
19b30d56b2
commit
a4b504abc9
@ -53,18 +53,19 @@ namespace {
|
||||
/// RunProgramWithTimeout - This function provides an alternate interface
|
||||
/// to the sys::Program::ExecuteAndWait interface.
|
||||
/// @see sys::Program::ExecuteAndWait
|
||||
static int RunProgramWithTimeout(const sys::Path &ProgramPath,
|
||||
static int RunProgramWithTimeout(StringRef ProgramPath,
|
||||
const char **Args,
|
||||
const sys::Path &StdInFile,
|
||||
const sys::Path &StdOutFile,
|
||||
const sys::Path &StdErrFile,
|
||||
StringRef StdInFile,
|
||||
StringRef StdOutFile,
|
||||
StringRef StdErrFile,
|
||||
unsigned NumSeconds = 0,
|
||||
unsigned MemoryLimit = 0,
|
||||
std::string *ErrMsg = 0) {
|
||||
const sys::Path P[3] = { sys::Path(StdInFile), sys::Path(StdOutFile),
|
||||
sys::Path(StdErrFile) };
|
||||
const sys::Path* redirects[3];
|
||||
redirects[0] = &StdInFile;
|
||||
redirects[1] = &StdOutFile;
|
||||
redirects[2] = &StdErrFile;
|
||||
for (int I = 0; I < 3; ++I)
|
||||
redirects[I] = &P[I];
|
||||
|
||||
#if 0 // For debug purposes
|
||||
{
|
||||
@ -75,8 +76,8 @@ static int RunProgramWithTimeout(const sys::Path &ProgramPath,
|
||||
}
|
||||
#endif
|
||||
|
||||
return sys::ExecuteAndWait(ProgramPath, Args, 0, redirects, NumSeconds,
|
||||
MemoryLimit, ErrMsg);
|
||||
return sys::ExecuteAndWait(sys::Path(ProgramPath), Args, 0, redirects,
|
||||
NumSeconds, MemoryLimit, ErrMsg);
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// code otherwise.
|
||||
/// @see sys::Program::ExecuteAndWait
|
||||
static int RunProgramRemotelyWithTimeout(const sys::Path &RemoteClientPath,
|
||||
static int RunProgramRemotelyWithTimeout(StringRef RemoteClientPath,
|
||||
const char **Args,
|
||||
const sys::Path &StdInFile,
|
||||
const sys::Path &StdOutFile,
|
||||
const sys::Path &StdErrFile,
|
||||
StringRef StdInFile,
|
||||
StringRef StdOutFile,
|
||||
StringRef StdErrFile,
|
||||
unsigned NumSeconds = 0,
|
||||
unsigned MemoryLimit = 0) {
|
||||
const sys::Path P[3] = { sys::Path(StdInFile), sys::Path(StdOutFile),
|
||||
sys::Path(StdErrFile) };
|
||||
const sys::Path* redirects[3];
|
||||
redirects[0] = &StdInFile;
|
||||
redirects[1] = &StdOutFile;
|
||||
redirects[2] = &StdErrFile;
|
||||
for (int I = 0; I < 3; ++I)
|
||||
redirects[I] = &P[I];
|
||||
|
||||
#if 0 // For debug purposes
|
||||
{
|
||||
@ -107,8 +109,8 @@ static int RunProgramRemotelyWithTimeout(const sys::Path &RemoteClientPath,
|
||||
#endif
|
||||
|
||||
// Run the program remotely with the remote client
|
||||
int ReturnCode = sys::ExecuteAndWait(RemoteClientPath, Args, 0, redirects,
|
||||
NumSeconds, MemoryLimit);
|
||||
int ReturnCode = sys::ExecuteAndWait(sys::Path(RemoteClientPath), Args, 0,
|
||||
redirects, NumSeconds, MemoryLimit);
|
||||
|
||||
// Has the remote client fail?
|
||||
if (255 == ReturnCode) {
|
||||
@ -119,7 +121,7 @@ static int RunProgramRemotelyWithTimeout(const sys::Path &RemoteClientPath,
|
||||
OS << "\n";
|
||||
|
||||
// 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) {
|
||||
std::copy(std::istreambuf_iterator<char>(ErrorFile),
|
||||
std::istreambuf_iterator<char>(),
|
||||
@ -133,7 +135,7 @@ static int RunProgramRemotelyWithTimeout(const sys::Path &RemoteClientPath,
|
||||
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 MemoryLimit = 0) {
|
||||
std::ostringstream OS;
|
||||
@ -149,8 +151,8 @@ static std::string ProcessFailure(sys::Path ProgPath, const char** Args,
|
||||
errs() << "Error making unique filename: " << ErrMsg << "\n";
|
||||
exit(1);
|
||||
}
|
||||
RunProgramWithTimeout(ProgPath, Args, sys::Path(""), ErrorFilename,
|
||||
ErrorFilename, Timeout, MemoryLimit);
|
||||
RunProgramWithTimeout(ProgPath, Args, "", ErrorFilename.str(),
|
||||
ErrorFilename.str(), Timeout, MemoryLimit);
|
||||
// FIXME: check return code ?
|
||||
|
||||
// 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() << "\n";
|
||||
);
|
||||
return RunProgramWithTimeout(sys::Path(LLIPath), &LLIArgs[0],
|
||||
sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
|
||||
return RunProgramWithTimeout(LLIPath, &LLIArgs[0],
|
||||
InputFile, OutputFile, OutputFile,
|
||||
Timeout, MemoryLimit, Error);
|
||||
}
|
||||
|
||||
@ -304,10 +306,10 @@ void CustomCompiler::compileProgram(const std::string &Bitcode,
|
||||
for (unsigned i = 0, e = CompilerArgs.size(); i != e; ++i)
|
||||
ProgramArgs.push_back(CompilerArgs[i].c_str());
|
||||
|
||||
if (RunProgramWithTimeout( sys::Path(CompilerCommand), &ProgramArgs[0],
|
||||
sys::Path(), sys::Path(), sys::Path(),
|
||||
if (RunProgramWithTimeout(CompilerCommand, &ProgramArgs[0],
|
||||
"", "", "",
|
||||
Timeout, MemoryLimit, Error))
|
||||
*Error = ProcessFailure(sys::Path(CompilerCommand), &ProgramArgs[0],
|
||||
*Error = ProcessFailure(CompilerCommand, &ProgramArgs[0],
|
||||
Timeout, MemoryLimit);
|
||||
}
|
||||
|
||||
@ -362,9 +364,9 @@ int CustomExecutor::ExecuteProgram(const std::string &Bitcode,
|
||||
ProgramArgs.push_back(Args[i].c_str());
|
||||
|
||||
return RunProgramWithTimeout(
|
||||
sys::Path(ExecutionCommand),
|
||||
&ProgramArgs[0], sys::Path(InputFile), sys::Path(OutputFile),
|
||||
sys::Path(OutputFile), Timeout, MemoryLimit, Error);
|
||||
ExecutionCommand,
|
||||
&ProgramArgs[0], InputFile, OutputFile,
|
||||
OutputFile, Timeout, MemoryLimit, Error);
|
||||
}
|
||||
|
||||
// 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() << "\n";
|
||||
);
|
||||
if (RunProgramWithTimeout(sys::Path(LLCPath), &LLCArgs[0],
|
||||
sys::Path(), sys::Path(), sys::Path(),
|
||||
if (RunProgramWithTimeout(LLCPath, &LLCArgs[0],
|
||||
"", "", "",
|
||||
Timeout, MemoryLimit))
|
||||
Error = ProcessFailure(sys::Path(LLCPath), &LLCArgs[0],
|
||||
Error = ProcessFailure(LLCPath, &LLCArgs[0],
|
||||
Timeout, MemoryLimit);
|
||||
return UseIntegratedAssembler ? GCC::ObjectFile : GCC::AsmFile;
|
||||
}
|
||||
@ -602,8 +604,8 @@ int JIT::ExecuteProgram(const std::string &Bitcode,
|
||||
errs() << "\n";
|
||||
);
|
||||
DEBUG(errs() << "\nSending output to " << OutputFile << "\n");
|
||||
return RunProgramWithTimeout(sys::Path(LLIPath), &JITArgs[0],
|
||||
sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
|
||||
return RunProgramWithTimeout(LLIPath, &JITArgs[0],
|
||||
InputFile, OutputFile, OutputFile,
|
||||
Timeout, MemoryLimit, Error);
|
||||
}
|
||||
|
||||
@ -711,9 +713,8 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
|
||||
errs() << " " << GCCArgs[i];
|
||||
errs() << "\n";
|
||||
);
|
||||
if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], sys::Path(), sys::Path(),
|
||||
sys::Path())) {
|
||||
*Error = ProcessFailure(GCCPath, &GCCArgs[0]);
|
||||
if (RunProgramWithTimeout(GCCPath.str(), &GCCArgs[0], "", "", "")) {
|
||||
*Error = ProcessFailure(GCCPath.str(), &GCCArgs[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -767,9 +768,9 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
|
||||
|
||||
if (RemoteClientPath.isEmpty()) {
|
||||
DEBUG(errs() << "<run locally>");
|
||||
int ExitCode = RunProgramWithTimeout(OutputBinary, &ProgramArgs[0],
|
||||
sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
|
||||
Timeout, MemoryLimit, Error);
|
||||
int ExitCode = RunProgramWithTimeout(OutputBinary.str(), &ProgramArgs[0],
|
||||
InputFile, OutputFile, OutputFile,
|
||||
Timeout, MemoryLimit, Error);
|
||||
// Treat a signal (usually SIGSEGV) or timeout as part of the program output
|
||||
// so that crash-causing miscompilation is handled seamlessly.
|
||||
if (ExitCode < -1) {
|
||||
@ -781,9 +782,9 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
|
||||
return ExitCode;
|
||||
} else {
|
||||
outs() << "<run remotely>"; outs().flush();
|
||||
return RunProgramRemotelyWithTimeout(sys::Path(RemoteClientPath),
|
||||
&ProgramArgs[0], sys::Path(InputFile), sys::Path(OutputFile),
|
||||
sys::Path(OutputFile), Timeout, MemoryLimit);
|
||||
return RunProgramRemotelyWithTimeout(RemoteClientPath.str(),
|
||||
&ProgramArgs[0], InputFile, OutputFile,
|
||||
OutputFile, Timeout, MemoryLimit);
|
||||
}
|
||||
}
|
||||
|
||||
@ -861,9 +862,8 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
|
||||
errs() << " " << GCCArgs[i];
|
||||
errs() << "\n";
|
||||
);
|
||||
if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], sys::Path(), sys::Path(),
|
||||
sys::Path())) {
|
||||
Error = ProcessFailure(GCCPath, &GCCArgs[0]);
|
||||
if (RunProgramWithTimeout(GCCPath.str(), &GCCArgs[0], "", "", "")) {
|
||||
Error = ProcessFailure(GCCPath.str(), &GCCArgs[0]);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user