Update wasmparser for exception handling (#2431)
This commit is contained in:
34
Cargo.lock
generated
34
Cargo.lock
generated
@@ -586,7 +586,7 @@ dependencies = [
|
||||
"smallvec",
|
||||
"target-lexicon",
|
||||
"thiserror",
|
||||
"wasmparser 0.67.0",
|
||||
"wasmparser 0.68.0",
|
||||
"wat",
|
||||
]
|
||||
|
||||
@@ -1150,7 +1150,7 @@ dependencies = [
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"typemap",
|
||||
"wasmparser 0.67.0",
|
||||
"wasmparser 0.68.0",
|
||||
"wat",
|
||||
]
|
||||
|
||||
@@ -2321,24 +2321,18 @@ checksum = "32fddd575d477c6e9702484139cf9f23dcd554b06d185ed0f56c857dd3a47aa6"
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.66.0"
|
||||
version = "0.68.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c97fc0456d6d09ca7b64bc33c34f4e8f29d5ccfa8e5595ef7a8957818339e6f6"
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.67.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f091cf3849e5fe76a60255bff169277459f2201435bc583b6656880553f0ad0"
|
||||
checksum = "29a00e14eed9c2ecbbdbdd4fb284f49d21b6808965de24769a6379a13ec47d4c"
|
||||
|
||||
[[package]]
|
||||
name = "wasmprinter"
|
||||
version = "0.2.13"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b580bee9eb1f029fac6014620b31f82ea2afa22d0701b9bd7f879747e3f5242"
|
||||
checksum = "f39a73b5f09cfcb1b568b61968d39b19e4ddec9b49040cfc091adf3b0788bca6"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"wasmparser 0.66.0",
|
||||
"wasmparser 0.68.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2357,7 +2351,7 @@ dependencies = [
|
||||
"smallvec",
|
||||
"target-lexicon",
|
||||
"tempfile",
|
||||
"wasmparser 0.67.0",
|
||||
"wasmparser 0.68.0",
|
||||
"wasmtime-cache",
|
||||
"wasmtime-environ",
|
||||
"wasmtime-jit",
|
||||
@@ -2435,7 +2429,7 @@ dependencies = [
|
||||
"test-programs",
|
||||
"tracing-subscriber",
|
||||
"wasi-common",
|
||||
"wasmparser 0.67.0",
|
||||
"wasmparser 0.68.0",
|
||||
"wasmtime",
|
||||
"wasmtime-cache",
|
||||
"wasmtime-debug",
|
||||
@@ -2471,7 +2465,7 @@ dependencies = [
|
||||
"object",
|
||||
"target-lexicon",
|
||||
"thiserror",
|
||||
"wasmparser 0.67.0",
|
||||
"wasmparser 0.68.0",
|
||||
"wasmtime-environ",
|
||||
]
|
||||
|
||||
@@ -2490,7 +2484,7 @@ dependencies = [
|
||||
"more-asserts",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"wasmparser 0.67.0",
|
||||
"wasmparser 0.68.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2518,7 +2512,7 @@ dependencies = [
|
||||
"log",
|
||||
"rayon",
|
||||
"wasm-smith",
|
||||
"wasmparser 0.67.0",
|
||||
"wasmparser 0.68.0",
|
||||
"wasmprinter",
|
||||
"wasmtime",
|
||||
"wasmtime-wast",
|
||||
@@ -2545,7 +2539,7 @@ dependencies = [
|
||||
"serde",
|
||||
"target-lexicon",
|
||||
"thiserror",
|
||||
"wasmparser 0.67.0",
|
||||
"wasmparser 0.68.0",
|
||||
"wasmtime-cranelift",
|
||||
"wasmtime-debug",
|
||||
"wasmtime-environ",
|
||||
@@ -2562,7 +2556,7 @@ version = "0.21.0"
|
||||
dependencies = [
|
||||
"cranelift-codegen",
|
||||
"lightbeam",
|
||||
"wasmparser 0.67.0",
|
||||
"wasmparser 0.68.0",
|
||||
"wasmtime-environ",
|
||||
]
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ libc = "0.2.60"
|
||||
log = "0.4.8"
|
||||
rayon = "1.2.1"
|
||||
humantime = "2.0.0"
|
||||
wasmparser = "0.67"
|
||||
wasmparser = "0.68"
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.8.1"
|
||||
|
||||
@@ -12,7 +12,7 @@ keywords = ["webassembly", "wasm"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
wasmparser = { version = "0.67.0", default-features = false }
|
||||
wasmparser = { version = "0.68.0", default-features = false }
|
||||
cranelift-codegen = { path = "../codegen", version = "0.68.0", default-features = false }
|
||||
cranelift-entity = { path = "../entity", version = "0.68.0" }
|
||||
cranelift-frontend = { path = "../frontend", version = "0.68.0", default-features = false }
|
||||
|
||||
@@ -534,6 +534,17 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
state.popn(return_count);
|
||||
state.reachable = false;
|
||||
}
|
||||
/********************************** Exception handing **********************************/
|
||||
Operator::Try { .. }
|
||||
| Operator::Catch
|
||||
| Operator::BrOnExn { .. }
|
||||
| Operator::Throw { .. }
|
||||
| Operator::Rethrow => {
|
||||
return Err(wasm_unsupported!(
|
||||
"proposed exception handling operator {:?}",
|
||||
op
|
||||
));
|
||||
}
|
||||
/************************************ Calls ****************************************
|
||||
* The call instructions pop off their arguments from the stack and append their
|
||||
* return values to it. `call_indirect` needs environment support because there is an
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
use crate::state::FuncTranslationState;
|
||||
use crate::translation_utils::{
|
||||
DataIndex, ElemIndex, EntityType, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex, Table,
|
||||
TableIndex, TypeIndex,
|
||||
DataIndex, ElemIndex, EntityType, Event, EventIndex, FuncIndex, Global, GlobalIndex, Memory,
|
||||
MemoryIndex, Table, TableIndex, TypeIndex,
|
||||
};
|
||||
use core::convert::From;
|
||||
use core::convert::TryFrom;
|
||||
@@ -44,6 +44,8 @@ pub enum WasmType {
|
||||
FuncRef,
|
||||
/// ExternRef type
|
||||
ExternRef,
|
||||
/// ExnRef type
|
||||
ExnRef,
|
||||
}
|
||||
|
||||
impl TryFrom<wasmparser::Type> for WasmType {
|
||||
@@ -58,6 +60,7 @@ impl TryFrom<wasmparser::Type> for WasmType {
|
||||
V128 => Ok(WasmType::V128),
|
||||
FuncRef => Ok(WasmType::FuncRef),
|
||||
ExternRef => Ok(WasmType::ExternRef),
|
||||
ExnRef => Ok(WasmType::ExnRef),
|
||||
EmptyBlockType | Func => Err(WasmError::InvalidWebAssembly {
|
||||
message: "unexpected value type".to_string(),
|
||||
offset: 0,
|
||||
@@ -76,6 +79,7 @@ impl From<WasmType> for wasmparser::Type {
|
||||
WasmType::V128 => wasmparser::Type::V128,
|
||||
WasmType::FuncRef => wasmparser::Type::FuncRef,
|
||||
WasmType::ExternRef => wasmparser::Type::ExternRef,
|
||||
WasmType::ExnRef => wasmparser::Type::ExnRef,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -689,6 +693,17 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
|
||||
field: &'data str,
|
||||
) -> WasmResult<()>;
|
||||
|
||||
/// Declares an event import to the environment.
|
||||
fn declare_event_import(
|
||||
&mut self,
|
||||
event: Event,
|
||||
module: &'data str,
|
||||
field: &'data str,
|
||||
) -> WasmResult<()> {
|
||||
drop((event, module, field));
|
||||
Err(WasmError::Unsupported("wasm events".to_string()))
|
||||
}
|
||||
|
||||
/// Declares a global import to the environment.
|
||||
fn declare_global_import(
|
||||
&mut self,
|
||||
@@ -751,6 +766,18 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
|
||||
/// Declares a memory to the environment
|
||||
fn declare_memory(&mut self, memory: Memory) -> WasmResult<()>;
|
||||
|
||||
/// Provides the number of defined events up front. By default this does nothing, but
|
||||
/// implementations can use this to preallocate memory if desired.
|
||||
fn reserve_events(&mut self, _num: u32) -> WasmResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Declares an event to the environment
|
||||
fn declare_event(&mut self, event: Event) -> WasmResult<()> {
|
||||
drop(event);
|
||||
Err(WasmError::Unsupported("wasm events".to_string()))
|
||||
}
|
||||
|
||||
/// Provides the number of defined globals up front. By default this does nothing, but
|
||||
/// implementations can use this to preallocate memory if desired.
|
||||
fn reserve_globals(&mut self, _num: u32) -> WasmResult<()> {
|
||||
@@ -780,6 +807,16 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
|
||||
name: &'data str,
|
||||
) -> WasmResult<()>;
|
||||
|
||||
/// Declares an event export to the environment.
|
||||
fn declare_event_export(
|
||||
&mut self,
|
||||
event_index: EventIndex,
|
||||
name: &'data str,
|
||||
) -> WasmResult<()> {
|
||||
drop((event_index, name));
|
||||
Err(WasmError::Unsupported("wasm events".to_string()))
|
||||
}
|
||||
|
||||
/// Declares a global export to the environment.
|
||||
fn declare_global_export(
|
||||
&mut self,
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
//! to deal with each part of it.
|
||||
use crate::environ::{ModuleEnvironment, WasmResult};
|
||||
use crate::sections_translator::{
|
||||
parse_data_section, parse_element_section, parse_export_section, parse_function_section,
|
||||
parse_global_section, parse_import_section, parse_memory_section, parse_name_section,
|
||||
parse_start_section, parse_table_section, parse_type_section,
|
||||
parse_data_section, parse_element_section, parse_event_section, parse_export_section,
|
||||
parse_function_section, parse_global_section, parse_import_section, parse_memory_section,
|
||||
parse_name_section, parse_start_section, parse_table_section, parse_type_section,
|
||||
};
|
||||
use crate::state::ModuleTranslationState;
|
||||
use cranelift_codegen::timing;
|
||||
@@ -65,6 +65,11 @@ pub fn translate_module<'data>(
|
||||
parse_memory_section(memories, environ)?;
|
||||
}
|
||||
|
||||
Payload::EventSection(events) => {
|
||||
validator.event_section(&events)?;
|
||||
parse_event_section(events, environ)?;
|
||||
}
|
||||
|
||||
Payload::GlobalSection(globals) => {
|
||||
validator.global_section(&globals)?;
|
||||
parse_global_section(globals, environ)?;
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
use crate::environ::{ModuleEnvironment, WasmError, WasmResult};
|
||||
use crate::state::ModuleTranslationState;
|
||||
use crate::translation_utils::{
|
||||
tabletype_to_type, type_to_type, DataIndex, ElemIndex, EntityType, FuncIndex, Global,
|
||||
GlobalIndex, GlobalInit, Memory, MemoryIndex, Table, TableElementType, TableIndex, TypeIndex,
|
||||
tabletype_to_type, type_to_type, DataIndex, ElemIndex, EntityType, Event, EventIndex,
|
||||
FuncIndex, Global, GlobalIndex, GlobalInit, Memory, MemoryIndex, Table, TableElementType,
|
||||
TableIndex, TypeIndex,
|
||||
};
|
||||
use crate::wasm_unsupported;
|
||||
use core::convert::TryFrom;
|
||||
@@ -24,10 +25,10 @@ use std::boxed::Box;
|
||||
use std::vec::Vec;
|
||||
use wasmparser::{
|
||||
self, Data, DataKind, DataSectionReader, Element, ElementItem, ElementItems, ElementKind,
|
||||
ElementSectionReader, Export, ExportSectionReader, ExternalKind, FunctionSectionReader,
|
||||
GlobalSectionReader, GlobalType, ImportSectionEntryType, ImportSectionReader,
|
||||
MemorySectionReader, MemoryType, NameSectionReader, Naming, Operator, TableSectionReader,
|
||||
TableType, TypeDef, TypeSectionReader,
|
||||
ElementSectionReader, EventSectionReader, EventType, Export, ExportSectionReader, ExternalKind,
|
||||
FunctionSectionReader, GlobalSectionReader, GlobalType, ImportSectionEntryType,
|
||||
ImportSectionReader, MemorySectionReader, MemoryType, NameSectionReader, Naming, Operator,
|
||||
TableSectionReader, TableType, TypeDef, TypeSectionReader,
|
||||
};
|
||||
|
||||
fn entity_type(
|
||||
@@ -39,6 +40,7 @@ fn entity_type(
|
||||
ImportSectionEntryType::Module(sig) => EntityType::Module(TypeIndex::from_u32(sig)),
|
||||
ImportSectionEntryType::Instance(sig) => EntityType::Instance(TypeIndex::from_u32(sig)),
|
||||
ImportSectionEntryType::Memory(ty) => EntityType::Memory(memory(ty)),
|
||||
ImportSectionEntryType::Event(evt) => EntityType::Event(event(evt)),
|
||||
ImportSectionEntryType::Global(ty) => {
|
||||
EntityType::Global(global(ty, environ, GlobalInit::Import)?)
|
||||
}
|
||||
@@ -58,6 +60,12 @@ fn memory(ty: MemoryType) -> Memory {
|
||||
}
|
||||
}
|
||||
|
||||
fn event(e: EventType) -> Event {
|
||||
Event {
|
||||
ty: TypeIndex::from_u32(e.type_index),
|
||||
}
|
||||
}
|
||||
|
||||
fn table(ty: TableType, environ: &mut dyn ModuleEnvironment<'_>) -> WasmResult<Table> {
|
||||
Ok(Table {
|
||||
wasm_ty: ty.element_type.try_into()?,
|
||||
@@ -163,6 +171,7 @@ pub fn parse_import_section<'data>(
|
||||
EntityType::Memory(ty) => {
|
||||
environ.declare_memory_import(ty, module_name, field_name)?;
|
||||
}
|
||||
EntityType::Event(e) => environ.declare_event_import(e, module_name, field_name)?,
|
||||
EntityType::Global(ty) => {
|
||||
environ.declare_global_import(ty, module_name, field_name)?;
|
||||
}
|
||||
@@ -227,6 +236,21 @@ pub fn parse_memory_section(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Parses the Event section of the wasm module.
|
||||
pub fn parse_event_section(
|
||||
events: EventSectionReader,
|
||||
environ: &mut dyn ModuleEnvironment,
|
||||
) -> WasmResult<()> {
|
||||
environ.reserve_events(events.get_count())?;
|
||||
|
||||
for entry in events {
|
||||
let event = event(entry?);
|
||||
environ.declare_event(event)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Parses the Global section of the wasm module.
|
||||
pub fn parse_global_section(
|
||||
globals: GlobalSectionReader,
|
||||
@@ -290,6 +314,7 @@ pub fn parse_export_section<'data>(
|
||||
ExternalKind::Memory => {
|
||||
environ.declare_memory_export(MemoryIndex::new(index), field)?
|
||||
}
|
||||
ExternalKind::Event => environ.declare_event_export(EventIndex::new(index), field)?,
|
||||
ExternalKind::Global => {
|
||||
environ.declare_global_export(GlobalIndex::new(index), field)?
|
||||
}
|
||||
|
||||
@@ -91,6 +91,12 @@ entity_impl!(ModuleIndex);
|
||||
pub struct InstanceIndex(u32);
|
||||
entity_impl!(InstanceIndex);
|
||||
|
||||
/// Index type of an event inside the WebAssembly module.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
pub struct EventIndex(u32);
|
||||
entity_impl!(EventIndex);
|
||||
|
||||
/// An index of an entity.
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
@@ -119,6 +125,8 @@ pub enum EntityType {
|
||||
Global(Global),
|
||||
/// A linear memory with the specified limits
|
||||
Memory(Memory),
|
||||
/// An event definition.
|
||||
Event(Event),
|
||||
/// A table with the specified element type and limits
|
||||
Table(Table),
|
||||
/// A function type where the index points to the type section and records a
|
||||
@@ -212,6 +220,14 @@ pub struct Memory {
|
||||
pub shared: bool,
|
||||
}
|
||||
|
||||
/// WebAssembly event.
|
||||
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
pub struct Event {
|
||||
/// The event signature type.
|
||||
pub ty: TypeIndex,
|
||||
}
|
||||
|
||||
/// Helper function translating wasmparser types to Cranelift types when possible.
|
||||
pub fn type_to_type<PE: TargetEnvironment + ?Sized>(
|
||||
ty: wasmparser::Type,
|
||||
|
||||
@@ -13,7 +13,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
gimli = "0.23.0"
|
||||
wasmparser = "0.67.0"
|
||||
wasmparser = "0.68.0"
|
||||
object = { version = "0.22.0", default-features = false, features = ["read", "write"] }
|
||||
wasmtime-environ = { path = "../environ", version = "0.21.0" }
|
||||
target-lexicon = { version = "0.11.0", default-features = false }
|
||||
|
||||
@@ -16,7 +16,7 @@ anyhow = "1.0"
|
||||
cranelift-codegen = { path = "../../cranelift/codegen", version = "0.68.0", features = ["enable-serde"] }
|
||||
cranelift-entity = { path = "../../cranelift/entity", version = "0.68.0", features = ["enable-serde"] }
|
||||
cranelift-wasm = { path = "../../cranelift/wasm", version = "0.68.0", features = ["enable-serde"] }
|
||||
wasmparser = "0.67.0"
|
||||
wasmparser = "0.68.0"
|
||||
indexmap = { version = "1.0.2", features = ["serde-1"] }
|
||||
thiserror = "1.0.4"
|
||||
serde = { version = "1.0.94", features = ["derive"] }
|
||||
|
||||
@@ -12,8 +12,8 @@ arbitrary = { version = "0.4.1", features = ["derive"] }
|
||||
env_logger = "0.8.1"
|
||||
log = "0.4.8"
|
||||
rayon = "1.2.1"
|
||||
wasmparser = "0.67.0"
|
||||
wasmprinter = "0.2.13"
|
||||
wasmparser = "0.68.0"
|
||||
wasmprinter = "0.2.15"
|
||||
wasmtime = { path = "../wasmtime" }
|
||||
wasmtime-wast = { path = "../wast" }
|
||||
wasm-smith = "0.1.10"
|
||||
|
||||
@@ -28,7 +28,7 @@ rayon = { version = "1.0", optional = true }
|
||||
region = "2.1.0"
|
||||
thiserror = "1.0.4"
|
||||
target-lexicon = { version = "0.11.0", default-features = false }
|
||||
wasmparser = "0.67.0"
|
||||
wasmparser = "0.68.0"
|
||||
more-asserts = "0.2.1"
|
||||
anyhow = "1.0"
|
||||
cfg-if = "1.0"
|
||||
|
||||
@@ -24,7 +24,7 @@ more-asserts = "0.2.1"
|
||||
smallvec = "1.0.0"
|
||||
thiserror = "1.0.9"
|
||||
typemap = "0.3"
|
||||
wasmparser = "0.67.0"
|
||||
wasmparser = "0.68.0"
|
||||
|
||||
[dev-dependencies]
|
||||
lazy_static = "1.2"
|
||||
|
||||
@@ -13,6 +13,6 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
lightbeam = { path = "..", version = "0.21.0" }
|
||||
wasmparser = "0.67"
|
||||
wasmparser = "0.68"
|
||||
cranelift-codegen = { path = "../../../cranelift/codegen", version = "0.68.0" }
|
||||
wasmtime-environ = { path = "../../environ", version = "0.21.0" }
|
||||
|
||||
@@ -16,7 +16,7 @@ wasmtime-jit = { path = "../jit", version = "0.21.0" }
|
||||
wasmtime-cache = { path = "../cache", version = "0.21.0", optional = true }
|
||||
wasmtime-profiling = { path = "../profiling", version = "0.21.0" }
|
||||
target-lexicon = { version = "0.11.0", default-features = false }
|
||||
wasmparser = "0.67.0"
|
||||
wasmparser = "0.68.0"
|
||||
anyhow = "1.0.19"
|
||||
region = "2.2.0"
|
||||
libc = "0.2"
|
||||
|
||||
@@ -133,6 +133,7 @@ impl ValType {
|
||||
wasm::WasmType::V128 => Self::V128,
|
||||
wasm::WasmType::FuncRef => Self::FuncRef,
|
||||
wasm::WasmType::ExternRef => Self::ExternRef,
|
||||
wasm::WasmType::ExnRef => unimplemented!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,6 +223,7 @@ impl ExternType {
|
||||
};
|
||||
InstanceType::from_wasmtime(module, exports).into()
|
||||
}
|
||||
EntityType::Event(_) => unimplemented!("wasm event support"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user