void BlockBuilder::makeBlocks() { /** uses the base class GraphBuilder to work out which elements are connected (a subGraph) Each subGraph will be used to make a new PFBlock */ for (auto& elementIds : m_subGraphs) { if (elementIds.size() > 1) { sortIds(elementIds); // TODO allow sorting by energy using a helper class } auto block = PFBlock(elementIds, m_edges); // make the block PDebug::write("Made {}", block); // put the block in the unordered map of blocks using move IdType id = block.uniqueId(); m_blocks.emplace(id, std::move(block)); // update the history nodes (if they exist) if (m_historyNodes.size() > 0) { // make a new history node for the block and add into the history Nodes m_historyNodes.emplace(id, std::move(PFNode(id))); // move auto storedBlocknode = m_historyNodes[id]; // add in the links between the block elements and the block for (auto elemid : m_blocks[id].elementIds()) { m_historyNodes[elemid].addChild(storedBlocknode); } } } }
void dissemble(PFBlock fb) { Opcodes opcode; int rmode,rdata, k = 0; string name; Instruction *pi = fb->pstart; while (pi != end_of_code) { opcode = (Opcodes)pi->opcode; // *add 1.2.4 HALT+data is not always a breakpoint! // (it is used as a NOP + <any useful tag data>) if (opcode == HALT) { if (pi->data < MAX_BREAKPOINTS) { Breakpoint *pb = Breakpoint::from_id(pi->data); Instruction ai = pb->saved_instruction(); std::cout << "*"; opcode = (Opcodes)ai.opcode; rmode = ai.rmode; rdata = ai.data; } else { opcode = NOP; rdata = pi->data; } } else { rmode = pi->rmode; rdata = pi->data; } name = get_opcode_name(opcode); std::cout << k++ << ' ' << name << '\t'; if (opcode == CCALL || opcode == CALL || opcode == CALLD || opcode == CALLN) { FBlock* pfb; void *data = data_ptr(rdata); if (opcode == CALLN) pfb = Builtin::imported_fblock_from_function((void*)((NFBlock *)data)->pfn); else pfb = PFBlock(data_ptr(rdata)); if (pfb) Function::from_fun_block(pfb)->dump(std::cout); } else if (opcode == JSWITCH) { int *swb = (int *)data_ptr(rdata); int sz = *swb++; int def = *swb++; std::cout << '(' << sz << ',' << def << ") "; for (int i = 0; i < sz; i++) std::cout << *swb++ << ' ' << *swb++ << ' '; } else if (opcode == TOSD || opcode == TPODS) { PClass pc = *(PClass *)data_ptr(rdata); std::cout << pc->name(); } else { if (rmode) switch(rmode) { case DIRECT: std::cout << "D "; break; case SREL: std::cout << "R "; break; case OREL: std::cout << "S "; break; } if (rdata != 0) std::cout << rdata; } std::cout << std::endl; if (opcode == RET || opcode == RETI || opcode == RETD) break; pi++; } }