Struct cranelift_frontend::Switch
source · pub struct Switch { /* private fields */ }
Expand description
Unlike with br_table
, Switch
cases may be sparse or non-0-based.
They emit efficient code using branches, jump tables, or a combination of both.
Example
let block0 = builder.create_block();
let block1 = builder.create_block();
let block2 = builder.create_block();
let fallback = builder.create_block();
let val = builder.ins().iconst(I32, 1);
let mut switch = Switch::new();
switch.set_entry(0, block0);
switch.set_entry(1, block1);
switch.set_entry(7, block2);
switch.emit(&mut builder, val, fallback);