Add new method

llvm-svn: 12394
This commit is contained in:
Chris Lattner 2004-03-14 21:17:03 +00:00
parent fd72bed301
commit 1a5c540c27
2 changed files with 28 additions and 0 deletions

View 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,

View 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;
}