From 3b6441e1050a9a2a55c79f58513191b3195fdaf7 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 14 Mar 2004 21:17:03 +0000 Subject: [PATCH] Add new method git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12394 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/bugpoint/BugDriver.h | 5 +++++ tools/bugpoint/OptimizerDriver.cpp | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h index a4428cffea9..b1cc3e830ba 100644 --- a/tools/bugpoint/BugDriver.h +++ b/tools/bugpoint/BugDriver.h @@ -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 &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, diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp index d21b5b59521..d741265606a 100644 --- a/tools/bugpoint/OptimizerDriver.cpp +++ b/tools/bugpoint/OptimizerDriver.cpp @@ -161,3 +161,26 @@ bool BugDriver::runPasses(const std::vector &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 &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; +} -- 2.34.1