Skip to content

Commit fdd7a64

Browse files
Add a index to track the location of the AST block out of which a basic block was carved out.
1 parent 7b3bc0a commit fdd7a64

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

include/blocks/basic_blocks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class basic_block {
1414
cfg_block successor;
1515
block::expr::Ptr branch_expr;
1616
block::stmt::Ptr parent;
17-
unsigned int index;
17+
unsigned int ast_index;
1818
unsigned int id;
1919
std::string name;
2020
};

src/blocks/basic_blocks.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
99
int basic_block_count = 0;
1010

1111
// step 1: fill the work_list
12+
unsigned int ast_index_counter = 0;
1213
for (auto st: ast->stmts) {
1314
auto bb = std::make_shared<basic_block>(std::to_string(basic_block_count));
1415
bb->parent = st;
15-
// bb->index = ;
16+
bb->ast_index = ast_index_counter++;
1617
work_list.push_back(bb);
1718
basic_block_count++;
1819
}
@@ -27,6 +28,7 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
2728
auto bb = work_list.front();
2829

2930
if (isa<block::stmt_block>(bb->parent)) {
31+
ast_index_counter = 0;
3032
stmt_block::Ptr stmt_block_ = to<stmt_block>(bb->parent);
3133
bb->name = "stmt" + bb->name;
3234

@@ -37,6 +39,7 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
3739
for (auto st: stmt_block_->stmts) {
3840
stmt_block_list.push_back(std::make_shared<basic_block>(std::to_string(basic_block_count++)));
3941
stmt_block_list.back()->parent = st;
42+
stmt_block_list.back()->ast_index = ast_index_counter++;
4043
}
4144

4245
// set the basic block successors

0 commit comments

Comments
 (0)