Struct walrus::InstrSeqBuilder
source · pub struct InstrSeqBuilder<'a> { /* private fields */ }
Expand description
A builder returned by instruction sequence-construction methods to build up instructions within a block/loop/if-else over time.
Implementations§
source§impl InstrSeqBuilder<'_>
impl InstrSeqBuilder<'_>
sourcepub fn id(&self) -> InstrSeqId
pub fn id(&self) -> InstrSeqId
Returns the id of the instruction sequence that we’re building.
sourcepub fn instrs(&self) -> &[(Instr, InstrLocId)]
pub fn instrs(&self) -> &[(Instr, InstrLocId)]
Get this instruction sequence’s instructions.
sourcepub fn instrs_mut(&mut self) -> &mut Vec<(Instr, InstrLocId)>
pub fn instrs_mut(&mut self) -> &mut Vec<(Instr, InstrLocId)>
Get this instruction sequence’s instructions mutably.
sourcepub fn instr(&mut self, instr: impl Into<Instr>) -> &mut Self
pub fn instr(&mut self, instr: impl Into<Instr>) -> &mut Self
Pushes a new instruction onto this builder’s sequence.
sourcepub fn instr_at(
&mut self,
position: usize,
instr: impl Into<Instr>
) -> &mut Self
pub fn instr_at( &mut self, position: usize, instr: impl Into<Instr> ) -> &mut Self
Splice a new instruction into this builder’s sequence at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn i32_const(&mut self, val: i32) -> &mut Self
pub fn i32_const(&mut self, val: i32) -> &mut Self
Creates an i32.const
instruction for the specified value.
sourcepub fn i64_const(&mut self, val: i64) -> &mut Self
pub fn i64_const(&mut self, val: i64) -> &mut Self
Creates an i64.const
instruction for the specified value.
sourcepub fn f32_const(&mut self, val: f32) -> &mut Self
pub fn f32_const(&mut self, val: f32) -> &mut Self
Creates an f32.const
instruction for the specified value
sourcepub fn f64_const(&mut self, val: f64) -> &mut Self
pub fn f64_const(&mut self, val: f64) -> &mut Self
Creates an f64.const
instruction for the specified value
sourcepub fn block(
&mut self,
ty: impl Into<InstrSeqType>,
make_block: impl FnOnce(&mut InstrSeqBuilder<'_>)
) -> &mut Self
pub fn block( &mut self, ty: impl Into<InstrSeqType>, make_block: impl FnOnce(&mut InstrSeqBuilder<'_>) ) -> &mut Self
Append a new, nested block ... end
to this builder’s sequence.
Example:
let mut module = walrus::Module::default();
let mut builder = walrus::FunctionBuilder::new(&mut module.types, &[], &[]);
// Append the following WAT to the function:
//
// block
// i32.const 1337
// drop
// end
builder
.func_body()
.block(None, |block| {
block
.i32_const(1337)
.drop();
});
sourcepub fn block_at(
&mut self,
position: usize,
ty: impl Into<InstrSeqType>,
make_block: impl FnOnce(&mut InstrSeqBuilder<'_>)
) -> &mut Self
pub fn block_at( &mut self, position: usize, ty: impl Into<InstrSeqType>, make_block: impl FnOnce(&mut InstrSeqBuilder<'_>) ) -> &mut Self
Append a new, nested block ... end
to this builder’s sequence.
Example:
let mut module = walrus::Module::default();
let mut builder = walrus::FunctionBuilder::new(&mut module.types, &[], &[]);
// Make the function's body be a single `unreachable` instruction.
builder
.func_body()
.unreachable();
// Splice the following WAT into the function, before the `unreachable`:
//
// block
// i32.const 1337
// drop
// end
builder
.func_body()
.block_at(0, None, |block| {
block
.i32_const(1337)
.drop();
});
sourcepub fn loop_(
&mut self,
ty: impl Into<InstrSeqType>,
make_loop: impl FnOnce(&mut InstrSeqBuilder<'_>)
) -> &mut Self
pub fn loop_( &mut self, ty: impl Into<InstrSeqType>, make_loop: impl FnOnce(&mut InstrSeqBuilder<'_>) ) -> &mut Self
Create a new loop ... end
instruction sequence.
Example
let mut module = walrus::Module::default();
let mut builder = walrus::FunctionBuilder::new(&mut module.types, &[], &[]);
// Append the following WAT to the function:
//
// block
// i32.const 1337
// drop
// end
builder
.func_body()
.loop_(None, |loop_| {
loop_
.i32_const(1337)
.drop();
});
sourcepub fn loop_at(
&mut self,
position: usize,
ty: impl Into<InstrSeqType>,
make_loop: impl FnOnce(&mut InstrSeqBuilder<'_>)
) -> &mut Self
pub fn loop_at( &mut self, position: usize, ty: impl Into<InstrSeqType>, make_loop: impl FnOnce(&mut InstrSeqBuilder<'_>) ) -> &mut Self
Splice a new loop ... end
into this instruction sequence at the given
position.
Example
let mut module = walrus::Module::default();
let mut builder = walrus::FunctionBuilder::new(&mut module.types, &[], &[]);
// Make the function's body be a single `unreachable` instruction.
builder
.func_body()
.unreachable();
// Splice the following WAT into the function, before the `unreachable`:
//
// loop
// i32.const 1337
// drop
// end
builder
.func_body()
.loop_at(0, None, |loop_| {
loop_
.i32_const(1337)
.drop();
});
sourcepub fn if_else(
&mut self,
ty: impl Into<InstrSeqType>,
consequent: impl FnOnce(&mut InstrSeqBuilder<'_>),
alternative: impl FnOnce(&mut InstrSeqBuilder<'_>)
) -> &mut Self
pub fn if_else( &mut self, ty: impl Into<InstrSeqType>, consequent: impl FnOnce(&mut InstrSeqBuilder<'_>), alternative: impl FnOnce(&mut InstrSeqBuilder<'_>) ) -> &mut Self
Build a new if <consequent> else <alternative> end
instruction
sequence.
Example
use walrus::ValType;
let mut module = walrus::Module::default();
let ty = module.types.add(&[], &[ValType::I32]);
let (flip_coin, _) = module.add_import_func("flip", "coin", ty);
let mut builder = walrus::FunctionBuilder::new(&mut module.types, &[], &[]);
builder
.func_body()
// (if (call $flip_coin)
// (then (i32.const 12))
// (else (i32.const 34)))
.call(flip_coin)
.if_else(
ValType::I32,
|then| {
then.i32_const(12);
},
|else_| {
else_.i32_const(34);
},
);
sourcepub fn if_else_at(
&mut self,
position: usize,
ty: impl Into<InstrSeqType>,
consequent: impl FnOnce(&mut InstrSeqBuilder<'_>),
alternative: impl FnOnce(&mut InstrSeqBuilder<'_>)
) -> &mut Self
pub fn if_else_at( &mut self, position: usize, ty: impl Into<InstrSeqType>, consequent: impl FnOnce(&mut InstrSeqBuilder<'_>), alternative: impl FnOnce(&mut InstrSeqBuilder<'_>) ) -> &mut Self
Splice a new if <consequent> else <alternative> end
into this
instruction sequence at the given position.
Example
use walrus::ValType;
let mut module = walrus::Module::default();
let ty = module.types.add(&[], &[ValType::I32]);
let (flip_coin, _) = module.add_import_func("flip", "coin", ty);
let mut builder = walrus::FunctionBuilder::new(&mut module.types, &[], &[]);
builder
.func_body()
.call(flip_coin)
.unreachable();
// Splice an if/else after the `call` and before the `unreachable`.
builder
.func_body()
.if_else_at(
1,
ValType::I32,
|then| {
then.i32_const(12);
},
|else_| {
else_.i32_const(34);
},
);
source§impl InstrSeqBuilder<'_>
impl InstrSeqBuilder<'_>
sourcepub fn call(&mut self, func: FunctionId) -> &mut Self
pub fn call(&mut self, func: FunctionId) -> &mut Self
Push a new Call
instruction onto this builder’s block.
sourcepub fn call_at(&mut self, position: usize, func: FunctionId) -> &mut Self
pub fn call_at(&mut self, position: usize, func: FunctionId) -> &mut Self
Splice a new Call
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn call_indirect(&mut self, ty: TypeId, table: TableId) -> &mut Self
pub fn call_indirect(&mut self, ty: TypeId, table: TableId) -> &mut Self
Push a new CallIndirect
instruction onto this builder’s block.
sourcepub fn call_indirect_at(
&mut self,
position: usize,
ty: TypeId,
table: TableId
) -> &mut Self
pub fn call_indirect_at( &mut self, position: usize, ty: TypeId, table: TableId ) -> &mut Self
Splice a new CallIndirect
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn local_get(&mut self, local: LocalId) -> &mut Self
pub fn local_get(&mut self, local: LocalId) -> &mut Self
Push a new LocalGet
instruction onto this builder’s block.
sourcepub fn local_get_at(&mut self, position: usize, local: LocalId) -> &mut Self
pub fn local_get_at(&mut self, position: usize, local: LocalId) -> &mut Self
Splice a new LocalGet
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn local_set(&mut self, local: LocalId) -> &mut Self
pub fn local_set(&mut self, local: LocalId) -> &mut Self
Push a new LocalSet
instruction onto this builder’s block.
sourcepub fn local_set_at(&mut self, position: usize, local: LocalId) -> &mut Self
pub fn local_set_at(&mut self, position: usize, local: LocalId) -> &mut Self
Splice a new LocalSet
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn local_tee(&mut self, local: LocalId) -> &mut Self
pub fn local_tee(&mut self, local: LocalId) -> &mut Self
Push a new LocalTee
instruction onto this builder’s block.
sourcepub fn local_tee_at(&mut self, position: usize, local: LocalId) -> &mut Self
pub fn local_tee_at(&mut self, position: usize, local: LocalId) -> &mut Self
Splice a new LocalTee
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn global_get(&mut self, global: GlobalId) -> &mut Self
pub fn global_get(&mut self, global: GlobalId) -> &mut Self
Push a new GlobalGet
instruction onto this builder’s block.
sourcepub fn global_get_at(&mut self, position: usize, global: GlobalId) -> &mut Self
pub fn global_get_at(&mut self, position: usize, global: GlobalId) -> &mut Self
Splice a new GlobalGet
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn global_set(&mut self, global: GlobalId) -> &mut Self
pub fn global_set(&mut self, global: GlobalId) -> &mut Self
Push a new GlobalSet
instruction onto this builder’s block.
sourcepub fn global_set_at(&mut self, position: usize, global: GlobalId) -> &mut Self
pub fn global_set_at(&mut self, position: usize, global: GlobalId) -> &mut Self
Splice a new GlobalSet
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn const_(&mut self, value: Value) -> &mut Self
pub fn const_(&mut self, value: Value) -> &mut Self
Push a new Const
instruction onto this builder’s block.
sourcepub fn const_at(&mut self, position: usize, value: Value) -> &mut Self
pub fn const_at(&mut self, position: usize, value: Value) -> &mut Self
Splice a new Const
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn binop(&mut self, op: BinaryOp) -> &mut Self
pub fn binop(&mut self, op: BinaryOp) -> &mut Self
Push a new Binop
instruction onto this builder’s block.
sourcepub fn binop_at(&mut self, position: usize, op: BinaryOp) -> &mut Self
pub fn binop_at(&mut self, position: usize, op: BinaryOp) -> &mut Self
Splice a new Binop
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn unop(&mut self, op: UnaryOp) -> &mut Self
pub fn unop(&mut self, op: UnaryOp) -> &mut Self
Push a new Unop
instruction onto this builder’s block.
sourcepub fn unop_at(&mut self, position: usize, op: UnaryOp) -> &mut Self
pub fn unop_at(&mut self, position: usize, op: UnaryOp) -> &mut Self
Splice a new Unop
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn select(&mut self, ty: Option<ValType>) -> &mut Self
pub fn select(&mut self, ty: Option<ValType>) -> &mut Self
Push a new Select
instruction onto this builder’s block.
sourcepub fn select_at(&mut self, position: usize, ty: Option<ValType>) -> &mut Self
pub fn select_at(&mut self, position: usize, ty: Option<ValType>) -> &mut Self
Splice a new Select
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn unreachable(&mut self) -> &mut Self
pub fn unreachable(&mut self) -> &mut Self
Push a new Unreachable
instruction onto this builder’s block.
sourcepub fn unreachable_at(&mut self, position: usize) -> &mut Self
pub fn unreachable_at(&mut self, position: usize) -> &mut Self
Splice a new Unreachable
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn br(&mut self, block: InstrSeqId) -> &mut Self
pub fn br(&mut self, block: InstrSeqId) -> &mut Self
Push a new Br
instruction onto this builder’s block.
sourcepub fn br_at(&mut self, position: usize, block: InstrSeqId) -> &mut Self
pub fn br_at(&mut self, position: usize, block: InstrSeqId) -> &mut Self
Splice a new Br
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn br_if(&mut self, block: InstrSeqId) -> &mut Self
pub fn br_if(&mut self, block: InstrSeqId) -> &mut Self
Push a new BrIf
instruction onto this builder’s block.
sourcepub fn br_if_at(&mut self, position: usize, block: InstrSeqId) -> &mut Self
pub fn br_if_at(&mut self, position: usize, block: InstrSeqId) -> &mut Self
Splice a new BrIf
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn br_table(
&mut self,
blocks: Box<[InstrSeqId]>,
default: InstrSeqId
) -> &mut Self
pub fn br_table( &mut self, blocks: Box<[InstrSeqId]>, default: InstrSeqId ) -> &mut Self
Push a new BrTable
instruction onto this builder’s block.
sourcepub fn br_table_at(
&mut self,
position: usize,
blocks: Box<[InstrSeqId]>,
default: InstrSeqId
) -> &mut Self
pub fn br_table_at( &mut self, position: usize, blocks: Box<[InstrSeqId]>, default: InstrSeqId ) -> &mut Self
Splice a new BrTable
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn drop_at(&mut self, position: usize) -> &mut Self
pub fn drop_at(&mut self, position: usize) -> &mut Self
Splice a new Drop
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn return_(&mut self) -> &mut Self
pub fn return_(&mut self) -> &mut Self
Push a new Return
instruction onto this builder’s block.
sourcepub fn return_at(&mut self, position: usize) -> &mut Self
pub fn return_at(&mut self, position: usize) -> &mut Self
Splice a new Return
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn memory_size(&mut self, memory: MemoryId) -> &mut Self
pub fn memory_size(&mut self, memory: MemoryId) -> &mut Self
Push a new MemorySize
instruction onto this builder’s block.
sourcepub fn memory_size_at(&mut self, position: usize, memory: MemoryId) -> &mut Self
pub fn memory_size_at(&mut self, position: usize, memory: MemoryId) -> &mut Self
Splice a new MemorySize
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn memory_grow(&mut self, memory: MemoryId) -> &mut Self
pub fn memory_grow(&mut self, memory: MemoryId) -> &mut Self
Push a new MemoryGrow
instruction onto this builder’s block.
sourcepub fn memory_grow_at(&mut self, position: usize, memory: MemoryId) -> &mut Self
pub fn memory_grow_at(&mut self, position: usize, memory: MemoryId) -> &mut Self
Splice a new MemoryGrow
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn memory_init(&mut self, memory: MemoryId, data: DataId) -> &mut Self
pub fn memory_init(&mut self, memory: MemoryId, data: DataId) -> &mut Self
Push a new MemoryInit
instruction onto this builder’s block.
sourcepub fn memory_init_at(
&mut self,
position: usize,
memory: MemoryId,
data: DataId
) -> &mut Self
pub fn memory_init_at( &mut self, position: usize, memory: MemoryId, data: DataId ) -> &mut Self
Splice a new MemoryInit
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn data_drop(&mut self, data: DataId) -> &mut Self
pub fn data_drop(&mut self, data: DataId) -> &mut Self
Push a new DataDrop
instruction onto this builder’s block.
sourcepub fn data_drop_at(&mut self, position: usize, data: DataId) -> &mut Self
pub fn data_drop_at(&mut self, position: usize, data: DataId) -> &mut Self
Splice a new DataDrop
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn memory_copy(&mut self, src: MemoryId, dst: MemoryId) -> &mut Self
pub fn memory_copy(&mut self, src: MemoryId, dst: MemoryId) -> &mut Self
Push a new MemoryCopy
instruction onto this builder’s block.
sourcepub fn memory_copy_at(
&mut self,
position: usize,
src: MemoryId,
dst: MemoryId
) -> &mut Self
pub fn memory_copy_at( &mut self, position: usize, src: MemoryId, dst: MemoryId ) -> &mut Self
Splice a new MemoryCopy
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn memory_fill(&mut self, memory: MemoryId) -> &mut Self
pub fn memory_fill(&mut self, memory: MemoryId) -> &mut Self
Push a new MemoryFill
instruction onto this builder’s block.
sourcepub fn memory_fill_at(&mut self, position: usize, memory: MemoryId) -> &mut Self
pub fn memory_fill_at(&mut self, position: usize, memory: MemoryId) -> &mut Self
Splice a new MemoryFill
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn load(
&mut self,
memory: MemoryId,
kind: LoadKind,
arg: MemArg
) -> &mut Self
pub fn load( &mut self, memory: MemoryId, kind: LoadKind, arg: MemArg ) -> &mut Self
Push a new Load
instruction onto this builder’s block.
sourcepub fn load_at(
&mut self,
position: usize,
memory: MemoryId,
kind: LoadKind,
arg: MemArg
) -> &mut Self
pub fn load_at( &mut self, position: usize, memory: MemoryId, kind: LoadKind, arg: MemArg ) -> &mut Self
Splice a new Load
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn store(
&mut self,
memory: MemoryId,
kind: StoreKind,
arg: MemArg
) -> &mut Self
pub fn store( &mut self, memory: MemoryId, kind: StoreKind, arg: MemArg ) -> &mut Self
Push a new Store
instruction onto this builder’s block.
sourcepub fn store_at(
&mut self,
position: usize,
memory: MemoryId,
kind: StoreKind,
arg: MemArg
) -> &mut Self
pub fn store_at( &mut self, position: usize, memory: MemoryId, kind: StoreKind, arg: MemArg ) -> &mut Self
Splice a new Store
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn atomic_rmw(
&mut self,
memory: MemoryId,
op: AtomicOp,
width: AtomicWidth,
arg: MemArg
) -> &mut Self
pub fn atomic_rmw( &mut self, memory: MemoryId, op: AtomicOp, width: AtomicWidth, arg: MemArg ) -> &mut Self
Push a new AtomicRmw
instruction onto this builder’s block.
sourcepub fn atomic_rmw_at(
&mut self,
position: usize,
memory: MemoryId,
op: AtomicOp,
width: AtomicWidth,
arg: MemArg
) -> &mut Self
pub fn atomic_rmw_at( &mut self, position: usize, memory: MemoryId, op: AtomicOp, width: AtomicWidth, arg: MemArg ) -> &mut Self
Splice a new AtomicRmw
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn cmpxchg(
&mut self,
memory: MemoryId,
width: AtomicWidth,
arg: MemArg
) -> &mut Self
pub fn cmpxchg( &mut self, memory: MemoryId, width: AtomicWidth, arg: MemArg ) -> &mut Self
Push a new Cmpxchg
instruction onto this builder’s block.
sourcepub fn cmpxchg_at(
&mut self,
position: usize,
memory: MemoryId,
width: AtomicWidth,
arg: MemArg
) -> &mut Self
pub fn cmpxchg_at( &mut self, position: usize, memory: MemoryId, width: AtomicWidth, arg: MemArg ) -> &mut Self
Splice a new Cmpxchg
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn atomic_notify(&mut self, memory: MemoryId, arg: MemArg) -> &mut Self
pub fn atomic_notify(&mut self, memory: MemoryId, arg: MemArg) -> &mut Self
Push a new AtomicNotify
instruction onto this builder’s block.
sourcepub fn atomic_notify_at(
&mut self,
position: usize,
memory: MemoryId,
arg: MemArg
) -> &mut Self
pub fn atomic_notify_at( &mut self, position: usize, memory: MemoryId, arg: MemArg ) -> &mut Self
Splice a new AtomicNotify
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn atomic_wait(
&mut self,
memory: MemoryId,
arg: MemArg,
sixty_four: bool
) -> &mut Self
pub fn atomic_wait( &mut self, memory: MemoryId, arg: MemArg, sixty_four: bool ) -> &mut Self
Push a new AtomicWait
instruction onto this builder’s block.
sourcepub fn atomic_wait_at(
&mut self,
position: usize,
memory: MemoryId,
arg: MemArg,
sixty_four: bool
) -> &mut Self
pub fn atomic_wait_at( &mut self, position: usize, memory: MemoryId, arg: MemArg, sixty_four: bool ) -> &mut Self
Splice a new AtomicWait
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn atomic_fence(&mut self) -> &mut Self
pub fn atomic_fence(&mut self) -> &mut Self
Push a new AtomicFence
instruction onto this builder’s block.
sourcepub fn atomic_fence_at(&mut self, position: usize) -> &mut Self
pub fn atomic_fence_at(&mut self, position: usize) -> &mut Self
Splice a new AtomicFence
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn table_get(&mut self, table: TableId) -> &mut Self
pub fn table_get(&mut self, table: TableId) -> &mut Self
Push a new TableGet
instruction onto this builder’s block.
sourcepub fn table_get_at(&mut self, position: usize, table: TableId) -> &mut Self
pub fn table_get_at(&mut self, position: usize, table: TableId) -> &mut Self
Splice a new TableGet
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn table_set(&mut self, table: TableId) -> &mut Self
pub fn table_set(&mut self, table: TableId) -> &mut Self
Push a new TableSet
instruction onto this builder’s block.
sourcepub fn table_set_at(&mut self, position: usize, table: TableId) -> &mut Self
pub fn table_set_at(&mut self, position: usize, table: TableId) -> &mut Self
Splice a new TableSet
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn table_grow(&mut self, table: TableId) -> &mut Self
pub fn table_grow(&mut self, table: TableId) -> &mut Self
Push a new TableGrow
instruction onto this builder’s block.
sourcepub fn table_grow_at(&mut self, position: usize, table: TableId) -> &mut Self
pub fn table_grow_at(&mut self, position: usize, table: TableId) -> &mut Self
Splice a new TableGrow
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn table_size(&mut self, table: TableId) -> &mut Self
pub fn table_size(&mut self, table: TableId) -> &mut Self
Push a new TableSize
instruction onto this builder’s block.
sourcepub fn table_size_at(&mut self, position: usize, table: TableId) -> &mut Self
pub fn table_size_at(&mut self, position: usize, table: TableId) -> &mut Self
Splice a new TableSize
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn table_fill(&mut self, table: TableId) -> &mut Self
pub fn table_fill(&mut self, table: TableId) -> &mut Self
Push a new TableFill
instruction onto this builder’s block.
sourcepub fn table_fill_at(&mut self, position: usize, table: TableId) -> &mut Self
pub fn table_fill_at(&mut self, position: usize, table: TableId) -> &mut Self
Splice a new TableFill
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn ref_null(&mut self, ty: ValType) -> &mut Self
pub fn ref_null(&mut self, ty: ValType) -> &mut Self
Push a new RefNull
instruction onto this builder’s block.
sourcepub fn ref_null_at(&mut self, position: usize, ty: ValType) -> &mut Self
pub fn ref_null_at(&mut self, position: usize, ty: ValType) -> &mut Self
Splice a new RefNull
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn ref_is_null(&mut self) -> &mut Self
pub fn ref_is_null(&mut self) -> &mut Self
Push a new RefIsNull
instruction onto this builder’s block.
sourcepub fn ref_is_null_at(&mut self, position: usize) -> &mut Self
pub fn ref_is_null_at(&mut self, position: usize) -> &mut Self
Splice a new RefIsNull
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn ref_func(&mut self, func: FunctionId) -> &mut Self
pub fn ref_func(&mut self, func: FunctionId) -> &mut Self
Push a new RefFunc
instruction onto this builder’s block.
sourcepub fn ref_func_at(&mut self, position: usize, func: FunctionId) -> &mut Self
pub fn ref_func_at(&mut self, position: usize, func: FunctionId) -> &mut Self
Splice a new RefFunc
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn v128_bitselect(&mut self) -> &mut Self
pub fn v128_bitselect(&mut self) -> &mut Self
Push a new V128Bitselect
instruction onto this builder’s block.
sourcepub fn v128_bitselect_at(&mut self, position: usize) -> &mut Self
pub fn v128_bitselect_at(&mut self, position: usize) -> &mut Self
Splice a new V128Bitselect
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn i8x16_swizzle(&mut self) -> &mut Self
pub fn i8x16_swizzle(&mut self) -> &mut Self
Push a new I8x16Swizzle
instruction onto this builder’s block.
sourcepub fn i8x16_swizzle_at(&mut self, position: usize) -> &mut Self
pub fn i8x16_swizzle_at(&mut self, position: usize) -> &mut Self
Splice a new I8x16Swizzle
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn i8x16_shuffle(&mut self, indices: ShuffleIndices) -> &mut Self
pub fn i8x16_shuffle(&mut self, indices: ShuffleIndices) -> &mut Self
Push a new I8x16Shuffle
instruction onto this builder’s block.
sourcepub fn i8x16_shuffle_at(
&mut self,
position: usize,
indices: ShuffleIndices
) -> &mut Self
pub fn i8x16_shuffle_at( &mut self, position: usize, indices: ShuffleIndices ) -> &mut Self
Splice a new I8x16Shuffle
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn load_simd(
&mut self,
memory: MemoryId,
kind: LoadSimdKind,
arg: MemArg
) -> &mut Self
pub fn load_simd( &mut self, memory: MemoryId, kind: LoadSimdKind, arg: MemArg ) -> &mut Self
Push a new LoadSimd
instruction onto this builder’s block.
sourcepub fn load_simd_at(
&mut self,
position: usize,
memory: MemoryId,
kind: LoadSimdKind,
arg: MemArg
) -> &mut Self
pub fn load_simd_at( &mut self, position: usize, memory: MemoryId, kind: LoadSimdKind, arg: MemArg ) -> &mut Self
Splice a new LoadSimd
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn table_init(&mut self, table: TableId, elem: ElementId) -> &mut Self
pub fn table_init(&mut self, table: TableId, elem: ElementId) -> &mut Self
Push a new TableInit
instruction onto this builder’s block.
sourcepub fn table_init_at(
&mut self,
position: usize,
table: TableId,
elem: ElementId
) -> &mut Self
pub fn table_init_at( &mut self, position: usize, table: TableId, elem: ElementId ) -> &mut Self
Splice a new TableInit
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn elem_drop(&mut self, elem: ElementId) -> &mut Self
pub fn elem_drop(&mut self, elem: ElementId) -> &mut Self
Push a new ElemDrop
instruction onto this builder’s block.
sourcepub fn elem_drop_at(&mut self, position: usize, elem: ElementId) -> &mut Self
pub fn elem_drop_at(&mut self, position: usize, elem: ElementId) -> &mut Self
Splice a new ElemDrop
instruction into this builder’s block at the given index.
Panics
Panics if position > self.instrs.len()
.
sourcepub fn table_copy(&mut self, src: TableId, dst: TableId) -> &mut Self
pub fn table_copy(&mut self, src: TableId, dst: TableId) -> &mut Self
Push a new TableCopy
instruction onto this builder’s block.
Methods from Deref<Target = FunctionBuilder>§
sourcepub fn name(&mut self, function_name: String) -> &mut FunctionBuilder
pub fn name(&mut self, function_name: String) -> &mut FunctionBuilder
Set function name.
sourcepub fn func_body_id(&self) -> InstrSeqId
pub fn func_body_id(&self) -> InstrSeqId
Get the id of this function’s body’s instruction sequence.
sourcepub fn func_body(&mut self) -> InstrSeqBuilder<'_>
pub fn func_body(&mut self) -> InstrSeqBuilder<'_>
Get a InstrSeqBuilder
for building and mutating this function’s body.
sourcepub fn instr_seq(&mut self, id: InstrSeqId) -> InstrSeqBuilder<'_>
pub fn instr_seq(&mut self, id: InstrSeqId) -> InstrSeqBuilder<'_>
Continue building and mutating an existing instruction sequence.
Example
let mut module = walrus::Module::default();
let mut builder = walrus::FunctionBuilder::new(&mut module.types, &[], &[]);
let mut block = builder.dangling_instr_seq(None);
let id = block.id();
// Build up the block some.
block
.f64_const(1337.0)
.drop();
// Do some other stuff...
drop(block);
// Use `instr_seq` to get the builder for the block again, and build
// some more things onto it.
let mut block = builder.instr_seq(id);
block
.i32_const(42)
.drop();
sourcepub fn dangling_instr_seq(
&mut self,
ty: impl Into<InstrSeqType>
) -> InstrSeqBuilder<'_>
pub fn dangling_instr_seq( &mut self, ty: impl Into<InstrSeqType> ) -> InstrSeqBuilder<'_>
Create a new instruction sequence that is unreachable.
It is your responsibility to
-
make a
Instr::Block
,Instr::Loop
, orInstr::IfElse
that uses this instruction sequence, and -
append that
Instr
into a parent instruction sequence viaInstrSeqBuilder::instr
orInstrSeqBuilder::instr_at
or else this built up instruction sequence will never be used.
Example
use walrus::ir::*;
let mut module = walrus::Module::default();
let mut builder = walrus::FunctionBuilder::new(&mut module.types, &[], &[]);
// Create an empty, dangling instruction sequemce.
let mut seq = builder.dangling_instr_seq(None);
let seq_id = seq.id();
// Do stuff with the sequence...
drop(seq);
// Finally, make our instruction sequence reachable by adding an
// block/loop/if-else instruction that uses it to a reachable instruction
// sequence.
builder
.func_body()
.instr(Block { seq: seq_id });