diff --git a/Cargo.toml b/Cargo.toml index 9f534b9..676f3f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,8 @@ license = "Apache-2.0 WITH LLVM-exception" edition = "2018" [dependencies] -wasmparser = "0.202" -wasm-encoder = "0.202" +wasmparser = { path = "../wasm-tools/crates/wasmparser" } +wasm-encoder = { path = "../wasm-tools/crates/wasm-encoder" } anyhow = "1.0" structopt = "0.3" log = "0.4" diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 7d3d0e1..2c074df 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -8,6 +8,7 @@ use anyhow::Result; use rayon::prelude::*; use std::borrow::Cow; use wasm_encoder::CustomSection; +use wasm_encoder::Encode; pub mod stackify; use stackify::{Context as StackifyContext, WasmBlock}; @@ -1144,6 +1145,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result { .map(|elts| elts.len() as u32) .unwrap_or(table.initial), maximum: table.max, + table64: false, }) } &ImportKind::Global(global) => { @@ -1152,6 +1154,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result { wasm_encoder::EntityType::Global(wasm_encoder::GlobalType { val_type: wasm_encoder::ValType::from(global.ty), mutable: global.mutable, + shared: false, }) } &ImportKind::Memory(mem) => { @@ -1162,6 +1165,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result { shared: mem.shared, minimum: mem.initial_pages as u64, maximum: mem.maximum_pages.map(|val| val as u64), + page_size_log2: None, }) } }; @@ -1194,6 +1198,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result { .map(|elt| elt.len()) .unwrap_or(0) as u32, maximum: table_data.max, + table64: false, }); } into_mod.section(&tables); @@ -1205,6 +1210,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result { maximum: mem_data.maximum_pages.map(|val| val as u64), memory64: mem_data.memory64, shared: mem_data.shared, + page_size_log2: None, }); } into_mod.section(&memories); @@ -1215,6 +1221,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result { wasm_encoder::GlobalType { val_type: wasm_encoder::ValType::from(global_data.ty), mutable: global_data.mutable, + shared: false, }, &const_init(global_data.ty, global_data.value), ); diff --git a/src/frontend.rs b/src/frontend.rs index b4ce04c..a1c2673 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -13,9 +13,7 @@ use anyhow::{bail, Result}; use fxhash::{FxHashMap, FxHashSet}; use log::trace; use std::convert::TryFrom; -use wasmparser::{ - BlockType, DataKind, ExternalKind, Name, NameSectionReader, Parser, Payload, TypeRef, -}; +use wasmparser::{BlockType, DataKind, ExternalKind, KnownCustom, Name, Parser, Payload, TypeRef}; #[derive(Clone, Copy, Debug, Default)] pub struct FrontendOptions { @@ -255,72 +253,68 @@ fn handle_payload<'a>( } } } - Payload::CustomSection(reader) if reader.name() == "name" => { - let name_reader = NameSectionReader::new(reader.data(), reader.data_offset()); - for subsection in name_reader { - let subsection = subsection?; - match subsection { - Name::Function(names) => { - for name in names { - let name = name?; - module.funcs[Func::new(name.index as usize)].set_name(name.name); + Payload::CustomSection(reader) => match reader.as_known() { + KnownCustom::Name(name_reader) => { + for subsection in name_reader { + let subsection = subsection?; + match subsection { + Name::Function(names) => { + for name in names { + let name = name?; + module.funcs[Func::new(name.index as usize)].set_name(name.name); + } } + _ => {} } - _ => {} } } - } - Payload::CustomSection(reader) if reader.name() == ".debug_info" => { - dwarf.debug_info = gimli::DebugInfo::new(reader.data(), gimli::LittleEndian); - } - Payload::CustomSection(reader) if reader.name() == ".debug_abbrev" => { - dwarf.debug_abbrev = gimli::DebugAbbrev::new(reader.data(), gimli::LittleEndian); - } - Payload::CustomSection(reader) if reader.name() == ".debug_addr" => { - dwarf.debug_addr = - gimli::DebugAddr::from(gimli::EndianSlice::new(reader.data(), gimli::LittleEndian)); - } - Payload::CustomSection(reader) if reader.name() == ".debug_aranges" => { - dwarf.debug_aranges = gimli::DebugAranges::new(reader.data(), gimli::LittleEndian); - } - Payload::CustomSection(reader) if reader.name() == ".debug_line" => { - dwarf.debug_line = gimli::DebugLine::new(reader.data(), gimli::LittleEndian); - } - Payload::CustomSection(reader) if reader.name() == ".debug_line_str" => { - dwarf.debug_line_str = gimli::DebugLineStr::new(reader.data(), gimli::LittleEndian); - } - Payload::CustomSection(reader) if reader.name() == ".debug_str" => { - dwarf.debug_str = gimli::DebugStr::new(reader.data(), gimli::LittleEndian); - } - Payload::CustomSection(reader) if reader.name() == ".debug_str_offsets" => { - dwarf.debug_str_offsets = gimli::DebugStrOffsets::from(gimli::EndianSlice::new( - reader.data(), - gimli::LittleEndian, - )); - } - Payload::CustomSection(reader) if reader.name() == ".debug_types" => { - dwarf.debug_types = gimli::DebugTypes::new(reader.data(), gimli::LittleEndian); - } - Payload::CustomSection(reader) if reader.name() == ".debug_loc" => { - extra_sections.debug_loc = gimli::DebugLoc::new(reader.data(), gimli::LittleEndian); - } - Payload::CustomSection(reader) if reader.name() == ".debug_loclists" => { - extra_sections.debug_loclists = - gimli::DebugLocLists::new(reader.data(), gimli::LittleEndian); - } - Payload::CustomSection(reader) if reader.name() == ".debug_ranges" => { - extra_sections.debug_ranges = - gimli::DebugRanges::new(reader.data(), gimli::LittleEndian); - } - Payload::CustomSection(reader) if reader.name() == ".debug_rnglists" => { - extra_sections.debug_rnglists = - gimli::DebugRngLists::new(reader.data(), gimli::LittleEndian); - } - Payload::CustomSection(reader) => { - module - .custom_sections - .insert(reader.name().to_owned(), reader.data().to_owned()); - } + KnownCustom::Unknown => { + if reader.name() == ".debug_info" { + dwarf.debug_info = gimli::DebugInfo::new(reader.data(), gimli::LittleEndian); + } else if reader.name() == ".debug_abbrev" { + dwarf.debug_abbrev = + gimli::DebugAbbrev::new(reader.data(), gimli::LittleEndian); + } else if reader.name() == ".debug_addr" { + dwarf.debug_addr = gimli::DebugAddr::from(gimli::EndianSlice::new( + reader.data(), + gimli::LittleEndian, + )); + } else if reader.name() == ".debug_aranges" { + dwarf.debug_aranges = + gimli::DebugAranges::new(reader.data(), gimli::LittleEndian); + } else if reader.name() == ".debug_line" { + dwarf.debug_line = gimli::DebugLine::new(reader.data(), gimli::LittleEndian); + } else if reader.name() == ".debug_line_str" { + dwarf.debug_line_str = + gimli::DebugLineStr::new(reader.data(), gimli::LittleEndian); + } else if reader.name() == ".debug_str" { + dwarf.debug_str = gimli::DebugStr::new(reader.data(), gimli::LittleEndian); + } else if reader.name() == ".debug_str_offsets" { + dwarf.debug_str_offsets = gimli::DebugStrOffsets::from( + gimli::EndianSlice::new(reader.data(), gimli::LittleEndian), + ); + } else if reader.name() == ".debug_types" { + dwarf.debug_types = gimli::DebugTypes::new(reader.data(), gimli::LittleEndian); + } else if reader.name() == ".debug_loc" { + extra_sections.debug_loc = + gimli::DebugLoc::new(reader.data(), gimli::LittleEndian); + } else if reader.name() == ".debug_loclists" { + extra_sections.debug_loclists = + gimli::DebugLocLists::new(reader.data(), gimli::LittleEndian); + } else if reader.name() == ".debug_ranges" { + extra_sections.debug_ranges = + gimli::DebugRanges::new(reader.data(), gimli::LittleEndian); + } else if reader.name() == ".debug_rnglists" { + extra_sections.debug_rnglists = + gimli::DebugRngLists::new(reader.data(), gimli::LittleEndian); + }else{ + module + .custom_sections + .insert(reader.name().to_owned(), reader.data().to_owned()); + } + } + _ => {} + }, Payload::Version { .. } => {} Payload::ElementSection(reader) => { for element in reader { diff --git a/src/ir/module.rs b/src/ir/module.rs index 9e26651..dc7c37a 100644 --- a/src/ir/module.rs +++ b/src/ir/module.rs @@ -47,8 +47,8 @@ pub struct MemorySegment { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct TableData { pub ty: Type, - pub initial: u32, - pub max: Option, + pub initial: u64, + pub max: Option, pub func_elements: Option>, } @@ -177,7 +177,7 @@ impl<'a> Module<'a> { } impl<'a> Module<'a> { - pub(crate) fn frontend_add_table(&mut self, ty: Type, initial: u32, max: Option) -> Table { + pub(crate) fn frontend_add_table(&mut self, ty: Type, initial: u64, max: Option) -> Table { let func_elements = Some(vec![]); self.tables.push(TableData { ty, diff --git a/src/lib.rs b/src/lib.rs index a773126..b981050 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,8 @@ // Re-export wasmparser for easier use of the right version by our embedders. pub use wasmparser; +// Likewise for wasm-encoder. +pub use wasm_encoder; mod backend; pub mod cfg;