Skip to content

Commit

Permalink
Check and error on duplicate labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat-Lafon committed Jul 26, 2024
1 parent 3368738 commit 1158ba5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions brilirs/src/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,14 @@ impl BBFunction {
let mut curr_block = BasicBlock::new();
for instr in func.instrs {
match instr {
bril_rs::Code::Label { label, pos: _ } => {
bril_rs::Code::Label { label, pos } => {
if !curr_block.instrs.is_empty() || curr_block.label.is_some() {
blocks.push(curr_block);
curr_block = BasicBlock::new();
}
label_map.insert(label.to_string(), blocks.len());
if label_map.insert(label.to_string(), blocks.len()).is_some() {
return Err(InterpError::DuplicateLabel(label).add_pos(pos));
}
curr_block.label = Some(label);
}
bril_rs::Code::Instruction(i @ bril_rs::Instruction::Effect { op, .. })
Expand Down
2 changes: 2 additions & 0 deletions brilirs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub enum InterpError {
NotOneChar,
#[error("multiple functions of the same name found")]
DuplicateFunction,
#[error("duplicate label `{0}` found")]
DuplicateLabel(String),
#[error("Expected empty return for `{0}`, found value")]
NonEmptyRetForFunc(String),
#[error("cannot allocate `{0}` entries")]
Expand Down

0 comments on commit 1158ba5

Please sign in to comment.