mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-28 14:11:57 +00:00
extend generation
This commit is contained in:
@ -13,9 +13,10 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let module = builder::module()
|
let module = builder::module()
|
||||||
.functions()
|
.function()
|
||||||
.signature().with_param(elements::ValueType::I32).build()
|
.signature().with_param(elements::ValueType::I32).build()
|
||||||
.bind()
|
.body().build()
|
||||||
|
.build()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
parity_wasm::serialize_to_file(&args[1], module).unwrap();
|
parity_wasm::serialize_to_file(&args[1], module).unwrap();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use super::invoke::{Invoke, Identity};
|
use super::invoke::{Invoke, Identity};
|
||||||
use super::code::{self, SignaturesBuilder};
|
use super::code::{self, SignaturesBuilder, FunctionBuilder};
|
||||||
use super::import;
|
use super::import;
|
||||||
use elements;
|
use elements;
|
||||||
|
|
||||||
@ -70,6 +70,10 @@ impl From<ModuleScaffold> for elements::Module {
|
|||||||
if functions.entries().len() > 0 {
|
if functions.entries().len() > 0 {
|
||||||
sections.push(elements::Section::Function(functions));
|
sections.push(elements::Section::Function(functions));
|
||||||
}
|
}
|
||||||
|
let code = module.code;
|
||||||
|
if code.bodies().len() > 0 {
|
||||||
|
sections.push(elements::Section::Code(code));
|
||||||
|
}
|
||||||
sections.extend(module.other);
|
sections.extend(module.other);
|
||||||
elements::Module::new(sections)
|
elements::Module::new(sections)
|
||||||
}
|
}
|
||||||
@ -182,6 +186,10 @@ impl<F> ModuleBuilder<F> where F: Invoke<elements::Module> {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn function(self) -> FunctionBuilder<Self> {
|
||||||
|
FunctionBuilder::with_callback(self)
|
||||||
|
}
|
||||||
|
|
||||||
/// Define functions section
|
/// Define functions section
|
||||||
pub fn functions(self) -> SignaturesBuilder<Self> {
|
pub fn functions(self) -> SignaturesBuilder<Self> {
|
||||||
SignaturesBuilder::with_callback(self)
|
SignaturesBuilder::with_callback(self)
|
||||||
@ -224,6 +232,19 @@ impl<F> Invoke<code::SignatureBindings> for ModuleBuilder<F>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl<F> Invoke<code::FunctionDefinition> for ModuleBuilder<F>
|
||||||
|
where F: Invoke<elements::Module>
|
||||||
|
{
|
||||||
|
type Result = Self;
|
||||||
|
|
||||||
|
fn invoke(self, def: code::FunctionDefinition) -> Self {
|
||||||
|
let mut b = self;
|
||||||
|
b.push_function(def);
|
||||||
|
b
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<F> Invoke<elements::ImportEntry> for ModuleBuilder<F>
|
impl<F> Invoke<elements::ImportEntry> for ModuleBuilder<F>
|
||||||
where F: Invoke<elements::Module>
|
where F: Invoke<elements::Module>
|
||||||
{
|
{
|
||||||
@ -258,13 +279,15 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn functions() {
|
fn functions() {
|
||||||
let module = module()
|
let module = module()
|
||||||
.functions()
|
.function()
|
||||||
.signature().with_param(::elements::ValueType::I32).build()
|
.signature().param().i32().build()
|
||||||
.bind()
|
.body().build()
|
||||||
|
.build()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
assert_eq!(module.type_section().expect("type section to exist").types().len(), 1);
|
assert_eq!(module.type_section().expect("type section to exist").types().len(), 1);
|
||||||
assert_eq!(module.functions_section().expect("function section to exist").entries().len(), 1);
|
assert_eq!(module.functions_section().expect("function section to exist").entries().len(), 1);
|
||||||
|
assert_eq!(module.code_section().expect("code section to exist").bodies().len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user