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);

Implementations§

Create a new empty switch

source

pub fn set_entry(&mut self, index: u128, block: Block)

Set a switch entry

Get a reference to all existing entries

Build the switch

Arguments
  • The function builder to emit to
  • The value to switch on
  • The default block

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.