+
+/// 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,
+ bool AutoDebugCrashes, unsigned NumExtraArgs,
+ const char * const *ExtraArgs) {
+ Module *OldProgram = swapProgramIn(M);
+ std::string BitcodeResult;
+ if (runPasses(Passes, BitcodeResult, false/*delete*/, true/*quiet*/,
+ NumExtraArgs, ExtraArgs)) {
+ if (AutoDebugCrashes) {
+ cerr << " Error running this sequence of passes"
+ << " on the input program!\n";
+ delete OldProgram;
+ EmitProgressBitcode("pass-error", false);
+ exit(debugOptimizerCrash());
+ }
+ swapProgramIn(OldProgram);
+ return 0;
+ }
+
+ // Restore the current program.
+ swapProgramIn(OldProgram);
+
+ Module *Ret = ParseInputFile(BitcodeResult);
+ if (Ret == 0) {
+ cerr << getToolName() << ": Error reading bitcode file '"
+ << BitcodeResult << "'!\n";
+ exit(1);
+ }
+ sys::Path(BitcodeResult).eraseFromDisk(); // No longer need the file on disk
+ return Ret;
+}