use early exits to reduce indentation.
[oota-llvm.git] / tools / bugpoint / ExecutionDriver.cpp
index 3916957a627806aafd909f243702fe3715fdb958..feda331177b166a62536526ccf85c0e882a029ca 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/SystemUtils.h"
+#include "llvm/Support/raw_ostream.h"
 #include <fstream>
 
 using namespace llvm;
@@ -99,6 +100,10 @@ namespace llvm {
   cl::list<std::string>
   InputArgv("args", cl::Positional, cl::desc("<program arguments>..."),
             cl::ZeroOrMore, cl::PositionalEatsArgs);
+
+  cl::opt<std::string>
+  OutputPrefix("output-prefix", cl::init("bugpoint"),
+            cl::desc("Prefix to use for outputs (default: 'bugpoint')"));
 }
 
 namespace {
@@ -273,16 +278,16 @@ bool BugDriver::initializeExecutionEnvironment() {
 ///
 void BugDriver::compileProgram(Module *M) {
   // Emit the program to a bitcode file...
-  sys::Path BitcodeFile ("bugpoint-test-program.bc");
+  sys::Path BitcodeFile (OutputPrefix + "-test-program.bc");
   std::string ErrMsg;
   if (BitcodeFile.makeUnique(true,&ErrMsg)) {
     errs() << ToolName << ": Error making unique filename: " << ErrMsg 
            << "\n";
     exit(1);
   }
-  if (writeProgramToFile(BitcodeFile.toString(), M)) {
+  if (writeProgramToFile(BitcodeFile.str(), M)) {
     errs() << ToolName << ": Error emitting bitcode to file '"
-           << BitcodeFile << "'!\n";
+           << BitcodeFile.str() << "'!\n";
     exit(1);
   }
 
@@ -290,7 +295,7 @@ void BugDriver::compileProgram(Module *M) {
   FileRemover BitcodeFileRemover(BitcodeFile, !SaveTemps);
 
   // Actually compile the program!
-  Interpreter->compileProgram(BitcodeFile.toString());
+  Interpreter->compileProgram(BitcodeFile.str());
 }
 
 
@@ -309,13 +314,13 @@ std::string BugDriver::executeProgram(std::string OutputFile,
   std::string ErrMsg;
   if (BitcodeFile.empty()) {
     // Emit the program to a bitcode file...
-    sys::Path uniqueFilename("bugpoint-test-program.bc");
+    sys::Path uniqueFilename(OutputPrefix + "-test-program.bc");
     if (uniqueFilename.makeUnique(true, &ErrMsg)) {
       errs() << ToolName << ": Error making unique filename: "
              << ErrMsg << "!\n";
       exit(1);
     }
-    BitcodeFile = uniqueFilename.toString();
+    BitcodeFile = uniqueFilename.str();
 
     if (writeProgramToFile(BitcodeFile, Program)) {
       errs() << ToolName << ": Error emitting bitcode to file '"
@@ -329,7 +334,7 @@ std::string BugDriver::executeProgram(std::string OutputFile,
   sys::Path BitcodePath (BitcodeFile);
   FileRemover BitcodeFileRemover(BitcodePath, CreatedBitcode && !SaveTemps);
 
-  if (OutputFile.empty()) OutputFile = "bugpoint-execution-output";
+  if (OutputFile.empty()) OutputFile = OutputPrefix + "-execution-output";
 
   // Check to see if this is a valid output filename...
   sys::Path uniqueFile(OutputFile);
@@ -338,7 +343,7 @@ std::string BugDriver::executeProgram(std::string OutputFile,
            << ErrMsg << "\n";
     exit(1);
   }
-  OutputFile = uniqueFile.toString();
+  OutputFile = uniqueFile.str();
 
   // Figure out which shared objects to run, if any.
   std::vector<std::string> SharedObjs(AdditionalSOs);
@@ -393,7 +398,7 @@ std::string BugDriver::compileSharedObject(const std::string &BitcodeFile) {
   GCC::FileType FT = SafeInterpreter->OutputCode(BitcodeFile, OutputFile);
 
   std::string SharedObjectFile;
-  if (gcc->MakeSharedObject(OutputFile.toString(), FT,
+  if (gcc->MakeSharedObject(OutputFile.str(), FT,
                             SharedObjectFile, AdditionalLinkerArgs))
     exit(1);
 
@@ -447,7 +452,7 @@ bool BugDriver::diffProgram(const std::string &BitcodeFile,
   std::string Error;
   bool FilesDifferent = false;
   if (int Diff = DiffFilesWithTolerance(sys::Path(ReferenceOutputFile),
-                                        sys::Path(Output.toString()),
+                                        sys::Path(Output.str()),
                                         AbsTolerance, RelTolerance, &Error)) {
     if (Diff == 2) {
       errs() << "While diffing output: " << Error << '\n';