Upgrade to latest wasmparser/wasmencoder.

This commit is contained in:
Chris Fallin 2024-06-21 19:38:03 -07:00 committed by Graham Kelly
parent 4bdc602ef9
commit efa07f16cf
5 changed files with 73 additions and 70 deletions

View file

@ -7,8 +7,8 @@ license = "Apache-2.0 WITH LLVM-exception"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
wasmparser = "0.202" wasmparser = { path = "../wasm-tools/crates/wasmparser" }
wasm-encoder = "0.202" wasm-encoder = { path = "../wasm-tools/crates/wasm-encoder" }
anyhow = "1.0" anyhow = "1.0"
structopt = "0.3" structopt = "0.3"
log = "0.4" log = "0.4"

View file

@ -8,6 +8,7 @@ use anyhow::Result;
use rayon::prelude::*; use rayon::prelude::*;
use std::borrow::Cow; use std::borrow::Cow;
use wasm_encoder::CustomSection; use wasm_encoder::CustomSection;
use wasm_encoder::Encode;
pub mod stackify; pub mod stackify;
use stackify::{Context as StackifyContext, WasmBlock}; use stackify::{Context as StackifyContext, WasmBlock};
@ -1144,6 +1145,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<wasm_encoder::Module> {
.map(|elts| elts.len() as u32) .map(|elts| elts.len() as u32)
.unwrap_or(table.initial), .unwrap_or(table.initial),
maximum: table.max, maximum: table.max,
table64: false,
}) })
} }
&ImportKind::Global(global) => { &ImportKind::Global(global) => {
@ -1152,6 +1154,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<wasm_encoder::Module> {
wasm_encoder::EntityType::Global(wasm_encoder::GlobalType { wasm_encoder::EntityType::Global(wasm_encoder::GlobalType {
val_type: wasm_encoder::ValType::from(global.ty), val_type: wasm_encoder::ValType::from(global.ty),
mutable: global.mutable, mutable: global.mutable,
shared: false,
}) })
} }
&ImportKind::Memory(mem) => { &ImportKind::Memory(mem) => {
@ -1162,6 +1165,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<wasm_encoder::Module> {
shared: mem.shared, shared: mem.shared,
minimum: mem.initial_pages as u64, minimum: mem.initial_pages as u64,
maximum: mem.maximum_pages.map(|val| val 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<wasm_encoder::Module> {
.map(|elt| elt.len()) .map(|elt| elt.len())
.unwrap_or(0) as u32, .unwrap_or(0) as u32,
maximum: table_data.max, maximum: table_data.max,
table64: false,
}); });
} }
into_mod.section(&tables); into_mod.section(&tables);
@ -1205,6 +1210,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<wasm_encoder::Module> {
maximum: mem_data.maximum_pages.map(|val| val as u64), maximum: mem_data.maximum_pages.map(|val| val as u64),
memory64: mem_data.memory64, memory64: mem_data.memory64,
shared: mem_data.shared, shared: mem_data.shared,
page_size_log2: None,
}); });
} }
into_mod.section(&memories); into_mod.section(&memories);
@ -1215,6 +1221,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<wasm_encoder::Module> {
wasm_encoder::GlobalType { wasm_encoder::GlobalType {
val_type: wasm_encoder::ValType::from(global_data.ty), val_type: wasm_encoder::ValType::from(global_data.ty),
mutable: global_data.mutable, mutable: global_data.mutable,
shared: false,
}, },
&const_init(global_data.ty, global_data.value), &const_init(global_data.ty, global_data.value),
); );

View file

@ -13,9 +13,7 @@ use anyhow::{bail, Result};
use fxhash::{FxHashMap, FxHashSet}; use fxhash::{FxHashMap, FxHashSet};
use log::trace; use log::trace;
use std::convert::TryFrom; use std::convert::TryFrom;
use wasmparser::{ use wasmparser::{BlockType, DataKind, ExternalKind, KnownCustom, Name, Parser, Payload, TypeRef};
BlockType, DataKind, ExternalKind, Name, NameSectionReader, Parser, Payload, TypeRef,
};
#[derive(Clone, Copy, Debug, Default)] #[derive(Clone, Copy, Debug, Default)]
pub struct FrontendOptions { pub struct FrontendOptions {
@ -255,8 +253,8 @@ fn handle_payload<'a>(
} }
} }
} }
Payload::CustomSection(reader) if reader.name() == "name" => { Payload::CustomSection(reader) => match reader.as_known() {
let name_reader = NameSectionReader::new(reader.data(), reader.data_offset()); KnownCustom::Name(name_reader) => {
for subsection in name_reader { for subsection in name_reader {
let subsection = subsection?; let subsection = subsection?;
match subsection { match subsection {
@ -270,57 +268,53 @@ fn handle_payload<'a>(
} }
} }
} }
Payload::CustomSection(reader) if reader.name() == ".debug_info" => { KnownCustom::Unknown => {
if reader.name() == ".debug_info" {
dwarf.debug_info = gimli::DebugInfo::new(reader.data(), gimli::LittleEndian); dwarf.debug_info = gimli::DebugInfo::new(reader.data(), gimli::LittleEndian);
} } else if reader.name() == ".debug_abbrev" {
Payload::CustomSection(reader) if reader.name() == ".debug_abbrev" => { dwarf.debug_abbrev =
dwarf.debug_abbrev = gimli::DebugAbbrev::new(reader.data(), gimli::LittleEndian); gimli::DebugAbbrev::new(reader.data(), gimli::LittleEndian);
} } else if reader.name() == ".debug_addr" {
Payload::CustomSection(reader) if reader.name() == ".debug_addr" => { dwarf.debug_addr = gimli::DebugAddr::from(gimli::EndianSlice::new(
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(), reader.data(),
gimli::LittleEndian, gimli::LittleEndian,
)); ));
} } else if reader.name() == ".debug_aranges" {
Payload::CustomSection(reader) if reader.name() == ".debug_types" => { 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); dwarf.debug_types = gimli::DebugTypes::new(reader.data(), gimli::LittleEndian);
} } else if reader.name() == ".debug_loc" {
Payload::CustomSection(reader) if reader.name() == ".debug_loc" => { extra_sections.debug_loc =
extra_sections.debug_loc = gimli::DebugLoc::new(reader.data(), gimli::LittleEndian); gimli::DebugLoc::new(reader.data(), gimli::LittleEndian);
} } else if reader.name() == ".debug_loclists" {
Payload::CustomSection(reader) if reader.name() == ".debug_loclists" => {
extra_sections.debug_loclists = extra_sections.debug_loclists =
gimli::DebugLocLists::new(reader.data(), gimli::LittleEndian); gimli::DebugLocLists::new(reader.data(), gimli::LittleEndian);
} } else if reader.name() == ".debug_ranges" {
Payload::CustomSection(reader) if reader.name() == ".debug_ranges" => {
extra_sections.debug_ranges = extra_sections.debug_ranges =
gimli::DebugRanges::new(reader.data(), gimli::LittleEndian); gimli::DebugRanges::new(reader.data(), gimli::LittleEndian);
} } else if reader.name() == ".debug_rnglists" {
Payload::CustomSection(reader) if reader.name() == ".debug_rnglists" => {
extra_sections.debug_rnglists = extra_sections.debug_rnglists =
gimli::DebugRngLists::new(reader.data(), gimli::LittleEndian); gimli::DebugRngLists::new(reader.data(), gimli::LittleEndian);
} }else{
Payload::CustomSection(reader) => {
module module
.custom_sections .custom_sections
.insert(reader.name().to_owned(), reader.data().to_owned()); .insert(reader.name().to_owned(), reader.data().to_owned());
} }
}
_ => {}
},
Payload::Version { .. } => {} Payload::Version { .. } => {}
Payload::ElementSection(reader) => { Payload::ElementSection(reader) => {
for element in reader { for element in reader {

View file

@ -47,8 +47,8 @@ pub struct MemorySegment {
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TableData { pub struct TableData {
pub ty: Type, pub ty: Type,
pub initial: u32, pub initial: u64,
pub max: Option<u32>, pub max: Option<u64>,
pub func_elements: Option<Vec<Func>>, pub func_elements: Option<Vec<Func>>,
} }
@ -177,7 +177,7 @@ impl<'a> Module<'a> {
} }
impl<'a> Module<'a> { impl<'a> Module<'a> {
pub(crate) fn frontend_add_table(&mut self, ty: Type, initial: u32, max: Option<u32>) -> Table { pub(crate) fn frontend_add_table(&mut self, ty: Type, initial: u64, max: Option<u64>) -> Table {
let func_elements = Some(vec![]); let func_elements = Some(vec![]);
self.tables.push(TableData { self.tables.push(TableData {
ty, ty,

View file

@ -4,6 +4,8 @@
// Re-export wasmparser for easier use of the right version by our embedders. // Re-export wasmparser for easier use of the right version by our embedders.
pub use wasmparser; pub use wasmparser;
// Likewise for wasm-encoder.
pub use wasm_encoder;
mod backend; mod backend;
pub mod cfg; pub mod cfg;