built dom

This commit is contained in:
2024-10-17 15:20:27 +00:00
parent 84c92dac81
commit c7470f2d45
3 changed files with 84 additions and 1 deletions

View File

@ -71,6 +71,19 @@ CFGNodeCollection GetCFGNodeCollectionsDifference(const CFGNodeCollection &a, co
return res;
}
bool CFGNodeCollectionIsSame(const CFGNodeCollection &a, const CFGNodeCollection &b) {
auto ita = a.begin();
auto itb = b.begin();
while (ita != a.end() && itb != b.end()) {
if (*ita != *itb) {
return false;
}
ita++;
itb++;
}
return ita == a.end() && itb == b.end();
}
CFGType BuildCFGForFunction(const std::shared_ptr<FunctionDefItem> &func) {
CFGType res;
if (!func->init_block) {
@ -94,8 +107,11 @@ CFGType BuildCFGForFunction(const std::shared_ptr<FunctionDefItem> &func) {
if (auto br = std::dynamic_pointer_cast<BRAction>(block->exit_action)) {
node->successors.push_back(res.block_to_node[res.label_to_block[br->true_label_full]]);
node->successors.push_back(res.block_to_node[res.label_to_block[br->false_label_full]]);
res.block_to_node[res.label_to_block[br->true_label_full]]->predecessors.push_back(node.get());
res.block_to_node[res.label_to_block[br->false_label_full]]->predecessors.push_back(node.get());
} else if (auto uncond = std::dynamic_pointer_cast<UNConditionJMPAction>(block->exit_action)) {
node->successors.push_back(res.block_to_node[res.label_to_block[uncond->label_full]]);
res.block_to_node[res.label_to_block[uncond->label_full]]->predecessors.push_back(node.get());
} else if (auto ret = std::dynamic_pointer_cast<RETAction>(block->exit_action)) {
// do nothing
} else {