Struct CodeBuilder

Source
pub struct CodeBuilder { /* private fields */ }

Implementations§

Source§

impl CodeBuilder

Source

pub fn new() -> Self

Source

pub fn build(self) -> Code

Source

pub fn unreachable(self) -> Self

Source

pub fn nop(self) -> Self

Source

pub fn block(self, sig: BlockType) -> Self

Source

pub fn loop_(self, sig: BlockType) -> Self

Source

pub fn if_(self, sig: BlockType) -> Self

Source

pub fn else_(self) -> Self

Source

pub fn end(self) -> Self

Source

pub fn br(self, depth: u32) -> Self

Source

pub fn br_if(self, depth: u32) -> Self

Source

pub fn br_table(self, table: Vec<u32>, default: u32) -> Self

Source

pub fn return_(self) -> Self

Examples found in repository?
examples/simple_add.rs (line 18)
10fn main() {
11    let out_file = env::args().nth(1).expect("argument missing: output file");
12
13    let mut md = ModuleBuilder::new();
14    let f = FunctionBuilder::new(funtype!((i32, i32) -> i32))
15        .code(|cb, params| {
16            let a = params[0];
17            let b = params[1];
18            cb.get_local(a).get_local(b).i32_add().return_()
19        })
20        .build();
21    md.new_function(f);
22
23    let module = md.build();
24    let mut code = Vec::new();
25    module.dump(&mut code);
26    let mut out = File::create(out_file).unwrap();
27    out.write(&code).unwrap();
28}
More examples
Hide additional examples
examples/fibonacci.rs (line 27)
9fn main() {
10    let out_file = env::args().nth(1).expect("argument missing: output file");
11
12    let mut md = ModuleBuilder::new();
13    // function to create must be the 0th function of the module...
14    let fib = FunctionIndex(0).into();
15    let f = FunctionBuilder::new(funtype!((i32) -> i32))
16        .code(|cb, params| {
17            let n = params[0];
18            cb.get_local(n)
19                .constant(1i32)
20                .i32_sub()
21                .call(fib)
22                .get_local(n)
23                .constant(2i32)
24                .i32_sub()
25                .call(fib)
26                .i32_add()
27                .return_()
28        })
29        .build();
30    md.new_function(f);
31
32    let module = md.build();
33    let mut code = Vec::new();
34    module.dump(&mut code);
35    let mut out = File::create(out_file).unwrap();
36    out.write(&code).unwrap();
37}
Source

pub fn call(self, index: FunctionSpaceIndex) -> Self

Examples found in repository?
examples/fibonacci.rs (line 21)
9fn main() {
10    let out_file = env::args().nth(1).expect("argument missing: output file");
11
12    let mut md = ModuleBuilder::new();
13    // function to create must be the 0th function of the module...
14    let fib = FunctionIndex(0).into();
15    let f = FunctionBuilder::new(funtype!((i32) -> i32))
16        .code(|cb, params| {
17            let n = params[0];
18            cb.get_local(n)
19                .constant(1i32)
20                .i32_sub()
21                .call(fib)
22                .get_local(n)
23                .constant(2i32)
24                .i32_sub()
25                .call(fib)
26                .i32_add()
27                .return_()
28        })
29        .build();
30    md.new_function(f);
31
32    let module = md.build();
33    let mut code = Vec::new();
34    module.dump(&mut code);
35    let mut out = File::create(out_file).unwrap();
36    out.write(&code).unwrap();
37}
Source

pub fn call_indirect(self, index: TypeIndex, reserved: bool) -> Self

Source

pub fn drop(self) -> Self

Source

pub fn select(self) -> Self

Source

pub fn get_local(self, idx: LocalIndex) -> Self

Examples found in repository?
examples/simple_add.rs (line 18)
10fn main() {
11    let out_file = env::args().nth(1).expect("argument missing: output file");
12
13    let mut md = ModuleBuilder::new();
14    let f = FunctionBuilder::new(funtype!((i32, i32) -> i32))
15        .code(|cb, params| {
16            let a = params[0];
17            let b = params[1];
18            cb.get_local(a).get_local(b).i32_add().return_()
19        })
20        .build();
21    md.new_function(f);
22
23    let module = md.build();
24    let mut code = Vec::new();
25    module.dump(&mut code);
26    let mut out = File::create(out_file).unwrap();
27    out.write(&code).unwrap();
28}
More examples
Hide additional examples
examples/fibonacci.rs (line 18)
9fn main() {
10    let out_file = env::args().nth(1).expect("argument missing: output file");
11
12    let mut md = ModuleBuilder::new();
13    // function to create must be the 0th function of the module...
14    let fib = FunctionIndex(0).into();
15    let f = FunctionBuilder::new(funtype!((i32) -> i32))
16        .code(|cb, params| {
17            let n = params[0];
18            cb.get_local(n)
19                .constant(1i32)
20                .i32_sub()
21                .call(fib)
22                .get_local(n)
23                .constant(2i32)
24                .i32_sub()
25                .call(fib)
26                .i32_add()
27                .return_()
28        })
29        .build();
30    md.new_function(f);
31
32    let module = md.build();
33    let mut code = Vec::new();
34    module.dump(&mut code);
35    let mut out = File::create(out_file).unwrap();
36    out.write(&code).unwrap();
37}
Source

pub fn set_local(self, idx: LocalIndex) -> Self

Source

pub fn tee_local(self, idx: LocalIndex) -> Self

Source

pub fn get_global(self, idx: GlobalIndex) -> Self

Source

pub fn set_global(self, idx: GlobalIndex) -> Self

Source

pub fn i32_load(self, offset: u32) -> Self

Source

pub fn i64_load(self, offset: u32) -> Self

Source

pub fn f32_load(self, offset: u32) -> Self

Source

pub fn f64_load(self, offset: u32) -> Self

Source

pub fn i32_load8_s(self, offset: u32) -> Self

Source

pub fn i32_load8_u(self, offset: u32) -> Self

Source

pub fn i32_load16_s(self, offset: u32) -> Self

Source

pub fn i32_load16_u(self, offset: u32) -> Self

Source

pub fn i64_load8_s(self, offset: u32) -> Self

Source

pub fn i64_load8_u(self, offset: u32) -> Self

Source

pub fn i64_load16_s(self, offset: u32) -> Self

Source

pub fn i64_load16_u(self, offset: u32) -> Self

Source

pub fn i64_load32_s(self, offset: u32) -> Self

Source

pub fn i64_load32_u(self, offset: u32) -> Self

Source

pub fn i32_store(self, offset: u32) -> Self

Source

pub fn i64_store(self, offset: u32) -> Self

Source

pub fn f32_store(self, offset: u32) -> Self

Source

pub fn f64_store(self, offset: u32) -> Self

Source

pub fn i32_store8(self, offset: u32) -> Self

Source

pub fn i32_store16(self, offset: u32) -> Self

Source

pub fn i64_store8(self, offset: u32) -> Self

Source

pub fn i64_store16(self, offset: u32) -> Self

Source

pub fn i64_store32(self, offset: u32) -> Self

Source

pub fn current_memory(self, reserved: bool) -> Self

Source

pub fn grow_memory(self, reserved: bool) -> Self

Source

pub fn constant<C>(self, c: C) -> Self
where Op: From<C>,

Examples found in repository?
examples/fibonacci.rs (line 19)
9fn main() {
10    let out_file = env::args().nth(1).expect("argument missing: output file");
11
12    let mut md = ModuleBuilder::new();
13    // function to create must be the 0th function of the module...
14    let fib = FunctionIndex(0).into();
15    let f = FunctionBuilder::new(funtype!((i32) -> i32))
16        .code(|cb, params| {
17            let n = params[0];
18            cb.get_local(n)
19                .constant(1i32)
20                .i32_sub()
21                .call(fib)
22                .get_local(n)
23                .constant(2i32)
24                .i32_sub()
25                .call(fib)
26                .i32_add()
27                .return_()
28        })
29        .build();
30    md.new_function(f);
31
32    let module = md.build();
33    let mut code = Vec::new();
34    module.dump(&mut code);
35    let mut out = File::create(out_file).unwrap();
36    out.write(&code).unwrap();
37}
Source

pub fn i32_eqz(self) -> Self

Source

pub fn i32_eq(self) -> Self

Source

pub fn i32_ne(self) -> Self

Source

pub fn i32_lt_s(self) -> Self

Source

pub fn i32_lt_u(self) -> Self

Source

pub fn i32_gt_s(self) -> Self

Source

pub fn i32_gt_u(self) -> Self

Source

pub fn i32_le_s(self) -> Self

Source

pub fn i32_le_u(self) -> Self

Source

pub fn i32_ge_s(self) -> Self

Source

pub fn i32_ge_u(self) -> Self

Source

pub fn i64_eqz(self) -> Self

Source

pub fn i64_eq(self) -> Self

Source

pub fn i64_ne(self) -> Self

Source

pub fn i64_lt_s(self) -> Self

Source

pub fn i64_lt_u(self) -> Self

Source

pub fn i64_gt_s(self) -> Self

Source

pub fn i64_gt_u(self) -> Self

Source

pub fn i64_le_s(self) -> Self

Source

pub fn i64_le_u(self) -> Self

Source

pub fn i64_ge_s(self) -> Self

Source

pub fn i64_ge_u(self) -> Self

Source

pub fn f32_eq(self) -> Self

Source

pub fn f32_ne(self) -> Self

Source

pub fn f32_lt(self) -> Self

Source

pub fn f32_gt(self) -> Self

Source

pub fn f32_le(self) -> Self

Source

pub fn f32_ge(self) -> Self

Source

pub fn f64_eq(self) -> Self

Source

pub fn f64_ne(self) -> Self

Source

pub fn f64_lt(self) -> Self

Source

pub fn f64_gt(self) -> Self

Source

pub fn f64_le(self) -> Self

Source

pub fn f64_ge(self) -> Self

Source

pub fn i32_clz(self) -> Self

Source

pub fn i32_ctz(self) -> Self

Source

pub fn i32_popcnt(self) -> Self

Source

pub fn i32_add(self) -> Self

Examples found in repository?
examples/simple_add.rs (line 18)
10fn main() {
11    let out_file = env::args().nth(1).expect("argument missing: output file");
12
13    let mut md = ModuleBuilder::new();
14    let f = FunctionBuilder::new(funtype!((i32, i32) -> i32))
15        .code(|cb, params| {
16            let a = params[0];
17            let b = params[1];
18            cb.get_local(a).get_local(b).i32_add().return_()
19        })
20        .build();
21    md.new_function(f);
22
23    let module = md.build();
24    let mut code = Vec::new();
25    module.dump(&mut code);
26    let mut out = File::create(out_file).unwrap();
27    out.write(&code).unwrap();
28}
More examples
Hide additional examples
examples/fibonacci.rs (line 26)
9fn main() {
10    let out_file = env::args().nth(1).expect("argument missing: output file");
11
12    let mut md = ModuleBuilder::new();
13    // function to create must be the 0th function of the module...
14    let fib = FunctionIndex(0).into();
15    let f = FunctionBuilder::new(funtype!((i32) -> i32))
16        .code(|cb, params| {
17            let n = params[0];
18            cb.get_local(n)
19                .constant(1i32)
20                .i32_sub()
21                .call(fib)
22                .get_local(n)
23                .constant(2i32)
24                .i32_sub()
25                .call(fib)
26                .i32_add()
27                .return_()
28        })
29        .build();
30    md.new_function(f);
31
32    let module = md.build();
33    let mut code = Vec::new();
34    module.dump(&mut code);
35    let mut out = File::create(out_file).unwrap();
36    out.write(&code).unwrap();
37}
Source

pub fn i32_sub(self) -> Self

Examples found in repository?
examples/fibonacci.rs (line 20)
9fn main() {
10    let out_file = env::args().nth(1).expect("argument missing: output file");
11
12    let mut md = ModuleBuilder::new();
13    // function to create must be the 0th function of the module...
14    let fib = FunctionIndex(0).into();
15    let f = FunctionBuilder::new(funtype!((i32) -> i32))
16        .code(|cb, params| {
17            let n = params[0];
18            cb.get_local(n)
19                .constant(1i32)
20                .i32_sub()
21                .call(fib)
22                .get_local(n)
23                .constant(2i32)
24                .i32_sub()
25                .call(fib)
26                .i32_add()
27                .return_()
28        })
29        .build();
30    md.new_function(f);
31
32    let module = md.build();
33    let mut code = Vec::new();
34    module.dump(&mut code);
35    let mut out = File::create(out_file).unwrap();
36    out.write(&code).unwrap();
37}
Source

pub fn i32_mul(self) -> Self

Source

pub fn i32_div_s(self) -> Self

Source

pub fn i32_div_u(self) -> Self

Source

pub fn i32_rem_s(self) -> Self

Source

pub fn i32_rem_u(self) -> Self

Source

pub fn i32_and(self) -> Self

Source

pub fn i32_or(self) -> Self

Source

pub fn i32_xor(self) -> Self

Source

pub fn i32_shl(self) -> Self

Source

pub fn i32_shr_s(self) -> Self

Source

pub fn i32_shr_u(self) -> Self

Source

pub fn i32_rotl(self) -> Self

Source

pub fn i32_rotr(self) -> Self

Source

pub fn i64_clz(self) -> Self

Source

pub fn i64_ctz(self) -> Self

Source

pub fn i64_popcnt(self) -> Self

Source

pub fn i64_add(self) -> Self

Source

pub fn i64_sub(self) -> Self

Source

pub fn i64_mul(self) -> Self

Source

pub fn i64_div_s(self) -> Self

Source

pub fn i64_div_u(self) -> Self

Source

pub fn i64_rem_s(self) -> Self

Source

pub fn i64_rem_u(self) -> Self

Source

pub fn i64_and(self) -> Self

Source

pub fn i64_or(self) -> Self

Source

pub fn i64_xor(self) -> Self

Source

pub fn i64_shl(self) -> Self

Source

pub fn i64_shr_s(self) -> Self

Source

pub fn i64_shr_u(self) -> Self

Source

pub fn i64_rotl(self) -> Self

Source

pub fn i64_rotr(self) -> Self

Source

pub fn f32_abs(self) -> Self

Source

pub fn f32_neg(self) -> Self

Source

pub fn f32_ceil(self) -> Self

Source

pub fn f32_floor(self) -> Self

Source

pub fn f32_trunc(self) -> Self

Source

pub fn f32_nearest(self) -> Self

Source

pub fn f32_sqrt(self) -> Self

Source

pub fn f32_add(self) -> Self

Source

pub fn f32_sub(self) -> Self

Source

pub fn f32_mul(self) -> Self

Source

pub fn f32_div(self) -> Self

Source

pub fn f32_min(self) -> Self

Source

pub fn f32_max(self) -> Self

Source

pub fn f32_copysign(self) -> Self

Source

pub fn f64_abs(self) -> Self

Source

pub fn f64_neg(self) -> Self

Source

pub fn f64_ceil(self) -> Self

Source

pub fn f64_floor(self) -> Self

Source

pub fn f64_trunc(self) -> Self

Source

pub fn f64_nearest(self) -> Self

Source

pub fn f64_sqrt(self) -> Self

Source

pub fn f64_add(self) -> Self

Source

pub fn f64_sub(self) -> Self

Source

pub fn f64_mul(self) -> Self

Source

pub fn f64_div(self) -> Self

Source

pub fn f64_min(self) -> Self

Source

pub fn f64_max(self) -> Self

Source

pub fn f64_copysign(self) -> Self

Source

pub fn i32_wrap_i64(self) -> Self

Source

pub fn i32_trunc_s_f32(self) -> Self

Source

pub fn i32_trunc_u_f32(self) -> Self

Source

pub fn i32_trunc_s_f64(self) -> Self

Source

pub fn i32_trunc_u_f64(self) -> Self

Source

pub fn i64_extend_s_i32(self) -> Self

Source

pub fn i64_extend_u_i32(self) -> Self

Source

pub fn i64_trunc_s_f32(self) -> Self

Source

pub fn i64_trunc_u_f32(self) -> Self

Source

pub fn i64_trunc_s_f64(self) -> Self

Source

pub fn i64_trunc_u_f64(self) -> Self

Source

pub fn f32_convert_s_i32(self) -> Self

Source

pub fn f32_convert_u_i32(self) -> Self

Source

pub fn f32_convert_s_i64(self) -> Self

Source

pub fn f32_convert_u_i64(self) -> Self

Source

pub fn f32_demote_f64(self) -> Self

Source

pub fn f64_convert_s_i32(self) -> Self

Source

pub fn f64_convert_u_i32(self) -> Self

Source

pub fn f64_convert_s_i64(self) -> Self

Source

pub fn f64_convert_u_i64(self) -> Self

Source

pub fn f64_promote_f32(self) -> Self

Source

pub fn i32_reinterpret_f32(self) -> Self

Source

pub fn i64_reinterpret_f64(self) -> Self

Source

pub fn f32_reinterpret_i32(self) -> Self

Source

pub fn f64_reinterpret_i64(self) -> Self

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.