Instead of abusing swapProgramIn, just add a Module argument to
[oota-llvm.git] / tools / bugpoint / OptimizerDriver.cpp
index 462718b7bf9eb702ee6f3d69542fd25b5f001ade..48936caf5fd1af2360fe561222f29f61ab3f8afa 100644 (file)
@@ -51,13 +51,13 @@ namespace {
 /// file.  If an error occurs, true is returned.
 ///
 bool BugDriver::writeProgramToFile(const std::string &Filename,
-                                   Module *M) const {
+                                   const Module *M) const {
   std::string ErrInfo;
   raw_fd_ostream Out(Filename.c_str(), ErrInfo,
                      raw_fd_ostream::F_Binary);
   if (!ErrInfo.empty()) return true;
   
-  WriteBitcodeToFile(M ? M : Program, Out);
+  WriteBitcodeToFile(M, Out);
   return false;
 }
 
@@ -65,12 +65,13 @@ bool BugDriver::writeProgramToFile(const std::string &Filename,
 /// EmitProgressBitcode - This function is used to output the current Program
 /// to a file named "bugpoint-ID.bc".
 ///
-void BugDriver::EmitProgressBitcode(const std::string &ID, bool NoFlyer) {
+void BugDriver::EmitProgressBitcode(const Module *M,
+                                    const std::string &ID, bool NoFlyer) {
   // Output the input to the current pass to a bitcode file, emit a message
   // telling the user how to reproduce it: opt -foo blah.bc
   //
   std::string Filename = OutputPrefix + "-" + ID + ".bc";
-  if (writeProgramToFile(Filename)) {
+  if (writeProgramToFile(Filename, M)) {
     errs() <<  "Error opening file '" << Filename << "' for writing!\n";
     return;
   }
@@ -83,7 +84,7 @@ void BugDriver::EmitProgressBitcode(const std::string &ID, bool NoFlyer) {
   outs() << getPassesString(PassesToRun) << "\n";
 }
 
-int BugDriver::runPassesAsChild(const std::vector<const StaticPassInfo*> &Passes) {
+int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) {
   std::string ErrInfo;
   raw_fd_ostream OutFile(ChildOutput.c_str(), ErrInfo,
                          raw_fd_ostream::F_Binary);
@@ -124,7 +125,7 @@ cl::opt<bool> SilencePasses("silence-passes", cl::desc("Suppress output of runni
 /// outs() a single line message indicating whether compilation was successful
 /// or failed.
 ///
-bool BugDriver::runPasses(const std::vector<const StaticPassInfo*> &Passes,
+bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
                           std::string &OutputFilename, bool DeleteOutput,
                           bool Quiet, unsigned NumExtraArgs,
                           const char * const *ExtraArgs) const {
@@ -178,7 +179,7 @@ bool BugDriver::runPasses(const std::vector<const StaticPassInfo*> &Passes,
     pass_args.push_back( std::string("-load"));
     pass_args.push_back( PluginLoader::getPlugin(i));
   }
-  for (std::vector<const StaticPassInfo*>::const_iterator I = Passes.begin(),
+  for (std::vector<const PassInfo*>::const_iterator I = Passes.begin(),
        E = Passes.end(); I != E; ++I )
     pass_args.push_back( std::string("-") + (*I)->getPassArgument() );
   for (std::vector<std::string>::const_iterator I = pass_args.begin(),
@@ -235,7 +236,7 @@ bool BugDriver::runPasses(const std::vector<const StaticPassInfo*> &Passes,
 /// module, returning the transformed module on success, or a null pointer on
 /// failure.
 Module *BugDriver::runPassesOn(Module *M,
-                               const std::vector<const StaticPassInfo*> &Passes,
+                               const std::vector<const PassInfo*> &Passes,
                                bool AutoDebugCrashes, unsigned NumExtraArgs,
                                const char * const *ExtraArgs) {
   Module *OldProgram = swapProgramIn(M);
@@ -246,7 +247,7 @@ Module *BugDriver::runPassesOn(Module *M,
       errs() << " Error running this sequence of passes"
              << " on the input program!\n";
       delete OldProgram;
-      EmitProgressBitcode("pass-error",  false);
+      EmitProgressBitcode(Program, "pass-error",  false);
       exit(debugOptimizerCrash());
     }
     swapProgramIn(OldProgram);