mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-14 15:31:44 +00:00
import section for scaffold struct
This commit is contained in:
@ -12,6 +12,7 @@ pub struct ModuleBuilder<F=Identity> {
|
|||||||
struct ModuleScaffold {
|
struct ModuleScaffold {
|
||||||
pub functions: elements::FunctionsSection,
|
pub functions: elements::FunctionsSection,
|
||||||
pub types: elements::TypeSection,
|
pub types: elements::TypeSection,
|
||||||
|
pub import: elements::ImportSection,
|
||||||
pub other: Vec<elements::Section>,
|
pub other: Vec<elements::Section>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,12 +20,14 @@ impl From<elements::Module> for ModuleScaffold {
|
|||||||
fn from(module: elements::Module) -> Self {
|
fn from(module: elements::Module) -> Self {
|
||||||
let mut funcs: Option<elements::FunctionsSection> = None;
|
let mut funcs: Option<elements::FunctionsSection> = None;
|
||||||
let mut types: Option<elements::TypeSection> = None;
|
let mut types: Option<elements::TypeSection> = None;
|
||||||
|
let mut import: Option<elements::ImportSection> = None;
|
||||||
|
|
||||||
let mut sections = module.into_sections();
|
let mut sections = module.into_sections();
|
||||||
while let Some(section) = sections.pop() {
|
while let Some(section) = sections.pop() {
|
||||||
match section {
|
match section {
|
||||||
elements::Section::Type(sect) => { types = Some(sect); }
|
elements::Section::Type(sect) => { types = Some(sect); }
|
||||||
elements::Section::Function(sect) => { funcs = Some(sect); }
|
elements::Section::Function(sect) => { funcs = Some(sect); }
|
||||||
|
elements::Section::Import(sect) => { import = Some(sect); }
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,6 +35,7 @@ impl From<elements::Module> for ModuleScaffold {
|
|||||||
ModuleScaffold {
|
ModuleScaffold {
|
||||||
functions: funcs.unwrap_or_default(),
|
functions: funcs.unwrap_or_default(),
|
||||||
types: types.unwrap_or_default(),
|
types: types.unwrap_or_default(),
|
||||||
|
import: import.unwrap_or_default(),
|
||||||
other: sections,
|
other: sections,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,6 +53,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 import = module.import;
|
||||||
|
if import.entries().len() > 0 {
|
||||||
|
sections.push(elements::Section::Import(import));
|
||||||
|
}
|
||||||
sections.extend(module.other);
|
sections.extend(module.other);
|
||||||
elements::Module::new(sections)
|
elements::Module::new(sections)
|
||||||
}
|
}
|
||||||
|
@ -220,6 +220,7 @@ impl Serialize for TypeSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Section of the imports definition.
|
/// Section of the imports definition.
|
||||||
|
#[derive(Default)]
|
||||||
pub struct ImportSection(Vec<ImportEntry>);
|
pub struct ImportSection(Vec<ImportEntry>);
|
||||||
|
|
||||||
impl ImportSection {
|
impl ImportSection {
|
||||||
|
Reference in New Issue
Block a user