void Decompiler::sortBasicBlock(BasicBlock *BB) { BasicBlock::InstListType *Cur = &BB->getInstList(); BasicBlock::InstListType::iterator P, I, E, S; I = Cur->begin(); E = Cur->end(); while (I != E) { P = I; if (++I == E) { break; // Note the terminator is always last instruction } if (Dis->getDebugOffset(P->getDebugLoc()) <= Dis->getDebugOffset(I->getDebugLoc())) { continue; } while (--P != Cur->begin() && Dis->getDebugOffset(P->getDebugLoc()) > Dis->getDebugOffset(I->getDebugLoc())) { // Do nothing. } // Insert at P, remove at I S = I; ++S; Instruction *Tmp = &(*I); Cur->remove(I); Cur->insertAfter(P, Tmp); I = S; } I = Cur->begin(); E = Cur->end(); while (I != E) { // outs() << "Line #: " << I->getDebugLoc().getLine() << "\n"; ++I; } }