Remove the concept of non-dense jump tables.
WebAssembly doesn't have non-dense jump tables, and higher-level users are better served by the facilities in lib/frontend/src/switch.rs for working with non-dense switches. This eliminates the concept of "absent" jump table entries, which were represented as "0" in the text format. Also, jump table contents are now enclosed in `[` and `]`, so that we can unambiguously display empty jump tables. Previously, empty jump tables were displayed as if they had a single absent entry.
This commit is contained in:
@@ -152,12 +152,11 @@ impl<'short, 'long> InstBuilderBase<'short> for FuncInstBuilder<'short, 'long> {
|
||||
.jump_tables
|
||||
.get(table)
|
||||
.expect("you are referencing an undeclared jump table")
|
||||
.entries()
|
||||
.map(|(_, ebb)| ebb)
|
||||
.filter(|dest_ebb| unique.insert(*dest_ebb))
|
||||
.iter()
|
||||
.filter(|&dest_ebb| unique.insert(*dest_ebb))
|
||||
{
|
||||
self.builder.func_ctx.ssa.declare_ebb_predecessor(
|
||||
dest_ebb,
|
||||
*dest_ebb,
|
||||
self.builder.position.basic_block.unwrap(),
|
||||
inst,
|
||||
)
|
||||
@@ -336,11 +335,6 @@ impl<'a> FunctionBuilder<'a> {
|
||||
self.func.create_jump_table(data)
|
||||
}
|
||||
|
||||
/// Inserts an entry in a previously declared jump table.
|
||||
pub fn insert_jump_table_entry(&mut self, jt: JumpTable, index: usize, ebb: Ebb) {
|
||||
self.func.insert_jump_table_entry(jt, index, ebb)
|
||||
}
|
||||
|
||||
/// Creates a stack slot in the function, to be used by `stack_load`, `stack_store` and
|
||||
/// `stack_addr` instructions.
|
||||
pub fn create_stack_slot(&mut self, data: StackSlotData) -> StackSlot {
|
||||
|
||||
@@ -672,8 +672,8 @@ impl SSABuilder {
|
||||
}
|
||||
|
||||
for old_dest in func.jump_tables[jt].as_mut_slice() {
|
||||
if *old_dest == PackedOption::from(dest_ebb) {
|
||||
*old_dest = PackedOption::from(middle_ebb);
|
||||
if *old_dest == dest_ebb {
|
||||
*old_dest = middle_ebb;
|
||||
}
|
||||
}
|
||||
let mut cur = FuncCursor::new(func).at_bottom(middle_ebb);
|
||||
@@ -1005,7 +1005,7 @@ mod tests {
|
||||
// Here is the pseudo-program we want to translate:
|
||||
//
|
||||
// function %f {
|
||||
// jt = jump_table ebb2, 0, ebb1
|
||||
// jt = jump_table [ebb2, ebb1]
|
||||
// ebb0:
|
||||
// x = 1;
|
||||
// br_table x, ebb2, jt
|
||||
@@ -1039,9 +1039,9 @@ mod tests {
|
||||
};
|
||||
ssa.def_var(x_var, x1, block0);
|
||||
|
||||
// jt = jump_table ebb2, 0, ebb1
|
||||
// jt = jump_table [ebb2, ebb1]
|
||||
jump_table.push_entry(ebb2);
|
||||
jump_table.set_entry(2, ebb1);
|
||||
jump_table.push_entry(ebb1);
|
||||
let jt = func.create_jump_table(jump_table);
|
||||
|
||||
// ebb0:
|
||||
|
||||
@@ -244,7 +244,7 @@ mod tests {
|
||||
let func = setup!(0, [0, 1,]);
|
||||
assert_eq!(
|
||||
func,
|
||||
" jt0 = jump_table ebb1, ebb2
|
||||
" jt0 = jump_table [ebb1, ebb2]
|
||||
|
||||
ebb0:
|
||||
v0 = iconst.i8 0
|
||||
@@ -280,8 +280,8 @@ ebb3:
|
||||
let func = setup!(0, [0, 1, 5, 7, 10, 11, 12,]);
|
||||
assert_eq!(
|
||||
func,
|
||||
" jt0 = jump_table ebb1, ebb2
|
||||
jt1 = jump_table ebb5, ebb6, ebb7
|
||||
" jt0 = jump_table [ebb1, ebb2]
|
||||
jt1 = jump_table [ebb5, ebb6, ebb7]
|
||||
|
||||
ebb0:
|
||||
v0 = iconst.i8 0
|
||||
|
||||
Reference in New Issue
Block a user