Skip to content

Commit

Permalink
Address #295
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat-Lafon committed Sep 16, 2023
1 parent c543ae2 commit b7ec510
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 23 deletions.
2 changes: 1 addition & 1 deletion brilirs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ plot: plot.svg
# This is primarily used for running examples and debuging a bril program
.PHONY: example
example:
bril2json < ../benchmarks/sqrt.bril | cargo run
bril2json < ../benchmarks/float/sqrt.bril | cargo run
44 changes: 22 additions & 22 deletions brilirs/src/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,28 +289,28 @@ impl BBFunction {
}
let last_idx = self.blocks.len() - 1;
for (i, block) in self.blocks.iter_mut().enumerate() {
// If we're before the last block
if i < last_idx {
// Get the last instruction
let last_instr = block.instrs.last().cloned();
if let Some(bril_rs::Instruction::Effect {
op: bril_rs::EffectOps::Jump | bril_rs::EffectOps::Branch,
labels,
..
}) = last_instr
{
for l in labels {
block
.exit
.push(*label_map.get(&l).ok_or(InterpError::MissingLabel(l))?);
}
} else if let Some(bril_rs::Instruction::Effect {
op: bril_rs::EffectOps::Return,
..
}) = last_instr
{
// We are done, there is no exit from this block
} else {
// Get the last instruction
let last_instr = block.instrs.last().cloned();
if let Some(bril_rs::Instruction::Effect {
op: bril_rs::EffectOps::Jump | bril_rs::EffectOps::Branch,
labels,
..
}) = last_instr
{
for l in labels {
block
.exit
.push(*label_map.get(&l).ok_or(InterpError::MissingLabel(l))?);
}
} else if let Some(bril_rs::Instruction::Effect {
op: bril_rs::EffectOps::Return,
..
}) = last_instr
{
// We are done, there is no exit from this block
} else {
// If we're before the last block
if i < last_idx {
block.exit.push(i + 1);
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/interp/core/non_linear_control_flow.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ARGS: false false
@main(b0: bool, b1: bool) {
jmp .start;
.end:
print x_0_2;
print x_1_2;
ret;
.l_1_3:
jmp .end;
.l_1_2:
x_1_2 : int = const 0;
jmp .l_1_3;
.l_1_1:
x_1_1 : int = const 1;
jmp .l_1_3;
.l_0_3:
br b1 .l_1_1 .l_1_2;
.l_0_2:
x_0_2 : int = const 2;
jmp .l_0_3;
.l_0_1:
x_0_1 : int = const 3;
jmp .l_0_3;
.start:
br b0 .l_0_1 .l_0_2;
}
2 changes: 2 additions & 0 deletions test/interp/core/non_linear_control_flow.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2
0

0 comments on commit b7ec510

Please sign in to comment.