pub struct ModuleBuilder(/* private fields */);
Implementations§
Source§impl ModuleBuilder
impl ModuleBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/simple_add.rs (line 13)
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 12)
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 function_index_of( &self, i: ImportIndex, ) -> Result<FunctionSpaceIndex, ImportIndex>
Sourcepub fn build(self) -> Module
pub fn build(self) -> Module
Examples found in repository?
examples/simple_add.rs (line 23)
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 32)
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 add_type(&mut self, ty: FuncType) -> TypeIndex
pub fn add_import(&mut self, ty: ImportEntry) -> ImportIndex
pub fn add_table(&mut self, ty: TableType) -> TableIndex
pub fn add_memory(&mut self, ty: MemoryType) -> MemoryIndex
pub fn add_global(&mut self, ty: GlobalVariable) -> GlobalIndex
pub fn add_export(&mut self, ty: ExportEntry) -> ExportIndex
pub fn start(&mut self, index: FunctionIndex)
pub fn add_element(&mut self, ty: ElemSegment) -> ElementIndex
pub fn add_data(&mut self, ty: DataSegment) -> DataIndex
Sourcepub fn new_function(
&mut self,
(t, body): (FuncType, FunctionBody),
) -> FunctionIndex
pub fn new_function( &mut self, (t, body): (FuncType, FunctionBody), ) -> FunctionIndex
Examples found in repository?
examples/simple_add.rs (line 21)
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 30)
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 new_data( &mut self, idx: MemoryIndex, offset: Code, data: Vec<u8>, ) -> DataIndex
pub fn new_global(&mut self, ty: GlobalType, init: Code) -> GlobalIndex
Trait Implementations§
Source§impl Export<FunctionIndex> for ModuleBuilder
impl Export<FunctionIndex> for ModuleBuilder
fn export<S: Into<String>>( &mut self, name: S, index: FunctionIndex, ) -> ExportIndex
Source§impl Export<GlobalIndex> for ModuleBuilder
impl Export<GlobalIndex> for ModuleBuilder
fn export<S: Into<String>>( &mut self, name: S, index: GlobalIndex, ) -> ExportIndex
Source§impl Export<MemoryIndex> for ModuleBuilder
impl Export<MemoryIndex> for ModuleBuilder
fn export<S: Into<String>>( &mut self, name: S, index: MemoryIndex, ) -> ExportIndex
Source§impl Export<TableIndex> for ModuleBuilder
impl Export<TableIndex> for ModuleBuilder
fn export<S: Into<String>>(&mut self, name: S, index: TableIndex) -> ExportIndex
Source§impl Import<GlobalType> for ModuleBuilder
impl Import<GlobalType> for ModuleBuilder
fn import<S, T>(&mut self, module: S, name: T, index: GlobalType) -> ImportIndex
Source§impl Import<MemoryType> for ModuleBuilder
impl Import<MemoryType> for ModuleBuilder
fn import<S, T>(&mut self, module: S, name: T, index: MemoryType) -> ImportIndex
Source§impl Import<TableType> for ModuleBuilder
impl Import<TableType> for ModuleBuilder
Source§impl Import<TypeIndex> for ModuleBuilder
impl Import<TypeIndex> for ModuleBuilder
Source§impl NewFunction<FuncType> for ModuleBuilder
impl NewFunction<FuncType> for ModuleBuilder
fn new_function(&mut self, t: FuncType, body: FunctionBody) -> FunctionIndex
Source§impl NewFunction<TypeIndex> for ModuleBuilder
impl NewFunction<TypeIndex> for ModuleBuilder
fn new_function(&mut self, t: TypeIndex, body: FunctionBody) -> FunctionIndex
Source§impl NewMemory<Range<u32>> for ModuleBuilder
impl NewMemory<Range<u32>> for ModuleBuilder
fn new_memory(&mut self, range: Range<u32>) -> MemoryIndex
Source§impl NewMemory<RangeFrom<u32>> for ModuleBuilder
impl NewMemory<RangeFrom<u32>> for ModuleBuilder
fn new_memory(&mut self, range: RangeFrom<u32>) -> MemoryIndex
Auto Trait Implementations§
impl Freeze for ModuleBuilder
impl RefUnwindSafe for ModuleBuilder
impl Send for ModuleBuilder
impl Sync for ModuleBuilder
impl Unpin for ModuleBuilder
impl UnwindSafe for ModuleBuilder
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