Warn about duplicate labels (in riscv).

This commit is contained in:
chriseth
2023-04-20 23:06:52 +02:00
parent c20de5340b
commit 680dfd4124

View File

@@ -110,7 +110,12 @@ pub fn extract_label_offsets(statements: &[Statement]) -> BTreeMap<&str, usize>
Statement::Label(l) => Some((l.as_str(), i)),
Statement::Directive(_, _) | Statement::Instruction(_, _) => None,
})
.collect()
.fold(BTreeMap::new(), |mut acc, (n, i)| {
if acc.insert(n, i).is_some() {
panic!("Duplicate label: {n}")
}
acc
})
}
pub fn referenced_labels(statement: &Statement) -> BTreeSet<&str> {