+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);
+ if (!ErrInfo.empty()) {
+ errs() << "Error opening bitcode file: " << ChildOutput << "\n";
+ return 1;
+ }
+
+ PassManager PM;
+ // Make sure that the appropriate target data is always used...
+ PM.add(new TargetData(Program));
+
+ for (unsigned i = 0, e = Passes.size(); i != e; ++i) {
+ if (Passes[i]->getNormalCtor())
+ PM.add(Passes[i]->getNormalCtor()());
+ else
+ errs() << "Cannot create pass yet: " << Passes[i]->getPassName() << "\n";
+ }
+ // Check that the module is well formed on completion of optimization
+ PM.add(createVerifierPass());
+
+ // Write bitcode out to disk as the last step...
+ PM.add(createBitcodeWriterPass(OutFile));
+
+ // Run all queued passes.
+ PM.run(*Program);
+
+ return 0;
+}
+