Skip to content

Commit 06cb0db

Browse files
committed
feat: add jump done label. fix one block crash.
1 parent b75d53a commit 06cb0db

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tigerc/src/canon.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
};
77

88
pub fn canonicalize(stmt: ir::Statement) -> Vec<Block> {
9-
basic_block(linearize(stmt))
9+
basic_block(linearize(stmt)).0
1010
}
1111

1212
// The result will fit two properties:
@@ -186,7 +186,8 @@ impl Block {
186186
}
187187
}
188188

189-
fn basic_block(stmts: Vec<ir::Statement>) -> Vec<Block> {
189+
fn basic_block(stmts: Vec<ir::Statement>) -> (Vec<Block>, Label) {
190+
let done_label = Label::new();
190191
let mut blocks = vec![];
191192
let mut block: Option<Block> = None;
192193
for stmt in stmts {
@@ -223,5 +224,10 @@ fn basic_block(stmts: Vec<ir::Statement>) -> Vec<Block> {
223224
}
224225
}
225226
}
226-
blocks
227+
if block.is_some() {
228+
blocks.push(block.take().unwrap());
229+
}
230+
// jump to end of function, avoid later reorder violate this
231+
blocks.last_mut().unwrap().push(ir::Statement::Jump { exp: ir::Exp::Name(done_label), labels: vec![done_label] });
232+
(blocks, done_label)
227233
}

0 commit comments

Comments
 (0)