pub struct CodeBuilder { /* private fields */ }
Implementations§
Source§impl CodeBuilder
impl CodeBuilder
pub fn new() -> Self
pub fn build(self) -> Code
pub fn unreachable(self) -> Self
pub fn nop(self) -> Self
pub fn block(self, sig: BlockType) -> Self
pub fn loop_(self, sig: BlockType) -> Self
pub fn if_(self, sig: BlockType) -> Self
pub fn else_(self) -> Self
pub fn end(self) -> Self
pub fn br(self, depth: u32) -> Self
pub fn br_if(self, depth: u32) -> Self
pub fn br_table(self, table: Vec<u32>, default: u32) -> Self
Sourcepub fn return_(self) -> Self
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
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}
Sourcepub fn call(self, index: FunctionSpaceIndex) -> Self
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}
pub fn call_indirect(self, index: TypeIndex, reserved: bool) -> Self
pub fn drop(self) -> Self
pub fn select(self) -> Self
Sourcepub fn get_local(self, idx: LocalIndex) -> Self
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
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}
pub fn set_local(self, idx: LocalIndex) -> Self
pub fn tee_local(self, idx: LocalIndex) -> Self
pub fn get_global(self, idx: GlobalIndex) -> Self
pub fn set_global(self, idx: GlobalIndex) -> Self
pub fn i32_load(self, offset: u32) -> Self
pub fn i64_load(self, offset: u32) -> Self
pub fn f32_load(self, offset: u32) -> Self
pub fn f64_load(self, offset: u32) -> Self
pub fn i32_load8_s(self, offset: u32) -> Self
pub fn i32_load8_u(self, offset: u32) -> Self
pub fn i32_load16_s(self, offset: u32) -> Self
pub fn i32_load16_u(self, offset: u32) -> Self
pub fn i64_load8_s(self, offset: u32) -> Self
pub fn i64_load8_u(self, offset: u32) -> Self
pub fn i64_load16_s(self, offset: u32) -> Self
pub fn i64_load16_u(self, offset: u32) -> Self
pub fn i64_load32_s(self, offset: u32) -> Self
pub fn i64_load32_u(self, offset: u32) -> Self
pub fn i32_store(self, offset: u32) -> Self
pub fn i64_store(self, offset: u32) -> Self
pub fn f32_store(self, offset: u32) -> Self
pub fn f64_store(self, offset: u32) -> Self
pub fn i32_store8(self, offset: u32) -> Self
pub fn i32_store16(self, offset: u32) -> Self
pub fn i64_store8(self, offset: u32) -> Self
pub fn i64_store16(self, offset: u32) -> Self
pub fn i64_store32(self, offset: u32) -> Self
pub fn current_memory(self, reserved: bool) -> Self
pub fn grow_memory(self, reserved: bool) -> Self
Sourcepub fn constant<C>(self, c: C) -> Self
pub fn constant<C>(self, c: C) -> Self
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}
pub fn i32_eqz(self) -> Self
pub fn i32_eq(self) -> Self
pub fn i32_ne(self) -> Self
pub fn i32_lt_s(self) -> Self
pub fn i32_lt_u(self) -> Self
pub fn i32_gt_s(self) -> Self
pub fn i32_gt_u(self) -> Self
pub fn i32_le_s(self) -> Self
pub fn i32_le_u(self) -> Self
pub fn i32_ge_s(self) -> Self
pub fn i32_ge_u(self) -> Self
pub fn i64_eqz(self) -> Self
pub fn i64_eq(self) -> Self
pub fn i64_ne(self) -> Self
pub fn i64_lt_s(self) -> Self
pub fn i64_lt_u(self) -> Self
pub fn i64_gt_s(self) -> Self
pub fn i64_gt_u(self) -> Self
pub fn i64_le_s(self) -> Self
pub fn i64_le_u(self) -> Self
pub fn i64_ge_s(self) -> Self
pub fn i64_ge_u(self) -> Self
pub fn f32_eq(self) -> Self
pub fn f32_ne(self) -> Self
pub fn f32_lt(self) -> Self
pub fn f32_gt(self) -> Self
pub fn f32_le(self) -> Self
pub fn f32_ge(self) -> Self
pub fn f64_eq(self) -> Self
pub fn f64_ne(self) -> Self
pub fn f64_lt(self) -> Self
pub fn f64_gt(self) -> Self
pub fn f64_le(self) -> Self
pub fn f64_ge(self) -> Self
pub fn i32_clz(self) -> Self
pub fn i32_ctz(self) -> Self
pub fn i32_popcnt(self) -> Self
Sourcepub fn i32_add(self) -> Self
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
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}
Sourcepub fn i32_sub(self) -> Self
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}
pub fn i32_mul(self) -> Self
pub fn i32_div_s(self) -> Self
pub fn i32_div_u(self) -> Self
pub fn i32_rem_s(self) -> Self
pub fn i32_rem_u(self) -> Self
pub fn i32_and(self) -> Self
pub fn i32_or(self) -> Self
pub fn i32_xor(self) -> Self
pub fn i32_shl(self) -> Self
pub fn i32_shr_s(self) -> Self
pub fn i32_shr_u(self) -> Self
pub fn i32_rotl(self) -> Self
pub fn i32_rotr(self) -> Self
pub fn i64_clz(self) -> Self
pub fn i64_ctz(self) -> Self
pub fn i64_popcnt(self) -> Self
pub fn i64_add(self) -> Self
pub fn i64_sub(self) -> Self
pub fn i64_mul(self) -> Self
pub fn i64_div_s(self) -> Self
pub fn i64_div_u(self) -> Self
pub fn i64_rem_s(self) -> Self
pub fn i64_rem_u(self) -> Self
pub fn i64_and(self) -> Self
pub fn i64_or(self) -> Self
pub fn i64_xor(self) -> Self
pub fn i64_shl(self) -> Self
pub fn i64_shr_s(self) -> Self
pub fn i64_shr_u(self) -> Self
pub fn i64_rotl(self) -> Self
pub fn i64_rotr(self) -> Self
pub fn f32_abs(self) -> Self
pub fn f32_neg(self) -> Self
pub fn f32_ceil(self) -> Self
pub fn f32_floor(self) -> Self
pub fn f32_trunc(self) -> Self
pub fn f32_nearest(self) -> Self
pub fn f32_sqrt(self) -> Self
pub fn f32_add(self) -> Self
pub fn f32_sub(self) -> Self
pub fn f32_mul(self) -> Self
pub fn f32_div(self) -> Self
pub fn f32_min(self) -> Self
pub fn f32_max(self) -> Self
pub fn f32_copysign(self) -> Self
pub fn f64_abs(self) -> Self
pub fn f64_neg(self) -> Self
pub fn f64_ceil(self) -> Self
pub fn f64_floor(self) -> Self
pub fn f64_trunc(self) -> Self
pub fn f64_nearest(self) -> Self
pub fn f64_sqrt(self) -> Self
pub fn f64_add(self) -> Self
pub fn f64_sub(self) -> Self
pub fn f64_mul(self) -> Self
pub fn f64_div(self) -> Self
pub fn f64_min(self) -> Self
pub fn f64_max(self) -> Self
pub fn f64_copysign(self) -> Self
pub fn i32_wrap_i64(self) -> Self
pub fn i32_trunc_s_f32(self) -> Self
pub fn i32_trunc_u_f32(self) -> Self
pub fn i32_trunc_s_f64(self) -> Self
pub fn i32_trunc_u_f64(self) -> Self
pub fn i64_extend_s_i32(self) -> Self
pub fn i64_extend_u_i32(self) -> Self
pub fn i64_trunc_s_f32(self) -> Self
pub fn i64_trunc_u_f32(self) -> Self
pub fn i64_trunc_s_f64(self) -> Self
pub fn i64_trunc_u_f64(self) -> Self
pub fn f32_convert_s_i32(self) -> Self
pub fn f32_convert_u_i32(self) -> Self
pub fn f32_convert_s_i64(self) -> Self
pub fn f32_convert_u_i64(self) -> Self
pub fn f32_demote_f64(self) -> Self
pub fn f64_convert_s_i32(self) -> Self
pub fn f64_convert_u_i32(self) -> Self
pub fn f64_convert_s_i64(self) -> Self
pub fn f64_convert_u_i64(self) -> Self
pub fn f64_promote_f32(self) -> Self
pub fn i32_reinterpret_f32(self) -> Self
pub fn i64_reinterpret_f64(self) -> Self
pub fn f32_reinterpret_i32(self) -> Self
pub fn f64_reinterpret_i64(self) -> Self
Auto Trait Implementations§
impl Freeze for CodeBuilder
impl RefUnwindSafe for CodeBuilder
impl Send for CodeBuilder
impl Sync for CodeBuilder
impl Unpin for CodeBuilder
impl UnwindSafe for CodeBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more