-namespace {
- std::vector<BasicBlock*> BlocksToNotExtract;
-
- /// BlockExtractorPass - This pass is used by bugpoint to extract all blocks
- /// from the module into their own functions except for those specified by the
- /// BlocksToNotExtract list.
- class BlockExtractorPass : public ModulePass {
- bool runOnModule(Module &M);
- };
- RegisterOpt<BlockExtractorPass>
- XX("extract-bbs", "Extract Basic Blocks From Module (for bugpoint use)");
-}
-
-bool BlockExtractorPass::runOnModule(Module &M) {
- std::set<BasicBlock*> TranslatedBlocksToNotExtract;
- for (unsigned i = 0, e = BlocksToNotExtract.size(); i != e; ++i) {
- BasicBlock *BB = BlocksToNotExtract[i];
- Function *F = BB->getParent();
-
- // Map the corresponding function in this module.
- Function *MF = M.getFunction(F->getName(), F->getFunctionType());
-
- // Figure out which index the basic block is in its function.
- Function::iterator BBI = MF->begin();
- std::advance(BBI, std::distance(F->begin(), Function::iterator(BB)));
- TranslatedBlocksToNotExtract.insert(BBI);
+std::unique_ptr<Module>
+BugDriver::extractMappedBlocksFromModule(const std::vector<BasicBlock *> &BBs,
+ Module *M) {
+ SmallString<128> Filename;
+ int FD;
+ std::error_code EC = sys::fs::createUniqueFile(
+ OutputPrefix + "-extractblocks%%%%%%%", FD, Filename);
+ if (EC) {
+ outs() << "*** Basic Block extraction failed!\n";
+ errs() << "Error creating temporary file: " << EC.message() << "\n";
+ EmitProgressBitcode(M, "basicblockextractfail", true);
+ return nullptr;
+ }
+ sys::RemoveFileOnSignal(Filename);
+
+ tool_output_file BlocksToNotExtractFile(Filename.c_str(), FD);
+ for (std::vector<BasicBlock*>::const_iterator I = BBs.begin(), E = BBs.end();
+ I != E; ++I) {
+ BasicBlock *BB = *I;
+ // If the BB doesn't have a name, give it one so we have something to key
+ // off of.
+ if (!BB->hasName()) BB->setName("tmpbb");
+ BlocksToNotExtractFile.os() << BB->getParent()->getName() << " "
+ << BB->getName() << "\n";