Add new method
authorChris Lattner <sabre@nondot.org>
Sun, 14 Mar 2004 21:17:03 +0000 (21:17 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 14 Mar 2004 21:17:03 +0000 (21:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12394 91177308-0d34-0410-b5e6-96231b3b80d8

tools/bugpoint/BugDriver.h
tools/bugpoint/OptimizerDriver.cpp

index a4428cffea976980942d8b48e26fe686b05df66d..b1cc3e830ba155f59e975f61e35316bd4b691c8c 100644 (file)
@@ -190,6 +190,11 @@ public:
   /// program or if the loop extractor crashes.
   Module *ExtractLoop(Module *M);
 
+  /// runPassesOn - Carefully run the specified set of pass on the specified
+  /// module, returning the transformed module on success, or a null pointer on
+  /// failure.
+  Module *runPassesOn(Module *M, const std::vector<const PassInfo*> &Passes);
+
   /// runPasses - Run the specified passes on Program, outputting a bytecode
   /// file and writting the filename into OutputFile if successful.  If the
   /// optimizations fail for some reason (optimizer crashes), return true,
index d21b5b59521358c05465b347b03eb47a12cf1337..d741265606adad7edec25c1ee1d9c35bad1c3f70 100644 (file)
@@ -161,3 +161,26 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
   return !ExitedOK;
 }
 
+
+/// runPassesOn - Carefully run the specified set of pass on the specified
+/// module, returning the transformed module on success, or a null pointer on
+/// failure.
+Module *BugDriver::runPassesOn(Module *M,
+                               const std::vector<const PassInfo*> &Passes) {
+  Module *OldProgram = swapProgramIn(M);
+  std::string BytecodeResult;
+  if (runPasses(Passes, BytecodeResult, false/*delete*/, true/*quiet*/))
+    return 0;
+
+  // Restore the current program.
+  swapProgramIn(OldProgram);
+
+  Module *Ret = ParseInputFile(BytecodeResult);
+  if (Ret == 0) {
+    std::cerr << getToolName() << ": Error reading bytecode file '"
+              << BytecodeResult << "'!\n";
+    exit(1);
+  }
+  removeFile(BytecodeResult);  // No longer need the file on disk
+  return Ret;
+}