void StatementList::makeIsect(StatementList &a, LocationSet &b) { if (this == &a) { // *this = *this isect b for (auto it = a.begin(); it != a.end();) { assert((*it)->isAssignment()); Assignment *as = static_cast<Assignment *>(*it); if (!b.contains(as->getLeft())) { it = m_list.erase(it); } else { it++; } } } else { // normal assignment clear(); for (Statement *stmt : a) { assert(stmt->isAssignment()); Assignment *as = static_cast<Assignment *>(stmt); if (b.contains(as->getLeft())) { append(as); } } } }
void removeRedundantBlocks(BlockPtr b) { StatementList& children = b->getChildren(); for (size_t i = 0; i < children.size(); ++i) { if (REN_DYNAMIC_CAST_PTR(ib, Block, children[i])) { removeRedundantBlocks(ib); StatementList sl = ib->getChildren(); children.erase(children.begin() + i); children.insert(children.begin() + i, sl.begin(), sl.end()); --i; } } }
void StatementList::append(const StatementList &sl) { if (&sl == this) { const size_t oldSize = m_list.size(); auto it = m_list.begin(); for (size_t i = 0; i < oldSize; i++) { m_list.push_back(*it++); } } else { m_list.insert(end(), sl.begin(), sl.end()); } }
void MiniDebugger::miniDebugger(UserProc *proc, const char *description) { OStream q_cout(stdout); QTextStream q_cin(stdin); q_cout << "decompiling " << proc->getName() << ": " << description << "\n"; QString stopAt; if (stopAt.isEmpty() || !proc->getName().compare(stopAt)) { // This is a mini command line debugger. Feel free to expand it. for (const Statement *stmt : watches) { stmt->print(q_cout); q_cout << "\n"; } q_cout << " <press enter to continue> \n"; QString line; while (true) { line.clear(); q_cin >> line; if (line.startsWith("print")) { proc->print(q_cout); } else if (line.startsWith("fprint")) { QFile tgt("out.proc"); if (tgt.open(QFile::WriteOnly)) { OStream of(&tgt); proc->print(of); } } else if (line.startsWith("run ")) { QStringList parts = line.trimmed().split(" ", QString::SkipEmptyParts); if (parts.size() > 1) { stopAt = parts[1]; } break; } else if (line.startsWith("watch ")) { QStringList parts = line.trimmed().split(" ", QString::SkipEmptyParts); if (parts.size() > 1) { int n = parts[1].toInt(); StatementList stmts; proc->getStatements(stmts); StatementList::iterator it; for (it = stmts.begin(); it != stmts.end(); ++it) { if ((*it)->getNumber() == n) { watches.insert(*it); q_cout << "watching " << *it << "\n"; } } } } else { break; } } } }