Fix empty BrTable generation

This commit is contained in:
Rerumu 2022-05-20 22:38:03 -04:00
parent 935fc86607
commit 29e7c972ed

View File

@ -129,9 +129,16 @@ fn condense_jump_table(list: &[u32]) -> Vec<(usize, usize, u32)> {
impl Driver for BrTable { impl Driver for BrTable {
fn write(&self, mng: &mut Manager, w: &mut dyn Write) -> Result<()> { fn write(&self, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
let default = self.data.default.try_into().unwrap();
// Our condition should be pure so we probably don't need
// to emit it in this case.
if self.data.table.is_empty() {
return write_br_at(default, mng, w);
}
write!(w, "temp = ")?; write!(w, "temp = ")?;
self.cond.write(mng, w)?; self.cond.write(mng, w)?;
write!(w, " ")?;
for (start, end, dest) in condense_jump_table(&self.data.table) { for (start, end, dest) in condense_jump_table(&self.data.table) {
if start == end { if start == end {
@ -145,7 +152,7 @@ impl Driver for BrTable {
} }
write!(w, " ")?; write!(w, " ")?;
write_br_at(self.data.default.try_into().unwrap(), mng, w)?; write_br_at(default, mng, w)?;
write!(w, "end ") write!(w, "end ")
} }
} }