[−][src]Struct walrus::InstrSeqBuilder
A builder returned by instruction sequence-construction methods to build up instructions within a block/loop/if-else over time.
Implementations
impl<'_> InstrSeqBuilder<'_>
[src]
pub fn id(&self) -> InstrSeqId
[src]
Returns the id of the instruction sequence that we're building.
pub fn instrs(&self) -> &[(Instr, InstrLocId)]
[src]
Get this instruction sequence's instructions.
pub fn instrs_mut(&mut self) -> &mut Vec<(Instr, InstrLocId)>
[src]
Get this instruction sequence's instructions mutably.
pub fn instr(&mut self, instr: impl Into<Instr>) -> &mut Self
[src]
Pushes a new instruction onto this builder's sequence.
pub fn instr_at(
&mut self,
position: usize,
instr: impl Into<Instr>
) -> &mut Self
[src]
&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()
.
pub fn i32_const(&mut self, val: i32) -> &mut Self
[src]
Creates an i32.const
instruction for the specified value.
pub fn i64_const(&mut self, val: i64) -> &mut Self
[src]
Creates an i64.const
instruction for the specified value.
pub fn f32_const(&mut self, val: f32) -> &mut Self
[src]
Creates an f32.const
instruction for the specified value
pub fn f64_const(&mut self, val: f64) -> &mut Self
[src]
Creates an f64.const
instruction for the specified value
pub fn block(
&mut self,
ty: impl Into<InstrSeqType>,
make_block: impl FnOnce(&mut InstrSeqBuilder)
) -> &mut Self
[src]
&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(); });
pub fn block_at(
&mut self,
position: usize,
ty: impl Into<InstrSeqType>,
make_block: impl FnOnce(&mut InstrSeqBuilder)
) -> &mut Self
[src]
&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(); });
pub fn loop_(
&mut self,
ty: impl Into<InstrSeqType>,
make_loop: impl FnOnce(&mut InstrSeqBuilder)
) -> &mut Self
[src]
&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(); });
pub fn loop_at(
&mut self,
position: usize,
ty: impl Into<InstrSeqType>,
make_loop: impl FnOnce(&mut InstrSeqBuilder)
) -> &mut Self
[src]
&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(); });
pub fn if_else(
&mut self,
ty: impl Into<InstrSeqType>,
consequent: impl FnOnce(&mut InstrSeqBuilder),
alternative: impl FnOnce(&mut InstrSeqBuilder)
) -> &mut Self
[src]
&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); }, );
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
[src]
&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); }, );
impl<'_> InstrSeqBuilder<'_>
[src]
pub fn call(&mut self, func: FunctionId) -> &mut Self
[src]
Push a new Call
instruction onto this builder's block.
pub fn call_at(&mut self, position: usize, func: FunctionId) -> &mut Self
[src]
Splice a new Call
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn call_indirect(&mut self, ty: TypeId, table: TableId) -> &mut Self
[src]
Push a new CallIndirect
instruction onto this builder's block.
pub fn call_indirect_at(
&mut self,
position: usize,
ty: TypeId,
table: TableId
) -> &mut Self
[src]
&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()
.
pub fn local_get(&mut self, local: LocalId) -> &mut Self
[src]
Push a new LocalGet
instruction onto this builder's block.
pub fn local_get_at(&mut self, position: usize, local: LocalId) -> &mut Self
[src]
Splice a new LocalGet
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn local_set(&mut self, local: LocalId) -> &mut Self
[src]
Push a new LocalSet
instruction onto this builder's block.
pub fn local_set_at(&mut self, position: usize, local: LocalId) -> &mut Self
[src]
Splice a new LocalSet
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn local_tee(&mut self, local: LocalId) -> &mut Self
[src]
Push a new LocalTee
instruction onto this builder's block.
pub fn local_tee_at(&mut self, position: usize, local: LocalId) -> &mut Self
[src]
Splice a new LocalTee
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn global_get(&mut self, global: GlobalId) -> &mut Self
[src]
Push a new GlobalGet
instruction onto this builder's block.
pub fn global_get_at(&mut self, position: usize, global: GlobalId) -> &mut Self
[src]
Splice a new GlobalGet
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn global_set(&mut self, global: GlobalId) -> &mut Self
[src]
Push a new GlobalSet
instruction onto this builder's block.
pub fn global_set_at(&mut self, position: usize, global: GlobalId) -> &mut Self
[src]
Splice a new GlobalSet
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn const_(&mut self, value: Value) -> &mut Self
[src]
Push a new Const
instruction onto this builder's block.
pub fn const_at(&mut self, position: usize, value: Value) -> &mut Self
[src]
Splice a new Const
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn binop(&mut self, op: BinaryOp) -> &mut Self
[src]
Push a new Binop
instruction onto this builder's block.
pub fn binop_at(&mut self, position: usize, op: BinaryOp) -> &mut Self
[src]
Splice a new Binop
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn unop(&mut self, op: UnaryOp) -> &mut Self
[src]
Push a new Unop
instruction onto this builder's block.
pub fn unop_at(&mut self, position: usize, op: UnaryOp) -> &mut Self
[src]
Splice a new Unop
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn select(&mut self, ty: Option<ValType>) -> &mut Self
[src]
Push a new Select
instruction onto this builder's block.
pub fn select_at(&mut self, position: usize, ty: Option<ValType>) -> &mut Self
[src]
Splice a new Select
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn unreachable(&mut self) -> &mut Self
[src]
Push a new Unreachable
instruction onto this builder's block.
pub fn unreachable_at(&mut self, position: usize) -> &mut Self
[src]
Splice a new Unreachable
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn br(&mut self, block: InstrSeqId) -> &mut Self
[src]
Push a new Br
instruction onto this builder's block.
pub fn br_at(&mut self, position: usize, block: InstrSeqId) -> &mut Self
[src]
Splice a new Br
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn br_if(&mut self, block: InstrSeqId) -> &mut Self
[src]
Push a new BrIf
instruction onto this builder's block.
pub fn br_if_at(&mut self, position: usize, block: InstrSeqId) -> &mut Self
[src]
Splice a new BrIf
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn br_table(
&mut self,
blocks: Box<[InstrSeqId]>,
default: InstrSeqId
) -> &mut Self
[src]
&mut self,
blocks: Box<[InstrSeqId]>,
default: InstrSeqId
) -> &mut Self
Push a new BrTable
instruction onto this builder's block.
pub fn br_table_at(
&mut self,
position: usize,
blocks: Box<[InstrSeqId]>,
default: InstrSeqId
) -> &mut Self
[src]
&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()
.
pub fn drop(&mut self) -> &mut Self
[src]
Push a new Drop
instruction onto this builder's block.
pub fn drop_at(&mut self, position: usize) -> &mut Self
[src]
Splice a new Drop
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn return_(&mut self) -> &mut Self
[src]
Push a new Return
instruction onto this builder's block.
pub fn return_at(&mut self, position: usize) -> &mut Self
[src]
Splice a new Return
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn memory_size(&mut self, memory: MemoryId) -> &mut Self
[src]
Push a new MemorySize
instruction onto this builder's block.
pub fn memory_size_at(&mut self, position: usize, memory: MemoryId) -> &mut Self
[src]
Splice a new MemorySize
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn memory_grow(&mut self, memory: MemoryId) -> &mut Self
[src]
Push a new MemoryGrow
instruction onto this builder's block.
pub fn memory_grow_at(&mut self, position: usize, memory: MemoryId) -> &mut Self
[src]
Splice a new MemoryGrow
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn memory_init(&mut self, memory: MemoryId, data: DataId) -> &mut Self
[src]
Push a new MemoryInit
instruction onto this builder's block.
pub fn memory_init_at(
&mut self,
position: usize,
memory: MemoryId,
data: DataId
) -> &mut Self
[src]
&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()
.
pub fn data_drop(&mut self, data: DataId) -> &mut Self
[src]
Push a new DataDrop
instruction onto this builder's block.
pub fn data_drop_at(&mut self, position: usize, data: DataId) -> &mut Self
[src]
Splice a new DataDrop
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn memory_copy(&mut self, src: MemoryId, dst: MemoryId) -> &mut Self
[src]
Push a new MemoryCopy
instruction onto this builder's block.
pub fn memory_copy_at(
&mut self,
position: usize,
src: MemoryId,
dst: MemoryId
) -> &mut Self
[src]
&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()
.
pub fn memory_fill(&mut self, memory: MemoryId) -> &mut Self
[src]
Push a new MemoryFill
instruction onto this builder's block.
pub fn memory_fill_at(&mut self, position: usize, memory: MemoryId) -> &mut Self
[src]
Splice a new MemoryFill
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn load(
&mut self,
memory: MemoryId,
kind: LoadKind,
arg: MemArg
) -> &mut Self
[src]
&mut self,
memory: MemoryId,
kind: LoadKind,
arg: MemArg
) -> &mut Self
Push a new Load
instruction onto this builder's block.
pub fn load_at(
&mut self,
position: usize,
memory: MemoryId,
kind: LoadKind,
arg: MemArg
) -> &mut Self
[src]
&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()
.
pub fn store(
&mut self,
memory: MemoryId,
kind: StoreKind,
arg: MemArg
) -> &mut Self
[src]
&mut self,
memory: MemoryId,
kind: StoreKind,
arg: MemArg
) -> &mut Self
Push a new Store
instruction onto this builder's block.
pub fn store_at(
&mut self,
position: usize,
memory: MemoryId,
kind: StoreKind,
arg: MemArg
) -> &mut Self
[src]
&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()
.
pub fn atomic_rmw(
&mut self,
memory: MemoryId,
op: AtomicOp,
width: AtomicWidth,
arg: MemArg
) -> &mut Self
[src]
&mut self,
memory: MemoryId,
op: AtomicOp,
width: AtomicWidth,
arg: MemArg
) -> &mut Self
Push a new AtomicRmw
instruction onto this builder's block.
pub fn atomic_rmw_at(
&mut self,
position: usize,
memory: MemoryId,
op: AtomicOp,
width: AtomicWidth,
arg: MemArg
) -> &mut Self
[src]
&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()
.
pub fn cmpxchg(
&mut self,
memory: MemoryId,
width: AtomicWidth,
arg: MemArg
) -> &mut Self
[src]
&mut self,
memory: MemoryId,
width: AtomicWidth,
arg: MemArg
) -> &mut Self
Push a new Cmpxchg
instruction onto this builder's block.
pub fn cmpxchg_at(
&mut self,
position: usize,
memory: MemoryId,
width: AtomicWidth,
arg: MemArg
) -> &mut Self
[src]
&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()
.
pub fn atomic_notify(&mut self, memory: MemoryId, arg: MemArg) -> &mut Self
[src]
Push a new AtomicNotify
instruction onto this builder's block.
pub fn atomic_notify_at(
&mut self,
position: usize,
memory: MemoryId,
arg: MemArg
) -> &mut Self
[src]
&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()
.
pub fn atomic_wait(
&mut self,
memory: MemoryId,
arg: MemArg,
sixty_four: bool
) -> &mut Self
[src]
&mut self,
memory: MemoryId,
arg: MemArg,
sixty_four: bool
) -> &mut Self
Push a new AtomicWait
instruction onto this builder's block.
pub fn atomic_wait_at(
&mut self,
position: usize,
memory: MemoryId,
arg: MemArg,
sixty_four: bool
) -> &mut Self
[src]
&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()
.
pub fn atomic_fence(&mut self) -> &mut Self
[src]
Push a new AtomicFence
instruction onto this builder's block.
pub fn atomic_fence_at(&mut self, position: usize) -> &mut Self
[src]
Splice a new AtomicFence
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn table_get(&mut self, table: TableId) -> &mut Self
[src]
Push a new TableGet
instruction onto this builder's block.
pub fn table_get_at(&mut self, position: usize, table: TableId) -> &mut Self
[src]
Splice a new TableGet
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn table_set(&mut self, table: TableId) -> &mut Self
[src]
Push a new TableSet
instruction onto this builder's block.
pub fn table_set_at(&mut self, position: usize, table: TableId) -> &mut Self
[src]
Splice a new TableSet
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn table_grow(&mut self, table: TableId) -> &mut Self
[src]
Push a new TableGrow
instruction onto this builder's block.
pub fn table_grow_at(&mut self, position: usize, table: TableId) -> &mut Self
[src]
Splice a new TableGrow
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn table_size(&mut self, table: TableId) -> &mut Self
[src]
Push a new TableSize
instruction onto this builder's block.
pub fn table_size_at(&mut self, position: usize, table: TableId) -> &mut Self
[src]
Splice a new TableSize
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn table_fill(&mut self, table: TableId) -> &mut Self
[src]
Push a new TableFill
instruction onto this builder's block.
pub fn table_fill_at(&mut self, position: usize, table: TableId) -> &mut Self
[src]
Splice a new TableFill
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn ref_null(&mut self, ty: ValType) -> &mut Self
[src]
Push a new RefNull
instruction onto this builder's block.
pub fn ref_null_at(&mut self, position: usize, ty: ValType) -> &mut Self
[src]
Splice a new RefNull
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn ref_is_null(&mut self) -> &mut Self
[src]
Push a new RefIsNull
instruction onto this builder's block.
pub fn ref_is_null_at(&mut self, position: usize) -> &mut Self
[src]
Splice a new RefIsNull
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn ref_func(&mut self, func: FunctionId) -> &mut Self
[src]
Push a new RefFunc
instruction onto this builder's block.
pub fn ref_func_at(&mut self, position: usize, func: FunctionId) -> &mut Self
[src]
Splice a new RefFunc
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn v128_bitselect(&mut self) -> &mut Self
[src]
Push a new V128Bitselect
instruction onto this builder's block.
pub fn v128_bitselect_at(&mut self, position: usize) -> &mut Self
[src]
Splice a new V128Bitselect
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn v128_swizzle(&mut self) -> &mut Self
[src]
Push a new V128Swizzle
instruction onto this builder's block.
pub fn v128_swizzle_at(&mut self, position: usize) -> &mut Self
[src]
Splice a new V128Swizzle
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn v128_shuffle(&mut self, indices: ShuffleIndices) -> &mut Self
[src]
Push a new V128Shuffle
instruction onto this builder's block.
pub fn v128_shuffle_at(
&mut self,
position: usize,
indices: ShuffleIndices
) -> &mut Self
[src]
&mut self,
position: usize,
indices: ShuffleIndices
) -> &mut Self
Splice a new V128Shuffle
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn load_simd(
&mut self,
memory: MemoryId,
kind: LoadSimdKind,
arg: MemArg
) -> &mut Self
[src]
&mut self,
memory: MemoryId,
kind: LoadSimdKind,
arg: MemArg
) -> &mut Self
Push a new LoadSimd
instruction onto this builder's block.
pub fn load_simd_at(
&mut self,
position: usize,
memory: MemoryId,
kind: LoadSimdKind,
arg: MemArg
) -> &mut Self
[src]
&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()
.
pub fn table_init(&mut self, table: TableId, elem: ElementId) -> &mut Self
[src]
Push a new TableInit
instruction onto this builder's block.
pub fn table_init_at(
&mut self,
position: usize,
table: TableId,
elem: ElementId
) -> &mut Self
[src]
&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()
.
pub fn elem_drop(&mut self, elem: ElementId) -> &mut Self
[src]
Push a new ElemDrop
instruction onto this builder's block.
pub fn elem_drop_at(&mut self, position: usize, elem: ElementId) -> &mut Self
[src]
Splice a new ElemDrop
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
pub fn table_copy(&mut self, src: TableId, dst: TableId) -> &mut Self
[src]
Push a new TableCopy
instruction onto this builder's block.
pub fn table_copy_at(
&mut self,
position: usize,
src: TableId,
dst: TableId
) -> &mut Self
[src]
&mut self,
position: usize,
src: TableId,
dst: TableId
) -> &mut Self
Splice a new TableCopy
instruction into this builder's block at the given index.
Panics
Panics if position > self.instrs.len()
.
Methods from Deref<Target = FunctionBuilder>
pub fn name(&mut self, function_name: String) -> &mut FunctionBuilder
[src]
Set function name.
pub fn func_body_id(&self) -> InstrSeqId
[src]
Get the id of this function's body's instruction sequence.
pub fn func_body(&mut self) -> InstrSeqBuilder
[src]
Get a InstrSeqBuilder
for building and mutating this function's body.
pub fn instr_seq(&mut self, id: InstrSeqId) -> InstrSeqBuilder
[src]
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();
pub fn dangling_instr_seq(
&mut self,
ty: impl Into<InstrSeqType>
) -> InstrSeqBuilder
[src]
&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 });
Trait Implementations
impl<'a> Debug for InstrSeqBuilder<'a>
[src]
impl<'_> Deref for InstrSeqBuilder<'_>
[src]
type Target = FunctionBuilder
The resulting type after dereferencing.
fn deref(&self) -> &FunctionBuilder
[src]
impl<'_> DerefMut for InstrSeqBuilder<'_>
[src]
fn deref_mut(&mut self) -> &mut FunctionBuilder
[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for InstrSeqBuilder<'a>
impl<'a> Send for InstrSeqBuilder<'a>
impl<'a> Sync for InstrSeqBuilder<'a>
impl<'a> Unpin for InstrSeqBuilder<'a>
impl<'a> !UnwindSafe for InstrSeqBuilder<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,