Skip to content

Commit

Permalink
improvement(semantic/cfg): better control flow for DoWhileStatements.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed May 28, 2024
1 parent 23229f3 commit 620cab3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
13 changes: 5 additions & 8 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
self.visit_statement(&stmt.body);

/* cfg - condition basic block */
let after_body_graph_ix = self.cfg.current_node_ix;
let start_of_condition_graph_ix = self.cfg.new_basic_block();
/* cfg */

Expand All @@ -655,18 +656,14 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {

let end_do_while_graph_ix = self.cfg.new_basic_block();

// before do while to start of condition basic block
self.cfg.add_edge(
before_do_while_stmt_graph_ix,
start_of_condition_graph_ix,
EdgeType::Normal,
);
// before do while to start of body basic block
self.cfg.add_edge(before_do_while_stmt_graph_ix, start_body_graph_ix, EdgeType::Normal);
// body of do-while to start of condition
self.cfg.add_edge(start_body_graph_ix, start_of_condition_graph_ix, EdgeType::Backedge);
self.cfg.add_edge(after_body_graph_ix, start_of_condition_graph_ix, EdgeType::Normal);
// end of condition to after do while
self.cfg.add_edge(end_of_condition_graph_ix, end_do_while_graph_ix, EdgeType::Normal);
// end of condition to after start of body
self.cfg.add_edge(end_of_condition_graph_ix, start_body_graph_ix, EdgeType::Normal);
self.cfg.add_edge(end_of_condition_graph_ix, start_body_graph_ix, EdgeType::Backedge);

self.cfg.restore_state(
&statement_state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ digraph {
2 -> 3 [ label = Normal ]
4 -> 5 [ label = Unreachable , style = "dotted" ]
4 -> 5 [ label = Normal ]
3 -> 6 [ label = Normal ]
4 -> 6 [ label = Backedge ]
3 -> 4 [ label = Normal ]
5 -> 6 [ label = Normal ]
6 -> 7 [ label = Normal ]
6 -> 4 [ label = Normal ]
6 -> 4 [ label = Backedge ]
7 -> 8 [ label = Unreachable , style = "dotted" ]
2 -> 9 [ label = Normal ]
10 -> 11 [ label = Unreachable , style = "dotted" ]
10 -> 11 [ label = Normal ]
9 -> 12 [ label = Normal ]
10 -> 12 [ label = Backedge ]
9 -> 10 [ label = Normal ]
11 -> 12 [ label = Normal ]
12 -> 13 [ label = Normal ]
12 -> 10 [ label = Normal ]
12 -> 10 [ label = Backedge ]
13 -> 14 [ label = Normal ]
0 -> 15 [ label = Normal ]
}

0 comments on commit 620cab3

Please sign in to comment.