For PR351:
Generally, remove use of fork/exec from bugpoint in favor of the portable
sys::Program::ExecuteAndWait method. This change requires two new options
to bugpoint to tell it that it is running in "child" mode. In this mode,
it reads its input and runs the passes. The result code signals to the
parent instance of bugpoint what happened (success, fail, crash).
This change should make bugpoint usable on Win32 systems.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24961 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/bugpoint/BugDriver.cpp b/tools/bugpoint/BugDriver.cpp
index 17e3374..bd558db 100644
--- a/tools/bugpoint/BugDriver.cpp
+++ b/tools/bugpoint/BugDriver.cpp
@@ -62,9 +62,9 @@
return Result;
}
-BugDriver::BugDriver(const char *toolname)
+BugDriver::BugDriver(const char *toolname, bool as_child)
: ToolName(toolname), ReferenceOutputFile(OutputFile),
- Program(0), Interpreter(0), cbe(0), gcc(0) {}
+ Program(0), Interpreter(0), cbe(0), gcc(0), run_as_child(as_child) {}
/// ParseInputFile - Given a bytecode or assembly input filename, parse and
@@ -97,13 +97,15 @@
// Load the first input file...
Program = ParseInputFile(Filenames[0]);
if (Program == 0) return true;
- std::cout << "Read input file : '" << Filenames[0] << "'\n";
+ if (!run_as_child)
+ std::cout << "Read input file : '" << Filenames[0] << "'\n";
for (unsigned i = 1, e = Filenames.size(); i != e; ++i) {
std::auto_ptr<Module> M(ParseInputFile(Filenames[i]));
if (M.get() == 0) return true;
- std::cout << "Linking in input file: '" << Filenames[i] << "'\n";
+ if (!run_as_child)
+ std::cout << "Linking in input file: '" << Filenames[i] << "'\n";
std::string ErrorMessage;
if (Linker::LinkModules(Program, M.get(), &ErrorMessage)) {
std::cerr << ToolName << ": error linking in '" << Filenames[i] << "': "
@@ -112,7 +114,8 @@
}
}
- std::cout << "*** All input ok\n";
+ if (!run_as_child)
+ std::cout << "*** All input ok\n";
// All input files read successfully!
return false;
@@ -124,12 +127,21 @@
/// variables are set up from command line arguments.
///
bool BugDriver::run() {
- // The first thing that we must do is determine what the problem is. Does the
- // optimization series crash the compiler, or does it produce illegal code?
- // We make the top-level decision by trying to run all of the passes on the
- // the input program, which should generate a bytecode file. If it does
- // generate a bytecode file, then we know the compiler didn't crash, so try
- // to diagnose a miscompilation.
+ // The first thing to do is determine if we're running as a child. If we are,
+ // then what to do is very narrow. This form of invocation is only called
+ // from the runPasses method to actually run those passes in a child process.
+ if (run_as_child) {
+ // Execute the passes
+ return runPassesAsChild(PassesToRun);
+ }
+
+ // If we're not running as a child, the first thing that we must do is
+ // determine what the problem is. Does the optimization series crash the
+ // compiler, or does it produce illegal code? We make the top-level
+ // decision by trying to run all of the passes on the the input program,
+ // which should generate a bytecode file. If it does generate a bytecode
+ // file, then we know the compiler didn't crash, so try to diagnose a
+ // miscompilation.
if (!PassesToRun.empty()) {
std::cout << "Running selected passes on program to test for crash: ";
if (runPasses(PassesToRun))