//===- OptimizerDriver.cpp - Allow BugPoint to run passes safely ----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
//
// This file defines an interface that allows bugpoint to run various passes
-// without the threat of a buggy pass corrupting bugpoint (of course bugpoint
-// may have it's own bugs, but that's another story...). It acheives this by
+// without the threat of a buggy pass corrupting bugpoint (of course, bugpoint
+// may have its own bugs, but that's another story...). It achieves this by
// forking a copy of itself and having the child process do the optimizations.
// If this client dies, we can always fork a new one. :)
//
//===----------------------------------------------------------------------===//
#include "BugDriver.h"
-#include "SystemUtils.h"
#include "llvm/PassManager.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Bytecode/WriteBytecodePass.h"
#include "llvm/Target/TargetData.h"
+#include "Support/FileUtilities.h"
+#include <fstream>
+#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <fstream>
/// writeProgramToFile - This writes the current "Program" to the named bytecode
/// file. If an error occurs, true is returned.
/// EmitProgressBytecode - This function is used to output the current Program
-/// to a file named "bugpoing-ID.bc".
+/// to a file named "bugpoint-ID.bc".
///
void BugDriver::EmitProgressBytecode(const std::string &ID, bool NoFlyer) {
// Output the input to the current pass to a bytecode file, emit a message
std::cout << getPassesString(PassesToRun) << "\n";
}
-/// FIXME: This should be parameterizable!!
-static TargetData TD("bugpoint target");
-
static void RunChild(Module *Program,const std::vector<const PassInfo*> &Passes,
const std::string &OutFilename) {
std::ofstream OutFile(OutFilename.c_str());
}
PassManager PM;
+ // Make sure that the appropriate target data is always used...
+ PM.add(new TargetData("bugpoint", Program));
+
for (unsigned i = 0, e = Passes.size(); i != e; ++i) {
if (Passes[i]->getNormalCtor())
PM.add(Passes[i]->getNormalCtor()());
- else if (Passes[i]->getDataCtor())
- PM.add(Passes[i]->getDataCtor()(TD)); // Provide dummy target data...
else
std::cerr << "Cannot create pass yet: " << Passes[i]->getPassName()
<< "\n";
}
/// runPasses - Run the specified passes on Program, outputting a bytecode file
-/// and writting the filename into OutputFile if successful. If the
+/// and writing the filename into OutputFile if successful. If the
/// optimizations fail for some reason (optimizer crashes), return true,
/// otherwise return false. If DeleteOutput is set to true, the bytecode is
/// deleted on success, and the filename string is undefined. This prints to
if (DeleteOutput)
removeFile(OutputFilename);
- if (!Quiet) std::cout << (Status ? "Crashed!\n" : "Success!\n");
+ bool ExitedOK = WIFEXITED(Status) && WEXITSTATUS(Status) == 0;
+
+ if (!Quiet) {
+ if (ExitedOK)
+ std::cout << "Success!\n";
+ else if (WIFEXITED(Status))
+ std::cout << "Exited with error code '" << WEXITSTATUS(Status) << "'\n";
+ else if (WIFSIGNALED(Status))
+ std::cout << "Crashed with signal #" << WTERMSIG(Status) << "\n";
+#ifdef WCOREDUMP
+ else if (WCOREDUMP(Status))
+ std::cout << "Dumped core\n";
+#endif
+ else
+ std::cout << "Failed for unknown reason!\n";
+ }
// Was the child successful?
- return Status != 0;
+ return !ExitedOK;
}