Struct ModuleBuilder

Source
pub struct ModuleBuilder(/* private fields */);

Implementations§

Source§

impl ModuleBuilder

Source

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
Hide additional 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}
Source

pub fn function_index_of( &self, i: ImportIndex, ) -> Result<FunctionSpaceIndex, ImportIndex>

Source

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
Hide additional 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}
Source

pub fn add_type(&mut self, ty: FuncType) -> TypeIndex

Source

pub fn add_import(&mut self, ty: ImportEntry) -> ImportIndex

Source

pub fn add_table(&mut self, ty: TableType) -> TableIndex

Source

pub fn add_memory(&mut self, ty: MemoryType) -> MemoryIndex

Source

pub fn add_global(&mut self, ty: GlobalVariable) -> GlobalIndex

Source

pub fn add_export(&mut self, ty: ExportEntry) -> ExportIndex

Source

pub fn start(&mut self, index: FunctionIndex)

Source

pub fn add_element(&mut self, ty: ElemSegment) -> ElementIndex

Source

pub fn add_data(&mut self, ty: DataSegment) -> DataIndex

Source

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
Hide additional 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}
Source

pub fn new_data( &mut self, idx: MemoryIndex, offset: Code, data: Vec<u8>, ) -> DataIndex

Source

pub fn new_global(&mut self, ty: GlobalType, init: Code) -> GlobalIndex

Trait Implementations§

Source§

impl Export<FunctionIndex> for ModuleBuilder

Source§

fn export<S: Into<String>>( &mut self, name: S, index: FunctionIndex, ) -> ExportIndex

Source§

impl Export<GlobalIndex> for ModuleBuilder

Source§

fn export<S: Into<String>>( &mut self, name: S, index: GlobalIndex, ) -> ExportIndex

Source§

impl Export<MemoryIndex> for ModuleBuilder

Source§

fn export<S: Into<String>>( &mut self, name: S, index: MemoryIndex, ) -> ExportIndex

Source§

impl Export<TableIndex> for ModuleBuilder

Source§

fn export<S: Into<String>>(&mut self, name: S, index: TableIndex) -> ExportIndex

Source§

impl Import<GlobalType> for ModuleBuilder

Source§

fn import<S, T>(&mut self, module: S, name: T, index: GlobalType) -> ImportIndex
where S: Into<String>, T: Into<String>,

Source§

impl Import<MemoryType> for ModuleBuilder

Source§

fn import<S, T>(&mut self, module: S, name: T, index: MemoryType) -> ImportIndex
where S: Into<String>, T: Into<String>,

Source§

impl Import<TableType> for ModuleBuilder

Source§

fn import<S, T>(&mut self, module: S, name: T, index: TableType) -> ImportIndex
where S: Into<String>, T: Into<String>,

Source§

impl Import<TypeIndex> for ModuleBuilder

Source§

fn import<S, T>(&mut self, module: S, name: T, index: TypeIndex) -> ImportIndex
where S: Into<String>, T: Into<String>,

Source§

impl NewFunction<FuncType> for ModuleBuilder

Source§

impl NewFunction<TypeIndex> for ModuleBuilder

Source§

impl NewMemory<Range<u32>> for ModuleBuilder

Source§

fn new_memory(&mut self, range: Range<u32>) -> MemoryIndex

Source§

impl NewMemory<RangeFrom<u32>> for ModuleBuilder

Source§

fn new_memory(&mut self, range: RangeFrom<u32>) -> MemoryIndex

Source§

impl NewTable<Range<u32>> for ModuleBuilder

Source§

fn new_table(&mut self, element: ElemType, range: Range<u32>) -> TableIndex

Source§

impl NewTable<RangeFrom<u32>> for ModuleBuilder

Source§

fn new_table(&mut self, element: ElemType, range: RangeFrom<u32>) -> TableIndex

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.