mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-23 03:31:56 +00:00
missing sections in builder and order
This commit is contained in:
@ -19,36 +19,64 @@ pub struct CodeLocation {
|
||||
|
||||
#[derive(Default)]
|
||||
struct ModuleScaffold {
|
||||
pub functions: elements::FunctionsSection,
|
||||
pub types: elements::TypeSection,
|
||||
pub import: elements::ImportSection,
|
||||
pub functions: elements::FunctionsSection,
|
||||
pub table: elements::TableSection,
|
||||
pub memory: elements::MemorySection,
|
||||
pub global: elements::GlobalSection,
|
||||
pub export: elements::ExportSection,
|
||||
pub start: Option<u32>,
|
||||
pub element: elements::ElementSection,
|
||||
pub code: elements::CodeSection,
|
||||
pub data: elements::DataSection,
|
||||
pub other: Vec<elements::Section>,
|
||||
}
|
||||
|
||||
impl From<elements::Module> for ModuleScaffold {
|
||||
fn from(module: elements::Module) -> Self {
|
||||
let mut funcs: Option<elements::FunctionsSection> = None;
|
||||
let mut types: Option<elements::TypeSection> = None;
|
||||
let mut import: Option<elements::ImportSection> = None;
|
||||
let mut funcs: Option<elements::FunctionsSection> = None;
|
||||
let mut table: Option<elements::TableSection> = None;
|
||||
let mut memory: Option<elements::MemorySection> = None;
|
||||
let mut global: Option<elements::GlobalSection> = None;
|
||||
let mut export: Option<elements::ExportSection> = None;
|
||||
let mut start: Option<u32> = None;
|
||||
let mut element: Option<elements::ElementSection> = None;
|
||||
let mut code: Option<elements::CodeSection> = None;
|
||||
let mut data: Option<elements::DataSection> = None;
|
||||
|
||||
let mut sections = module.into_sections();
|
||||
while let Some(section) = sections.pop() {
|
||||
match section {
|
||||
elements::Section::Type(sect) => { types = Some(sect); }
|
||||
elements::Section::Function(sect) => { funcs = Some(sect); }
|
||||
elements::Section::Import(sect) => { import = Some(sect); }
|
||||
elements::Section::Function(sect) => { funcs = Some(sect); }
|
||||
elements::Section::Table(sect) => { table = Some(sect); }
|
||||
elements::Section::Memory(sect) => { memory = Some(sect); }
|
||||
elements::Section::Global(sect) => { global = Some(sect); }
|
||||
elements::Section::Export(sect) => { export = Some(sect); }
|
||||
elements::Section::Start(index) => { start = Some(index); }
|
||||
elements::Section::Element(sect) => { element = Some(sect); }
|
||||
elements::Section::Code(sect) => { code = Some(sect); }
|
||||
elements::Section::Data(sect) => { data = Some(sect); }
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
ModuleScaffold {
|
||||
functions: funcs.unwrap_or_default(),
|
||||
types: types.unwrap_or_default(),
|
||||
import: import.unwrap_or_default(),
|
||||
functions: funcs.unwrap_or_default(),
|
||||
table: table.unwrap_or_default(),
|
||||
memory: memory.unwrap_or_default(),
|
||||
global: global.unwrap_or_default(),
|
||||
export: export.unwrap_or_default(),
|
||||
start: start,
|
||||
element: element.unwrap_or_default(),
|
||||
code: code.unwrap_or_default(),
|
||||
data: data.unwrap_or_default(),
|
||||
other: sections,
|
||||
}
|
||||
}
|
||||
@ -70,10 +98,37 @@ impl From<ModuleScaffold> for elements::Module {
|
||||
if functions.entries().len() > 0 {
|
||||
sections.push(elements::Section::Function(functions));
|
||||
}
|
||||
let table = module.table;
|
||||
if table.entries().len() > 0 {
|
||||
sections.push(elements::Section::Table(table));
|
||||
}
|
||||
let memory = module.memory;
|
||||
if memory.entries().len() > 0 {
|
||||
sections.push(elements::Section::Memory(memory));
|
||||
}
|
||||
let global = module.global;
|
||||
if global.entries().len() > 0 {
|
||||
sections.push(elements::Section::Global(global));
|
||||
}
|
||||
let export = module.export;
|
||||
if export.entries().len() > 0 {
|
||||
sections.push(elements::Section::Export(export));
|
||||
}
|
||||
if let Some(start) = module.start {
|
||||
sections.push(elements::Section::Start(start));
|
||||
}
|
||||
let element = module.element;
|
||||
if element.entries().len() > 0 {
|
||||
sections.push(elements::Section::Element(element));
|
||||
}
|
||||
let code = module.code;
|
||||
if code.bodies().len() > 0 {
|
||||
sections.push(elements::Section::Code(code));
|
||||
}
|
||||
let data = module.data;
|
||||
if data.entries().len() > 0 {
|
||||
sections.push(elements::Section::Data(data));
|
||||
}
|
||||
sections.extend(module.other);
|
||||
elements::Module::new(sections)
|
||||
}
|
||||
|
@ -16,7 +16,8 @@ mod segment;
|
||||
pub use self::module::Module;
|
||||
pub use self::section::{
|
||||
Section, FunctionsSection, CodeSection, MemorySection, DataSection,
|
||||
ImportSection, ExportSection, GlobalSection, TypeSection,
|
||||
ImportSection, ExportSection, GlobalSection, TypeSection, ElementSection,
|
||||
TableSection,
|
||||
};
|
||||
pub use self::import_entry::{ImportEntry, MemoryType, TableType, GlobalType, External};
|
||||
pub use self::export_entry::{ExportEntry, Internal};
|
||||
|
@ -315,9 +315,11 @@ impl Serialize for FunctionsSection {
|
||||
}
|
||||
|
||||
/// Section with table definition (currently only one is allowed).
|
||||
#[derive(Default)]
|
||||
pub struct TableSection(Vec<TableType>);
|
||||
|
||||
impl TableSection {
|
||||
/// Table entries.
|
||||
pub fn entries(&self) -> &[TableType] {
|
||||
&self.0
|
||||
}
|
||||
@ -351,6 +353,7 @@ impl Serialize for TableSection {
|
||||
}
|
||||
|
||||
/// Section with table definition (currently only one entry is allowed).
|
||||
#[derive(Default)]
|
||||
pub struct MemorySection(Vec<MemoryType>);
|
||||
|
||||
impl MemorySection {
|
||||
@ -388,6 +391,7 @@ impl Serialize for MemorySection {
|
||||
}
|
||||
|
||||
/// Globals definition section.
|
||||
#[derive(Default)]
|
||||
pub struct GlobalSection(Vec<GlobalEntry>);
|
||||
|
||||
impl GlobalSection {
|
||||
@ -425,6 +429,7 @@ impl Serialize for GlobalSection {
|
||||
}
|
||||
|
||||
/// List of exports definition.
|
||||
#[derive(Default)]
|
||||
pub struct ExportSection(Vec<ExportEntry>);
|
||||
|
||||
impl ExportSection {
|
||||
@ -510,6 +515,7 @@ impl Serialize for CodeSection {
|
||||
}
|
||||
|
||||
/// Element entries section.
|
||||
#[derive(Default)]
|
||||
pub struct ElementSection(Vec<ElementSegment>);
|
||||
|
||||
impl ElementSection {
|
||||
@ -552,6 +558,7 @@ impl Serialize for ElementSection {
|
||||
}
|
||||
|
||||
/// Data entries definitions.
|
||||
#[derive(Default)]
|
||||
pub struct DataSection(Vec<DataSegment>);
|
||||
|
||||
impl DataSection {
|
||||
|
Reference in New Issue
Block a user