basically can color

This commit is contained in:
2024-10-21 16:42:40 +00:00
parent 04ab579484
commit 8216cb774c
8 changed files with 284 additions and 51 deletions

View File

@ -3,23 +3,20 @@
CFGType BuildCFGForFunction(const std::shared_ptr<FunctionDefItem> &func) {
CFGType res;
auto init_block = func->init_block;
if (!func->init_block) {
// throw std::runtime_error("Function does not have an init block");
if (func->basic_blocks.size() == 0) throw std::runtime_error("Function does not have any block");
init_block = func->basic_blocks[0];
if (func->init_block) {
res.label_to_block[func->init_block->label_full] = func->init_block.get();
res.nodes.push_back(std::make_shared<CFGNodeType>());
res.entry = res.nodes.back().get();
res.entry->corresponding_block = func->init_block.get();
res.block_to_node[func->init_block.get()] = res.entry;
}
res.label_to_block[init_block->label_full] = init_block.get();
res.nodes.push_back(std::make_shared<CFGNodeType>());
res.entry = res.nodes.back().get();
res.entry->corresponding_block = init_block.get();
res.block_to_node[init_block.get()] = res.entry;
for (auto block_ptr : func->basic_blocks) {
res.label_to_block[block_ptr->label_full] = block_ptr.get();
res.nodes.push_back(std::make_shared<CFGNodeType>());
res.nodes.back()->corresponding_block = block_ptr.get();
res.block_to_node[block_ptr.get()] = res.nodes.back().get();
}
res.entry = res.nodes.front().get();
// now add information for successors and predecessors
for (auto node : res.nodes) {
auto block = node->corresponding_block;