Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brilirs: error on duplicate labels #331

Merged
merged 3 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 8 additions & 26 deletions brilirs/src/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,43 +210,28 @@ 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() {
if let Some(old_label) = curr_block.label.as_ref() {
label_map.insert(old_label.to_string(), blocks.len());
}
blocks.push(curr_block);
curr_block = BasicBlock::new();
}
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(bril_rs::Instruction::Effect {
op,
args,
funcs,
labels,
pos,
}) if op == bril_rs::EffectOps::Jump
|| op == bril_rs::EffectOps::Branch
|| op == bril_rs::EffectOps::Return =>
bril_rs::Code::Instruction(i @ bril_rs::Instruction::Effect { op, .. })
if op == bril_rs::EffectOps::Jump
|| op == bril_rs::EffectOps::Branch
|| op == bril_rs::EffectOps::Return =>
{
let i = bril_rs::Instruction::Effect {
op,
args,
funcs,
labels,
pos,
};
curr_block.numified_instrs.push(NumifiedInstruction::new(
&i,
&mut num_of_vars,
&mut num_var_map,
func_map,
)?);
curr_block.instrs.push(i);
if let Some(l) = curr_block.label.as_ref() {
label_map.insert(l.to_string(), blocks.len());
}
blocks.push(curr_block);
curr_block = BasicBlock::new();
}
Expand All @@ -263,9 +248,6 @@ impl BBFunction {
}

if !curr_block.instrs.is_empty() || curr_block.label.is_some() {
if let Some(l) = curr_block.label.as_ref() {
label_map.insert(l.to_string(), blocks.len());
}
blocks.push(curr_block);
}

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
Loading