[−][src]Struct walrus::FunctionBuilder
Build instances of LocalFunction
.
Example
-
For micro-examples, see the docs for various
FunctionBuilder
andInstrSeqBuilder
methods. -
For a bit more realistic example, see
examples/build-wasm-from-scratch.rs
.
Methods
impl FunctionBuilder
[src]
pub fn new(
types: &mut ModuleTypes,
params: &[ValType],
results: &[ValType]
) -> FunctionBuilder
[src]
types: &mut ModuleTypes,
params: &[ValType],
results: &[ValType]
) -> FunctionBuilder
Creates a new, empty function builder.
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(Box::new([]), Box::new([])); 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,
params: Box<[ValType]>,
results: Box<[ValType]>
) -> InstrSeqBuilder
[src]
&mut self,
params: Box<[ValType]>,
results: Box<[ValType]>
) -> 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(Box::new([]), Box::new([])); 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 });
pub fn finish(
self,
args: Vec<LocalId>,
funcs: &mut ModuleFunctions
) -> FunctionId
[src]
self,
args: Vec<LocalId>,
funcs: &mut ModuleFunctions
) -> FunctionId
Finishes this builder, wrapping it all up and inserting it into the
specified Module
.
Example
let mut module = walrus::Module::default(); let mut builder = walrus::FunctionBuilder::new(&mut module.types, &[], &[]); builder .func_body() .i32_const(1234) .drop(); let function_id = builder.finish(vec![], &mut module.funcs);
Trait Implementations
Auto Trait Implementations
impl Sync for FunctionBuilder
impl Send for FunctionBuilder
impl Unpin for FunctionBuilder
impl RefUnwindSafe for FunctionBuilder
impl UnwindSafe for FunctionBuilder
Blanket Implementations
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,