Upgrade to latest wasmparser/wasmencoder.
This commit is contained in:
parent
4bdc602ef9
commit
efa07f16cf
|
@ -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"
|
||||||
|
|
|
@ -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),
|
||||||
);
|
);
|
||||||
|
|
124
src/frontend.rs
124
src/frontend.rs
|
@ -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,72 +253,68 @@ 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 {
|
||||||
Name::Function(names) => {
|
Name::Function(names) => {
|
||||||
for name in names {
|
for name in names {
|
||||||
let name = name?;
|
let name = name?;
|
||||||
module.funcs[Func::new(name.index as usize)].set_name(name.name);
|
module.funcs[Func::new(name.index as usize)].set_name(name.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
KnownCustom::Unknown => {
|
||||||
Payload::CustomSection(reader) if reader.name() == ".debug_info" => {
|
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 =
|
reader.data(),
|
||||||
gimli::DebugAddr::from(gimli::EndianSlice::new(reader.data(), gimli::LittleEndian));
|
gimli::LittleEndian,
|
||||||
}
|
));
|
||||||
Payload::CustomSection(reader) if reader.name() == ".debug_aranges" => {
|
} else if reader.name() == ".debug_aranges" {
|
||||||
dwarf.debug_aranges = gimli::DebugAranges::new(reader.data(), gimli::LittleEndian);
|
dwarf.debug_aranges =
|
||||||
}
|
gimli::DebugAranges::new(reader.data(), gimli::LittleEndian);
|
||||||
Payload::CustomSection(reader) if reader.name() == ".debug_line" => {
|
} else if reader.name() == ".debug_line" {
|
||||||
dwarf.debug_line = gimli::DebugLine::new(reader.data(), gimli::LittleEndian);
|
dwarf.debug_line = gimli::DebugLine::new(reader.data(), gimli::LittleEndian);
|
||||||
}
|
} else if reader.name() == ".debug_line_str" {
|
||||||
Payload::CustomSection(reader) if reader.name() == ".debug_line_str" => {
|
dwarf.debug_line_str =
|
||||||
dwarf.debug_line_str = gimli::DebugLineStr::new(reader.data(), gimli::LittleEndian);
|
gimli::DebugLineStr::new(reader.data(), gimli::LittleEndian);
|
||||||
}
|
} else if reader.name() == ".debug_str" {
|
||||||
Payload::CustomSection(reader) if reader.name() == ".debug_str" => {
|
dwarf.debug_str = gimli::DebugStr::new(reader.data(), gimli::LittleEndian);
|
||||||
dwarf.debug_str = gimli::DebugStr::new(reader.data(), gimli::LittleEndian);
|
} else if reader.name() == ".debug_str_offsets" {
|
||||||
}
|
dwarf.debug_str_offsets = gimli::DebugStrOffsets::from(
|
||||||
Payload::CustomSection(reader) if reader.name() == ".debug_str_offsets" => {
|
gimli::EndianSlice::new(reader.data(), gimli::LittleEndian),
|
||||||
dwarf.debug_str_offsets = gimli::DebugStrOffsets::from(gimli::EndianSlice::new(
|
);
|
||||||
reader.data(),
|
} else if reader.name() == ".debug_types" {
|
||||||
gimli::LittleEndian,
|
dwarf.debug_types = gimli::DebugTypes::new(reader.data(), gimli::LittleEndian);
|
||||||
));
|
} else if reader.name() == ".debug_loc" {
|
||||||
}
|
extra_sections.debug_loc =
|
||||||
Payload::CustomSection(reader) if reader.name() == ".debug_types" => {
|
gimli::DebugLoc::new(reader.data(), gimli::LittleEndian);
|
||||||
dwarf.debug_types = gimli::DebugTypes::new(reader.data(), gimli::LittleEndian);
|
} else if reader.name() == ".debug_loclists" {
|
||||||
}
|
extra_sections.debug_loclists =
|
||||||
Payload::CustomSection(reader) if reader.name() == ".debug_loc" => {
|
gimli::DebugLocLists::new(reader.data(), gimli::LittleEndian);
|
||||||
extra_sections.debug_loc = gimli::DebugLoc::new(reader.data(), gimli::LittleEndian);
|
} else if reader.name() == ".debug_ranges" {
|
||||||
}
|
extra_sections.debug_ranges =
|
||||||
Payload::CustomSection(reader) if reader.name() == ".debug_loclists" => {
|
gimli::DebugRanges::new(reader.data(), gimli::LittleEndian);
|
||||||
extra_sections.debug_loclists =
|
} else if reader.name() == ".debug_rnglists" {
|
||||||
gimli::DebugLocLists::new(reader.data(), gimli::LittleEndian);
|
extra_sections.debug_rnglists =
|
||||||
}
|
gimli::DebugRngLists::new(reader.data(), gimli::LittleEndian);
|
||||||
Payload::CustomSection(reader) if reader.name() == ".debug_ranges" => {
|
}else{
|
||||||
extra_sections.debug_ranges =
|
module
|
||||||
gimli::DebugRanges::new(reader.data(), gimli::LittleEndian);
|
.custom_sections
|
||||||
}
|
.insert(reader.name().to_owned(), reader.data().to_owned());
|
||||||
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());
|
|
||||||
}
|
|
||||||
Payload::Version { .. } => {}
|
Payload::Version { .. } => {}
|
||||||
Payload::ElementSection(reader) => {
|
Payload::ElementSection(reader) => {
|
||||||
for element in reader {
|
for element in reader {
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue