Update wasm-tools crates (#3997)
* Update wasm-tools crates This commit updates the wasm-tools family of crates as used in Wasmtime. Notably this brings in the update which removes module linking support as well as a number of internal refactorings around names and such within wasmparser itself. This updates all of the wasm translation support which binds to wasmparser as appropriate. Other crates all had API-compatible changes for at least what Wasmtime used so no further changes were necessary beyond updating version requirements. * Update a test expectation
This commit is contained in:
45
Cargo.lock
generated
45
Cargo.lock
generated
@@ -3316,18 +3316,18 @@ checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-encoder"
|
name = "wasm-encoder"
|
||||||
version = "0.10.0"
|
version = "0.11.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "aa9d9bf45fc46f71c407837c9b30b1e874197f2dc357588430b21e5017d290ab"
|
checksum = "a35138d119147af92d7e44ae0f052f6496ee5f38e7c0cad3e0338befdb8f3753"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"leb128",
|
"leb128",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-mutate"
|
name = "wasm-mutate"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "88f7ccba3995e0533a62e5fa5786236e7a61e7b421a460ca68bc4c5382c7ed82"
|
checksum = "f9e5f369abe36f3dca16811234da3550d72075c6b1365173811118307478f51d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"egg",
|
"egg",
|
||||||
"log",
|
"log",
|
||||||
@@ -3339,15 +3339,16 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-smith"
|
name = "wasm-smith"
|
||||||
version = "0.9.1"
|
version = "0.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1bf1f1ae7d995f2d82326fda2c92deb2444fd3e59bf885fe9a4bbe9bde3b6c93"
|
checksum = "50b4138c138f975e29dbd3ceea3a8d3ea2bb43f71abd4b236640d0cb14cb8ef7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arbitrary",
|
"arbitrary",
|
||||||
"flagset",
|
"flagset",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"leb128",
|
"leb128",
|
||||||
"wasm-encoder",
|
"wasm-encoder",
|
||||||
|
"wasmparser",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3385,15 +3386,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmparser"
|
name = "wasmparser"
|
||||||
version = "0.83.0"
|
version = "0.84.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a"
|
checksum = "77dc97c22bb5ce49a47b745bed8812d30206eff5ef3af31424f2c1820c0974b2"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmprinter"
|
name = "wasmprinter"
|
||||||
version = "0.2.33"
|
version = "0.2.34"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f973822fb3ca7e03ab421910274514b405df19a3d53acb131ae4df3a2fc4eb58"
|
checksum = "9b72b3c96567183a4eca151040b5f61735b2d53e7cadd4242dbb61cd9011d865"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"wasmparser",
|
"wasmparser",
|
||||||
@@ -3734,7 +3738,7 @@ version = "0.37.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"wasmtime",
|
"wasmtime",
|
||||||
"wast 39.0.0",
|
"wast 40.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3758,12 +3762,23 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wat"
|
name = "wast"
|
||||||
version = "1.0.41"
|
version = "40.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ab98ed25494f97c69f28758617f27c3e92e5336040b5c3a14634f2dd3fe61830"
|
checksum = "9bb4f48a8b083dbc50e291e430afb8f524092bb00428957bcc63f49f856c64ac"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"wast 39.0.0",
|
"leb128",
|
||||||
|
"memchr",
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wat"
|
||||||
|
version = "1.0.42"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0401b6395ce0db91629a75b29597ccb66ea29950af9fc859f1bb3a736609c76e"
|
||||||
|
dependencies = [
|
||||||
|
"wast 40.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ file-per-thread-logger = "0.1.1"
|
|||||||
libc = "0.2.60"
|
libc = "0.2.60"
|
||||||
rayon = "1.5.0"
|
rayon = "1.5.0"
|
||||||
humantime = "2.0.0"
|
humantime = "2.0.0"
|
||||||
wasmparser = "0.83.0"
|
wasmparser = "0.84.0"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
listenfd = "0.3.5"
|
listenfd = "0.3.5"
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ num_cpus = "1.13.0"
|
|||||||
winapi = { version = "0.3.9", features = ['memoryapi'] }
|
winapi = { version = "0.3.9", features = ['memoryapi'] }
|
||||||
memchr = "2.4"
|
memchr = "2.4"
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
wat = "1.0.41"
|
wat = "1.0.42"
|
||||||
once_cell = "1.9.0"
|
once_cell = "1.9.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ keywords = ["webassembly", "wasm"]
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmparser = { version = "0.83.0", default-features = false }
|
wasmparser = { version = "0.84.0", default-features = false }
|
||||||
cranelift-codegen = { path = "../codegen", version = "0.84.0", default-features = false }
|
cranelift-codegen = { path = "../codegen", version = "0.84.0", default-features = false }
|
||||||
cranelift-entity = { path = "../entity", version = "0.84.0" }
|
cranelift-entity = { path = "../entity", version = "0.84.0" }
|
||||||
cranelift-frontend = { path = "../frontend", version = "0.84.0", default-features = false }
|
cranelift-frontend = { path = "../frontend", version = "0.84.0", default-features = false }
|
||||||
|
|||||||
@@ -596,7 +596,11 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
|||||||
state.popn(num_args);
|
state.popn(num_args);
|
||||||
state.pushn(inst_results);
|
state.pushn(inst_results);
|
||||||
}
|
}
|
||||||
Operator::CallIndirect { index, table_index } => {
|
Operator::CallIndirect {
|
||||||
|
index,
|
||||||
|
table_index,
|
||||||
|
table_byte: _,
|
||||||
|
} => {
|
||||||
// `index` is the index of the function's signature and `table_index` is the index of
|
// `index` is the index of the function's signature and `table_index` is the index of
|
||||||
// the table to search the function in.
|
// the table to search the function in.
|
||||||
let (sigref, num_args) = state.get_indirect_sig(builder.func, *index, environ)?;
|
let (sigref, num_args) = state.get_indirect_sig(builder.func, *index, environ)?;
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
|
|||||||
WasmType::F32 => ir::types::F32,
|
WasmType::F32 => ir::types::F32,
|
||||||
WasmType::F64 => ir::types::F64,
|
WasmType::F64 => ir::types::F64,
|
||||||
WasmType::V128 => ir::types::I8X16,
|
WasmType::V128 => ir::types::I8X16,
|
||||||
WasmType::ExnRef | WasmType::FuncRef | WasmType::ExternRef => ir::types::R64,
|
WasmType::FuncRef | WasmType::ExternRef => ir::types::R64,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -685,7 +685,7 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
|
|||||||
WasmType::F32 => ir::types::F32,
|
WasmType::F32 => ir::types::F32,
|
||||||
WasmType::F64 => ir::types::F64,
|
WasmType::F64 => ir::types::F64,
|
||||||
WasmType::V128 => ir::types::I8X16,
|
WasmType::V128 => ir::types::I8X16,
|
||||||
WasmType::FuncRef | WasmType::ExternRef | WasmType::ExnRef => reference_type,
|
WasmType::FuncRef | WasmType::ExternRef => reference_type,
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
sig.params.extend(wasm.params().iter().map(&mut cvt));
|
sig.params.extend(wasm.params().iter().map(&mut cvt));
|
||||||
@@ -698,7 +698,7 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
|
|||||||
&mut self,
|
&mut self,
|
||||||
index: TypeIndex,
|
index: TypeIndex,
|
||||||
module: &'data str,
|
module: &'data str,
|
||||||
field: Option<&'data str>,
|
field: &'data str,
|
||||||
) -> WasmResult<()> {
|
) -> WasmResult<()> {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
self.info.functions.len(),
|
self.info.functions.len(),
|
||||||
@@ -708,7 +708,7 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
|
|||||||
self.info.functions.push(Exportable::new(index));
|
self.info.functions.push(Exportable::new(index));
|
||||||
self.info
|
self.info
|
||||||
.imported_funcs
|
.imported_funcs
|
||||||
.push((String::from(module), String::from(field.unwrap())));
|
.push((String::from(module), String::from(field)));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,12 +726,12 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
|
|||||||
&mut self,
|
&mut self,
|
||||||
global: Global,
|
global: Global,
|
||||||
module: &'data str,
|
module: &'data str,
|
||||||
field: Option<&'data str>,
|
field: &'data str,
|
||||||
) -> WasmResult<()> {
|
) -> WasmResult<()> {
|
||||||
self.info.globals.push(Exportable::new(global));
|
self.info.globals.push(Exportable::new(global));
|
||||||
self.info
|
self.info
|
||||||
.imported_globals
|
.imported_globals
|
||||||
.push((String::from(module), String::from(field.unwrap())));
|
.push((String::from(module), String::from(field)));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -744,12 +744,12 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
|
|||||||
&mut self,
|
&mut self,
|
||||||
table: Table,
|
table: Table,
|
||||||
module: &'data str,
|
module: &'data str,
|
||||||
field: Option<&'data str>,
|
field: &'data str,
|
||||||
) -> WasmResult<()> {
|
) -> WasmResult<()> {
|
||||||
self.info.tables.push(Exportable::new(table));
|
self.info.tables.push(Exportable::new(table));
|
||||||
self.info
|
self.info
|
||||||
.imported_tables
|
.imported_tables
|
||||||
.push((String::from(module), String::from(field.unwrap())));
|
.push((String::from(module), String::from(field)));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -789,12 +789,12 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
|
|||||||
&mut self,
|
&mut self,
|
||||||
memory: Memory,
|
memory: Memory,
|
||||||
module: &'data str,
|
module: &'data str,
|
||||||
field: Option<&'data str>,
|
field: &'data str,
|
||||||
) -> WasmResult<()> {
|
) -> WasmResult<()> {
|
||||||
self.info.memories.push(Exportable::new(memory));
|
self.info.memories.push(Exportable::new(memory));
|
||||||
self.info
|
self.info
|
||||||
.imported_memories
|
.imported_memories
|
||||||
.push((String::from(module), String::from(field.unwrap())));
|
.push((String::from(module), String::from(field)));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,8 @@
|
|||||||
|
|
||||||
use crate::state::FuncTranslationState;
|
use crate::state::FuncTranslationState;
|
||||||
use crate::{
|
use crate::{
|
||||||
DataIndex, ElemIndex, EntityType, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex,
|
DataIndex, ElemIndex, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex,
|
||||||
SignatureIndex, Table, TableIndex, Tag, TagIndex, TypeIndex, WasmError, WasmFuncType,
|
Table, TableIndex, Tag, TagIndex, TypeIndex, WasmError, WasmFuncType, WasmResult, WasmType,
|
||||||
WasmResult, WasmType,
|
|
||||||
};
|
};
|
||||||
use core::convert::From;
|
use core::convert::From;
|
||||||
use cranelift_codegen::cursor::FuncCursor;
|
use cranelift_codegen::cursor::FuncCursor;
|
||||||
@@ -531,22 +530,6 @@ pub trait ModuleEnvironment<'data> {
|
|||||||
/// Declares a function signature to the environment.
|
/// Declares a function signature to the environment.
|
||||||
fn declare_type_func(&mut self, wasm_func_type: WasmFuncType) -> WasmResult<()>;
|
fn declare_type_func(&mut self, wasm_func_type: WasmFuncType) -> WasmResult<()>;
|
||||||
|
|
||||||
/// Declares a module type signature to the environment.
|
|
||||||
fn declare_type_module(
|
|
||||||
&mut self,
|
|
||||||
imports: &[(&'data str, Option<&'data str>, EntityType)],
|
|
||||||
exports: &[(&'data str, EntityType)],
|
|
||||||
) -> WasmResult<()> {
|
|
||||||
drop((imports, exports));
|
|
||||||
Err(WasmError::Unsupported("module linking".to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Declares an instance type signature to the environment.
|
|
||||||
fn declare_type_instance(&mut self, exports: &[(&'data str, EntityType)]) -> WasmResult<()> {
|
|
||||||
drop(exports);
|
|
||||||
Err(WasmError::Unsupported("module linking".to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Translates a type index to its signature index, only called for type
|
/// Translates a type index to its signature index, only called for type
|
||||||
/// indices which point to functions.
|
/// indices which point to functions.
|
||||||
fn type_to_signature(&self, index: TypeIndex) -> WasmResult<SignatureIndex> {
|
fn type_to_signature(&self, index: TypeIndex) -> WasmResult<SignatureIndex> {
|
||||||
@@ -565,7 +548,7 @@ pub trait ModuleEnvironment<'data> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
index: TypeIndex,
|
index: TypeIndex,
|
||||||
module: &'data str,
|
module: &'data str,
|
||||||
field: Option<&'data str>,
|
field: &'data str,
|
||||||
) -> WasmResult<()>;
|
) -> WasmResult<()>;
|
||||||
|
|
||||||
/// Declares a table import to the environment.
|
/// Declares a table import to the environment.
|
||||||
@@ -573,7 +556,7 @@ pub trait ModuleEnvironment<'data> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
table: Table,
|
table: Table,
|
||||||
module: &'data str,
|
module: &'data str,
|
||||||
field: Option<&'data str>,
|
field: &'data str,
|
||||||
) -> WasmResult<()>;
|
) -> WasmResult<()>;
|
||||||
|
|
||||||
/// Declares a memory import to the environment.
|
/// Declares a memory import to the environment.
|
||||||
@@ -581,7 +564,7 @@ pub trait ModuleEnvironment<'data> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
memory: Memory,
|
memory: Memory,
|
||||||
module: &'data str,
|
module: &'data str,
|
||||||
field: Option<&'data str>,
|
field: &'data str,
|
||||||
) -> WasmResult<()>;
|
) -> WasmResult<()>;
|
||||||
|
|
||||||
/// Declares an tag import to the environment.
|
/// Declares an tag import to the environment.
|
||||||
@@ -589,7 +572,7 @@ pub trait ModuleEnvironment<'data> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
tag: Tag,
|
tag: Tag,
|
||||||
module: &'data str,
|
module: &'data str,
|
||||||
field: Option<&'data str>,
|
field: &'data str,
|
||||||
) -> WasmResult<()> {
|
) -> WasmResult<()> {
|
||||||
drop((tag, module, field));
|
drop((tag, module, field));
|
||||||
Err(WasmError::Unsupported("wasm tags".to_string()))
|
Err(WasmError::Unsupported("wasm tags".to_string()))
|
||||||
@@ -600,20 +583,9 @@ pub trait ModuleEnvironment<'data> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
global: Global,
|
global: Global,
|
||||||
module: &'data str,
|
module: &'data str,
|
||||||
field: Option<&'data str>,
|
field: &'data str,
|
||||||
) -> WasmResult<()>;
|
) -> WasmResult<()>;
|
||||||
|
|
||||||
/// Declares a module import to the environment.
|
|
||||||
fn declare_module_import(
|
|
||||||
&mut self,
|
|
||||||
ty_index: TypeIndex,
|
|
||||||
module: &'data str,
|
|
||||||
field: Option<&'data str>,
|
|
||||||
) -> WasmResult<()> {
|
|
||||||
drop((ty_index, module, field));
|
|
||||||
Err(WasmError::Unsupported("module linking".to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Notifies the implementation that all imports have been declared.
|
/// Notifies the implementation that all imports have been declared.
|
||||||
fn finish_imports(&mut self) -> WasmResult<()> {
|
fn finish_imports(&mut self) -> WasmResult<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use crate::code_translator::{bitcast_arguments, translate_operator, wasm_param_t
|
|||||||
use crate::environ::{FuncEnvironment, ReturnMode};
|
use crate::environ::{FuncEnvironment, ReturnMode};
|
||||||
use crate::state::FuncTranslationState;
|
use crate::state::FuncTranslationState;
|
||||||
use crate::translation_utils::get_vmctx_value_label;
|
use crate::translation_utils::get_vmctx_value_label;
|
||||||
use crate::wasm_unsupported;
|
|
||||||
use crate::WasmResult;
|
use crate::WasmResult;
|
||||||
use core::convert::TryInto;
|
use core::convert::TryInto;
|
||||||
use cranelift_codegen::entity::EntityRef;
|
use cranelift_codegen::entity::EntityRef;
|
||||||
@@ -206,7 +205,6 @@ fn declare_locals<FE: FuncEnvironment + ?Sized>(
|
|||||||
ExternRef | FuncRef => {
|
ExternRef | FuncRef => {
|
||||||
environ.translate_ref_null(builder.cursor(), wasm_type.try_into()?)?
|
environ.translate_ref_null(builder.cursor(), wasm_type.try_into()?)?
|
||||||
}
|
}
|
||||||
ty => return Err(wasm_unsupported!("unsupported local type {:?}", ty)),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let ty = builder.func.dfg.value_type(zeroval);
|
let ty = builder.func.dfg.value_type(zeroval);
|
||||||
|
|||||||
@@ -20,16 +20,19 @@ pub fn translate_module<'data>(
|
|||||||
) -> WasmResult<ModuleTranslationState> {
|
) -> WasmResult<ModuleTranslationState> {
|
||||||
let _tt = timing::wasm_translate_module();
|
let _tt = timing::wasm_translate_module();
|
||||||
let mut module_translation_state = ModuleTranslationState::new();
|
let mut module_translation_state = ModuleTranslationState::new();
|
||||||
let mut validator = Validator::new();
|
let mut validator = Validator::new_with_features(environ.wasm_features());
|
||||||
validator.wasm_features(environ.wasm_features());
|
|
||||||
|
|
||||||
for payload in Parser::new(0).parse_all(data) {
|
for payload in Parser::new(0).parse_all(data) {
|
||||||
match payload? {
|
match payload? {
|
||||||
Payload::Version { num, range } => {
|
Payload::Version {
|
||||||
validator.version(num, &range)?;
|
num,
|
||||||
|
encoding,
|
||||||
|
range,
|
||||||
|
} => {
|
||||||
|
validator.version(num, encoding, &range)?;
|
||||||
}
|
}
|
||||||
Payload::End => {
|
Payload::End(offset) => {
|
||||||
validator.end()?;
|
validator.end(offset)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Payload::TypeSection(types) => {
|
Payload::TypeSection(types) => {
|
||||||
@@ -88,7 +91,7 @@ pub fn translate_module<'data>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Payload::CodeSectionEntry(body) => {
|
Payload::CodeSectionEntry(body) => {
|
||||||
let func_validator = validator.code_section_entry()?;
|
let func_validator = validator.code_section_entry(&body)?;
|
||||||
environ.define_function_body(func_validator, body)?;
|
environ.define_function_body(func_validator, body)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,28 +107,6 @@ pub fn translate_module<'data>(
|
|||||||
environ.reserve_passive_data(count)?;
|
environ.reserve_passive_data(count)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Payload::InstanceSection(s) => {
|
|
||||||
validator.instance_section(&s)?;
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
Payload::AliasSection(s) => {
|
|
||||||
validator.alias_section(&s)?;
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
Payload::ModuleSectionStart {
|
|
||||||
count,
|
|
||||||
range,
|
|
||||||
size: _,
|
|
||||||
} => {
|
|
||||||
validator.module_section_start(count, &range)?;
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
|
|
||||||
Payload::ModuleSectionEntry { .. } => {
|
|
||||||
validator.module_section_entry();
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
|
|
||||||
Payload::CustomSection {
|
Payload::CustomSection {
|
||||||
name: "name",
|
name: "name",
|
||||||
data,
|
data,
|
||||||
@@ -142,9 +123,9 @@ pub fn translate_module<'data>(
|
|||||||
|
|
||||||
Payload::CustomSection { name, data, .. } => environ.custom_section(name, data)?,
|
Payload::CustomSection { name, data, .. } => environ.custom_section(name, data)?,
|
||||||
|
|
||||||
Payload::UnknownSection { id, range, .. } => {
|
other => {
|
||||||
validator.unknown_section(id, &range)?;
|
validator.payload(&other)?;
|
||||||
unreachable!();
|
panic!("unimplemented section {:?}", other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use crate::environ::ModuleEnvironment;
|
|||||||
use crate::state::ModuleTranslationState;
|
use crate::state::ModuleTranslationState;
|
||||||
use crate::wasm_unsupported;
|
use crate::wasm_unsupported;
|
||||||
use crate::{
|
use crate::{
|
||||||
DataIndex, ElemIndex, EntityType, FuncIndex, Global, GlobalIndex, GlobalInit, Memory,
|
DataIndex, ElemIndex, FuncIndex, Global, GlobalIndex, GlobalInit, Memory, MemoryIndex, Table,
|
||||||
MemoryIndex, Table, TableIndex, Tag, TagIndex, TypeIndex, WasmError, WasmResult,
|
TableIndex, Tag, TagIndex, TypeIndex, WasmError, WasmResult,
|
||||||
};
|
};
|
||||||
use core::convert::TryFrom;
|
use core::convert::TryFrom;
|
||||||
use core::convert::TryInto;
|
use core::convert::TryInto;
|
||||||
@@ -23,31 +23,11 @@ use std::vec::Vec;
|
|||||||
use wasmparser::{
|
use wasmparser::{
|
||||||
self, Data, DataKind, DataSectionReader, Element, ElementItem, ElementItems, ElementKind,
|
self, Data, DataKind, DataSectionReader, Element, ElementItem, ElementItems, ElementKind,
|
||||||
ElementSectionReader, Export, ExportSectionReader, ExternalKind, FunctionSectionReader,
|
ElementSectionReader, Export, ExportSectionReader, ExternalKind, FunctionSectionReader,
|
||||||
GlobalSectionReader, GlobalType, ImportSectionEntryType, ImportSectionReader,
|
GlobalSectionReader, GlobalType, ImportSectionReader, MemorySectionReader, MemoryType,
|
||||||
MemorySectionReader, MemoryType, NameSectionReader, Naming, Operator, TableSectionReader,
|
NameSectionReader, Naming, Operator, TableSectionReader, TableType, TagSectionReader, TagType,
|
||||||
TableType, TagSectionReader, TagType, TypeDef, TypeSectionReader,
|
TypeDef, TypeRef, TypeSectionReader,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn entity_type(
|
|
||||||
ty: ImportSectionEntryType,
|
|
||||||
environ: &mut dyn ModuleEnvironment<'_>,
|
|
||||||
) -> WasmResult<EntityType> {
|
|
||||||
Ok(match ty {
|
|
||||||
ImportSectionEntryType::Function(sig) => {
|
|
||||||
EntityType::Function(environ.type_to_signature(TypeIndex::from_u32(sig))?)
|
|
||||||
}
|
|
||||||
ImportSectionEntryType::Memory(ty) => EntityType::Memory(memory(ty)),
|
|
||||||
ImportSectionEntryType::Tag(t) => EntityType::Tag(tag(t)),
|
|
||||||
ImportSectionEntryType::Global(ty) => EntityType::Global(global(ty, GlobalInit::Import)?),
|
|
||||||
ImportSectionEntryType::Table(ty) => EntityType::Table(table(ty)?),
|
|
||||||
|
|
||||||
// doesn't get past validation
|
|
||||||
ImportSectionEntryType::Module(_) | ImportSectionEntryType::Instance(_) => {
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn memory(ty: MemoryType) -> Memory {
|
fn memory(ty: MemoryType) -> Memory {
|
||||||
Memory {
|
Memory {
|
||||||
minimum: ty.initial,
|
minimum: ty.initial,
|
||||||
@@ -58,8 +38,10 @@ fn memory(ty: MemoryType) -> Memory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn tag(e: TagType) -> Tag {
|
fn tag(e: TagType) -> Tag {
|
||||||
Tag {
|
match e.kind {
|
||||||
ty: TypeIndex::from_u32(e.type_index),
|
wasmparser::TagKind::Exception => Tag {
|
||||||
|
ty: TypeIndex::from_u32(e.func_type_idx),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,27 +79,6 @@ pub fn parse_type_section<'a>(
|
|||||||
.wasm_types
|
.wasm_types
|
||||||
.push((wasm_func_ty.params, wasm_func_ty.returns));
|
.push((wasm_func_ty.params, wasm_func_ty.returns));
|
||||||
}
|
}
|
||||||
TypeDef::Module(t) => {
|
|
||||||
let imports = t
|
|
||||||
.imports
|
|
||||||
.iter()
|
|
||||||
.map(|i| Ok((i.module, i.field, entity_type(i.ty, environ)?)))
|
|
||||||
.collect::<WasmResult<Vec<_>>>()?;
|
|
||||||
let exports = t
|
|
||||||
.exports
|
|
||||||
.iter()
|
|
||||||
.map(|e| Ok((e.name, entity_type(e.ty, environ)?)))
|
|
||||||
.collect::<WasmResult<Vec<_>>>()?;
|
|
||||||
environ.declare_type_module(&imports, &exports)?;
|
|
||||||
}
|
|
||||||
TypeDef::Instance(t) => {
|
|
||||||
let exports = t
|
|
||||||
.exports
|
|
||||||
.iter()
|
|
||||||
.map(|e| Ok((e.name, entity_type(e.ty, environ)?)))
|
|
||||||
.collect::<WasmResult<Vec<_>>>()?;
|
|
||||||
environ.declare_type_instance(&exports)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -133,30 +94,26 @@ pub fn parse_import_section<'data>(
|
|||||||
for entry in imports {
|
for entry in imports {
|
||||||
let import = entry?;
|
let import = entry?;
|
||||||
match import.ty {
|
match import.ty {
|
||||||
ImportSectionEntryType::Function(sig) => {
|
TypeRef::Func(sig) => {
|
||||||
environ.declare_func_import(
|
environ.declare_func_import(
|
||||||
TypeIndex::from_u32(sig),
|
TypeIndex::from_u32(sig),
|
||||||
import.module,
|
import.module,
|
||||||
import.field,
|
import.name,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
ImportSectionEntryType::Memory(ty) => {
|
TypeRef::Memory(ty) => {
|
||||||
environ.declare_memory_import(memory(ty), import.module, import.field)?;
|
environ.declare_memory_import(memory(ty), import.module, import.name)?;
|
||||||
}
|
}
|
||||||
ImportSectionEntryType::Tag(e) => {
|
TypeRef::Tag(e) => {
|
||||||
environ.declare_tag_import(tag(e), import.module, import.field)?;
|
environ.declare_tag_import(tag(e), import.module, import.name)?;
|
||||||
}
|
}
|
||||||
ImportSectionEntryType::Global(ty) => {
|
TypeRef::Global(ty) => {
|
||||||
let ty = global(ty, GlobalInit::Import)?;
|
let ty = global(ty, GlobalInit::Import)?;
|
||||||
environ.declare_global_import(ty, import.module, import.field)?;
|
environ.declare_global_import(ty, import.module, import.name)?;
|
||||||
}
|
}
|
||||||
ImportSectionEntryType::Table(ty) => {
|
TypeRef::Table(ty) => {
|
||||||
let ty = table(ty)?;
|
let ty = table(ty)?;
|
||||||
environ.declare_table_import(ty, import.module, import.field)?;
|
environ.declare_table_import(ty, import.module, import.name)?;
|
||||||
}
|
|
||||||
|
|
||||||
ImportSectionEntryType::Module(_) | ImportSectionEntryType::Instance(_) => {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,7 +236,7 @@ pub fn parse_export_section<'data>(
|
|||||||
|
|
||||||
for entry in exports {
|
for entry in exports {
|
||||||
let Export {
|
let Export {
|
||||||
field,
|
name,
|
||||||
ref kind,
|
ref kind,
|
||||||
index,
|
index,
|
||||||
} = entry?;
|
} = entry?;
|
||||||
@@ -289,18 +246,11 @@ pub fn parse_export_section<'data>(
|
|||||||
// becomes a concern here.
|
// becomes a concern here.
|
||||||
let index = index as usize;
|
let index = index as usize;
|
||||||
match *kind {
|
match *kind {
|
||||||
ExternalKind::Function => environ.declare_func_export(FuncIndex::new(index), field)?,
|
ExternalKind::Func => environ.declare_func_export(FuncIndex::new(index), name)?,
|
||||||
ExternalKind::Table => environ.declare_table_export(TableIndex::new(index), field)?,
|
ExternalKind::Table => environ.declare_table_export(TableIndex::new(index), name)?,
|
||||||
ExternalKind::Memory => {
|
ExternalKind::Memory => environ.declare_memory_export(MemoryIndex::new(index), name)?,
|
||||||
environ.declare_memory_export(MemoryIndex::new(index), field)?
|
ExternalKind::Tag => environ.declare_tag_export(TagIndex::new(index), name)?,
|
||||||
}
|
ExternalKind::Global => environ.declare_global_export(GlobalIndex::new(index), name)?,
|
||||||
ExternalKind::Tag => environ.declare_tag_export(TagIndex::new(index), field)?,
|
|
||||||
ExternalKind::Global => {
|
|
||||||
environ.declare_global_export(GlobalIndex::new(index), field)?
|
|
||||||
}
|
|
||||||
|
|
||||||
// this never gets past validation
|
|
||||||
ExternalKind::Module | ExternalKind::Instance | ExternalKind::Type => unreachable!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ pub enum ControlStackFrame {
|
|||||||
num_return_values: usize,
|
num_return_values: usize,
|
||||||
original_stack_size: usize,
|
original_stack_size: usize,
|
||||||
exit_is_branched_to: bool,
|
exit_is_branched_to: bool,
|
||||||
blocktype: wasmparser::TypeOrFuncType,
|
blocktype: wasmparser::BlockType,
|
||||||
/// Was the head of the `if` reachable?
|
/// Was the head of the `if` reachable?
|
||||||
head_is_reachable: bool,
|
head_is_reachable: bool,
|
||||||
/// What was the reachability at the end of the consequent?
|
/// What was the reachability at the end of the consequent?
|
||||||
@@ -411,7 +411,7 @@ impl FuncTranslationState {
|
|||||||
else_data: ElseData,
|
else_data: ElseData,
|
||||||
num_param_types: usize,
|
num_param_types: usize,
|
||||||
num_result_types: usize,
|
num_result_types: usize,
|
||||||
blocktype: wasmparser::TypeOrFuncType,
|
blocktype: wasmparser::BlockType,
|
||||||
) {
|
) {
|
||||||
debug_assert!(num_param_types <= self.stack.len());
|
debug_assert!(num_param_types <= self.stack.len());
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
//! Helper functions and structures for the translation.
|
//! Helper functions and structures for the translation.
|
||||||
use crate::environ::TargetEnvironment;
|
use crate::environ::TargetEnvironment;
|
||||||
use crate::wasm_unsupported;
|
|
||||||
use crate::WasmResult;
|
use crate::WasmResult;
|
||||||
use core::convert::TryInto;
|
use core::convert::TryInto;
|
||||||
use core::u32;
|
use core::u32;
|
||||||
@@ -34,7 +33,6 @@ pub fn type_to_type<PE: TargetEnvironment + ?Sized>(
|
|||||||
wasmparser::Type::ExternRef | wasmparser::Type::FuncRef => {
|
wasmparser::Type::ExternRef | wasmparser::Type::FuncRef => {
|
||||||
Ok(environ.reference_type(ty.try_into()?))
|
Ok(environ.reference_type(ty.try_into()?))
|
||||||
}
|
}
|
||||||
ty => Err(wasm_unsupported!("type_to_type: wasm type {:?}", ty)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,17 +50,13 @@ pub fn tabletype_to_type<PE: TargetEnvironment + ?Sized>(
|
|||||||
wasmparser::Type::V128 => Ok(Some(ir::types::I8X16)),
|
wasmparser::Type::V128 => Ok(Some(ir::types::I8X16)),
|
||||||
wasmparser::Type::ExternRef => Ok(Some(environ.reference_type(ty.try_into()?))),
|
wasmparser::Type::ExternRef => Ok(Some(environ.reference_type(ty.try_into()?))),
|
||||||
wasmparser::Type::FuncRef => Ok(None),
|
wasmparser::Type::FuncRef => Ok(None),
|
||||||
ty => Err(wasm_unsupported!(
|
|
||||||
"tabletype_to_type: table wasm type {:?}",
|
|
||||||
ty
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the parameter and result types for the given Wasm blocktype.
|
/// Get the parameter and result types for the given Wasm blocktype.
|
||||||
pub fn blocktype_params_results<'a, T>(
|
pub fn blocktype_params_results<'a, T>(
|
||||||
validator: &'a FuncValidator<T>,
|
validator: &'a FuncValidator<T>,
|
||||||
ty_or_ft: wasmparser::TypeOrFuncType,
|
ty: wasmparser::BlockType,
|
||||||
) -> WasmResult<(
|
) -> WasmResult<(
|
||||||
impl ExactSizeIterator<Item = wasmparser::Type> + Clone + 'a,
|
impl ExactSizeIterator<Item = wasmparser::Type> + Clone + 'a,
|
||||||
impl ExactSizeIterator<Item = wasmparser::Type> + Clone + 'a,
|
impl ExactSizeIterator<Item = wasmparser::Type> + Clone + 'a,
|
||||||
@@ -70,26 +64,32 @@ pub fn blocktype_params_results<'a, T>(
|
|||||||
where
|
where
|
||||||
T: WasmModuleResources,
|
T: WasmModuleResources,
|
||||||
{
|
{
|
||||||
return Ok(match ty_or_ft {
|
return Ok(match ty {
|
||||||
wasmparser::TypeOrFuncType::Type(ty) => {
|
wasmparser::BlockType::Empty => {
|
||||||
let (params, results): (&'static [wasmparser::Type], &'static [wasmparser::Type]) =
|
let params: &'static [wasmparser::Type] = &[];
|
||||||
match ty {
|
let results: &'static [wasmparser::Type] = &[];
|
||||||
wasmparser::Type::I32 => (&[], &[wasmparser::Type::I32]),
|
(
|
||||||
wasmparser::Type::I64 => (&[], &[wasmparser::Type::I64]),
|
itertools::Either::Left(params.iter().copied()),
|
||||||
wasmparser::Type::F32 => (&[], &[wasmparser::Type::F32]),
|
itertools::Either::Left(results.iter().copied()),
|
||||||
wasmparser::Type::F64 => (&[], &[wasmparser::Type::F64]),
|
)
|
||||||
wasmparser::Type::V128 => (&[], &[wasmparser::Type::V128]),
|
}
|
||||||
wasmparser::Type::ExternRef => (&[], &[wasmparser::Type::ExternRef]),
|
wasmparser::BlockType::Type(ty) => {
|
||||||
wasmparser::Type::FuncRef => (&[], &[wasmparser::Type::FuncRef]),
|
let params: &'static [wasmparser::Type] = &[];
|
||||||
wasmparser::Type::EmptyBlockType => (&[], &[]),
|
let results: &'static [wasmparser::Type] = match ty {
|
||||||
ty => return Err(wasm_unsupported!("blocktype_params_results: type {:?}", ty)),
|
wasmparser::Type::I32 => &[wasmparser::Type::I32],
|
||||||
|
wasmparser::Type::I64 => &[wasmparser::Type::I64],
|
||||||
|
wasmparser::Type::F32 => &[wasmparser::Type::F32],
|
||||||
|
wasmparser::Type::F64 => &[wasmparser::Type::F64],
|
||||||
|
wasmparser::Type::V128 => &[wasmparser::Type::V128],
|
||||||
|
wasmparser::Type::ExternRef => &[wasmparser::Type::ExternRef],
|
||||||
|
wasmparser::Type::FuncRef => &[wasmparser::Type::FuncRef],
|
||||||
};
|
};
|
||||||
(
|
(
|
||||||
itertools::Either::Left(params.iter().copied()),
|
itertools::Either::Left(params.iter().copied()),
|
||||||
itertools::Either::Left(results.iter().copied()),
|
itertools::Either::Left(results.iter().copied()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
wasmparser::TypeOrFuncType::FuncType(ty_index) => {
|
wasmparser::BlockType::FuncType(ty_index) => {
|
||||||
let ty = validator
|
let ty = validator
|
||||||
.resources()
|
.resources()
|
||||||
.func_type_at(ty_index)
|
.func_type_at(ty_index)
|
||||||
@@ -129,12 +129,6 @@ pub fn block_with_params<PE: TargetEnvironment + ?Sized>(
|
|||||||
wasmparser::Type::V128 => {
|
wasmparser::Type::V128 => {
|
||||||
builder.append_block_param(block, ir::types::I8X16);
|
builder.append_block_param(block, ir::types::I8X16);
|
||||||
}
|
}
|
||||||
ty => {
|
|
||||||
return Err(wasm_unsupported!(
|
|
||||||
"block_with_params: type {:?} in multi-value block's signature",
|
|
||||||
ty
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(block)
|
Ok(block)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ wasmtime = { path = "../wasmtime", default-features = false, features = ['cranel
|
|||||||
wasmtime-c-api-macros = { path = "macros" }
|
wasmtime-c-api-macros = { path = "macros" }
|
||||||
|
|
||||||
# Optional dependency for the `wat2wasm` API
|
# Optional dependency for the `wat2wasm` API
|
||||||
wat = { version = "1.0.36", optional = true }
|
wat = { version = "1.0.42", optional = true }
|
||||||
|
|
||||||
# Optional dependencies for the `wasi` feature
|
# Optional dependencies for the `wasi` feature
|
||||||
wasi-cap-std-sync = { path = "../wasi-common/cap-std-sync", optional = true }
|
wasi-cap-std-sync = { path = "../wasi-common/cap-std-sync", optional = true }
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ cranelift-codegen = { path = "../../cranelift/codegen", version = "0.84.0" }
|
|||||||
cranelift-frontend = { path = "../../cranelift/frontend", version = "0.84.0" }
|
cranelift-frontend = { path = "../../cranelift/frontend", version = "0.84.0" }
|
||||||
cranelift-entity = { path = "../../cranelift/entity", version = "0.84.0" }
|
cranelift-entity = { path = "../../cranelift/entity", version = "0.84.0" }
|
||||||
cranelift-native = { path = "../../cranelift/native", version = "0.84.0" }
|
cranelift-native = { path = "../../cranelift/native", version = "0.84.0" }
|
||||||
wasmparser = "0.83.0"
|
wasmparser = "0.84.0"
|
||||||
target-lexicon = "0.12"
|
target-lexicon = "0.12"
|
||||||
gimli = { version = "0.26.0", default-features = false, features = ['read', 'std'] }
|
gimli = { version = "0.26.0", default-features = false, features = ['read', 'std'] }
|
||||||
object = { version = "0.27.0", default-features = false, features = ['write'] }
|
object = { version = "0.27.0", default-features = false, features = ['write'] }
|
||||||
|
|||||||
@@ -184,7 +184,6 @@ fn value_type(isa: &dyn TargetIsa, ty: WasmType) -> ir::types::Type {
|
|||||||
WasmType::F64 => ir::types::F64,
|
WasmType::F64 => ir::types::F64,
|
||||||
WasmType::V128 => ir::types::I8X16,
|
WasmType::V128 => ir::types::I8X16,
|
||||||
WasmType::FuncRef | WasmType::ExternRef => reference_type(ty, isa.pointer_type()),
|
WasmType::FuncRef | WasmType::ExternRef => reference_type(ty, isa.pointer_type()),
|
||||||
WasmType::ExnRef => unimplemented!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ edition = "2021"
|
|||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
cranelift-entity = { path = "../../cranelift/entity", version = "0.84.0" }
|
cranelift-entity = { path = "../../cranelift/entity", version = "0.84.0" }
|
||||||
wasmtime-types = { path = "../types", version = "0.37.0" }
|
wasmtime-types = { path = "../types", version = "0.37.0" }
|
||||||
wasmparser = "0.83.0"
|
wasmparser = "0.84.0"
|
||||||
indexmap = { version = "1.0.2", features = ["serde-1"] }
|
indexmap = { version = "1.0.2", features = ["serde-1"] }
|
||||||
thiserror = "1.0.4"
|
thiserror = "1.0.4"
|
||||||
serde = { version = "1.0.94", features = ["derive"] }
|
serde = { version = "1.0.94", features = ["derive"] }
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ use std::sync::Arc;
|
|||||||
use wasmparser::Type as WasmType;
|
use wasmparser::Type as WasmType;
|
||||||
use wasmparser::{
|
use wasmparser::{
|
||||||
DataKind, ElementItem, ElementKind, ExternalKind, FuncValidator, FunctionBody,
|
DataKind, ElementItem, ElementKind, ExternalKind, FuncValidator, FunctionBody,
|
||||||
ImportSectionEntryType, NameSectionReader, Naming, Operator, Parser, Payload, TypeDef,
|
NameSectionReader, Naming, Operator, Parser, Payload, TypeDef, TypeRef, Validator,
|
||||||
Validator, ValidatorResources, WasmFeatures,
|
ValidatorResources, WasmFeatures,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Object containing the standalone environment information.
|
/// Object containing the standalone environment information.
|
||||||
@@ -169,8 +169,7 @@ impl<'data> ModuleEnvironment<'data> {
|
|||||||
mut self,
|
mut self,
|
||||||
data: &'data [u8],
|
data: &'data [u8],
|
||||||
) -> WasmResult<(ModuleTranslation<'data>, TypeTables)> {
|
) -> WasmResult<(ModuleTranslation<'data>, TypeTables)> {
|
||||||
let mut validator = Validator::new();
|
let mut validator = Validator::new_with_features(self.features);
|
||||||
validator.wasm_features(self.features);
|
|
||||||
|
|
||||||
for payload in Parser::new(0).parse_all(data) {
|
for payload in Parser::new(0).parse_all(data) {
|
||||||
self.translate_payload(&mut validator, payload?)?;
|
self.translate_payload(&mut validator, payload?)?;
|
||||||
@@ -185,12 +184,16 @@ impl<'data> ModuleEnvironment<'data> {
|
|||||||
payload: Payload<'data>,
|
payload: Payload<'data>,
|
||||||
) -> WasmResult<()> {
|
) -> WasmResult<()> {
|
||||||
match payload {
|
match payload {
|
||||||
Payload::Version { num, range } => {
|
Payload::Version {
|
||||||
validator.version(num, &range)?;
|
num,
|
||||||
|
encoding,
|
||||||
|
range,
|
||||||
|
} => {
|
||||||
|
validator.version(num, encoding, &range)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Payload::End => {
|
Payload::End(offset) => {
|
||||||
validator.end()?;
|
validator.end(offset)?;
|
||||||
|
|
||||||
// With the `escaped_funcs` set of functions finished
|
// With the `escaped_funcs` set of functions finished
|
||||||
// we can calculate the set of signatures that are exported as
|
// we can calculate the set of signatures that are exported as
|
||||||
@@ -223,11 +226,6 @@ impl<'data> ModuleEnvironment<'data> {
|
|||||||
TypeDef::Func(wasm_func_ty) => {
|
TypeDef::Func(wasm_func_ty) => {
|
||||||
self.declare_type_func(wasm_func_ty.try_into()?)?;
|
self.declare_type_func(wasm_func_ty.try_into()?)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// doesn't get past validation
|
|
||||||
TypeDef::Module(_) | TypeDef::Instance(_) => {
|
|
||||||
unreachable!();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -241,35 +239,33 @@ impl<'data> ModuleEnvironment<'data> {
|
|||||||
for entry in imports {
|
for entry in imports {
|
||||||
let import = entry?;
|
let import = entry?;
|
||||||
let ty = match import.ty {
|
let ty = match import.ty {
|
||||||
ImportSectionEntryType::Function(index) => {
|
TypeRef::Func(index) => {
|
||||||
let index = TypeIndex::from_u32(index);
|
let index = TypeIndex::from_u32(index);
|
||||||
let sig_index = self.result.module.types[index].unwrap_function();
|
let sig_index = self.result.module.types[index].unwrap_function();
|
||||||
self.result.module.num_imported_funcs += 1;
|
self.result.module.num_imported_funcs += 1;
|
||||||
self.result.debuginfo.wasm_file.imported_func_count += 1;
|
self.result.debuginfo.wasm_file.imported_func_count += 1;
|
||||||
EntityType::Function(sig_index)
|
EntityType::Function(sig_index)
|
||||||
}
|
}
|
||||||
ImportSectionEntryType::Memory(ty) => {
|
TypeRef::Memory(ty) => {
|
||||||
if ty.shared {
|
if ty.shared {
|
||||||
return Err(WasmError::Unsupported("shared memories".to_owned()));
|
return Err(WasmError::Unsupported("shared memories".to_owned()));
|
||||||
}
|
}
|
||||||
self.result.module.num_imported_memories += 1;
|
self.result.module.num_imported_memories += 1;
|
||||||
EntityType::Memory(ty.into())
|
EntityType::Memory(ty.into())
|
||||||
}
|
}
|
||||||
ImportSectionEntryType::Global(ty) => {
|
TypeRef::Global(ty) => {
|
||||||
self.result.module.num_imported_globals += 1;
|
self.result.module.num_imported_globals += 1;
|
||||||
EntityType::Global(Global::new(ty, GlobalInit::Import)?)
|
EntityType::Global(Global::new(ty, GlobalInit::Import)?)
|
||||||
}
|
}
|
||||||
ImportSectionEntryType::Table(ty) => {
|
TypeRef::Table(ty) => {
|
||||||
self.result.module.num_imported_tables += 1;
|
self.result.module.num_imported_tables += 1;
|
||||||
EntityType::Table(ty.try_into()?)
|
EntityType::Table(ty.try_into()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
// doesn't get past validation
|
// doesn't get past validation
|
||||||
ImportSectionEntryType::Module(_)
|
TypeRef::Tag(_) => unreachable!(),
|
||||||
| ImportSectionEntryType::Instance(_)
|
|
||||||
| ImportSectionEntryType::Tag(_) => unreachable!(),
|
|
||||||
};
|
};
|
||||||
self.declare_import(import.module, import.field.unwrap(), ty);
|
self.declare_import(import.module, import.name, ty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,9 +364,9 @@ impl<'data> ModuleEnvironment<'data> {
|
|||||||
self.result.module.exports.reserve(cnt);
|
self.result.module.exports.reserve(cnt);
|
||||||
|
|
||||||
for entry in exports {
|
for entry in exports {
|
||||||
let wasmparser::Export { field, kind, index } = entry?;
|
let wasmparser::Export { name, kind, index } = entry?;
|
||||||
let entity = match kind {
|
let entity = match kind {
|
||||||
ExternalKind::Function => {
|
ExternalKind::Func => {
|
||||||
let index = FuncIndex::from_u32(index);
|
let index = FuncIndex::from_u32(index);
|
||||||
self.flag_func_escaped(index);
|
self.flag_func_escaped(index);
|
||||||
EntityIndex::Function(index)
|
EntityIndex::Function(index)
|
||||||
@@ -380,15 +376,12 @@ impl<'data> ModuleEnvironment<'data> {
|
|||||||
ExternalKind::Global => EntityIndex::Global(GlobalIndex::from_u32(index)),
|
ExternalKind::Global => EntityIndex::Global(GlobalIndex::from_u32(index)),
|
||||||
|
|
||||||
// this never gets past validation
|
// this never gets past validation
|
||||||
ExternalKind::Module
|
ExternalKind::Tag => unreachable!(),
|
||||||
| ExternalKind::Instance
|
|
||||||
| ExternalKind::Tag
|
|
||||||
| ExternalKind::Type => unreachable!(),
|
|
||||||
};
|
};
|
||||||
self.result
|
self.result
|
||||||
.module
|
.module
|
||||||
.exports
|
.exports
|
||||||
.insert(String::from(field), entity);
|
.insert(String::from(name), entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,7 +495,7 @@ impl<'data> ModuleEnvironment<'data> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Payload::CodeSectionEntry(mut body) => {
|
Payload::CodeSectionEntry(mut body) => {
|
||||||
let validator = validator.code_section_entry()?;
|
let validator = validator.code_section_entry(&body)?;
|
||||||
let func_index =
|
let func_index =
|
||||||
self.result.code_index + self.result.module.num_imported_funcs as u32;
|
self.result.code_index + self.result.module.num_imported_funcs as u32;
|
||||||
let func_index = FuncIndex::from_u32(func_index);
|
let func_index = FuncIndex::from_u32(func_index);
|
||||||
@@ -617,30 +610,6 @@ impl<'data> ModuleEnvironment<'data> {
|
|||||||
// the passive count, do not reserve anything here.
|
// the passive count, do not reserve anything here.
|
||||||
}
|
}
|
||||||
|
|
||||||
Payload::AliasSection(s) => {
|
|
||||||
validator.alias_section(&s)?;
|
|
||||||
unreachable!() // should never get past validation
|
|
||||||
}
|
|
||||||
|
|
||||||
Payload::InstanceSection(s) => {
|
|
||||||
validator.instance_section(&s)?;
|
|
||||||
unreachable!() // should never get past validation
|
|
||||||
}
|
|
||||||
|
|
||||||
Payload::ModuleSectionStart {
|
|
||||||
count,
|
|
||||||
range,
|
|
||||||
size: _,
|
|
||||||
} => {
|
|
||||||
validator.module_section_start(count, &range)?;
|
|
||||||
unreachable!() // should never get past validation
|
|
||||||
}
|
|
||||||
|
|
||||||
Payload::ModuleSectionEntry { .. } => {
|
|
||||||
validator.module_section_entry();
|
|
||||||
unreachable!() // should never get past validation
|
|
||||||
}
|
|
||||||
|
|
||||||
Payload::CustomSection {
|
Payload::CustomSection {
|
||||||
name: "name",
|
name: "name",
|
||||||
data,
|
data,
|
||||||
@@ -683,9 +652,13 @@ and for re-adding support for interface types you can see this issue:
|
|||||||
self.register_dwarf_section(name, data);
|
self.register_dwarf_section(name, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
Payload::UnknownSection { id, range, .. } => {
|
// It's expected that validation will probably reject other
|
||||||
validator.unknown_section(id, &range)?;
|
// payloads such as `UnknownSection` or those related to the
|
||||||
unreachable!();
|
// component model. If, however, something gets past validation then
|
||||||
|
// that's a bug in Wasmtime as we forgot to implement something.
|
||||||
|
other => {
|
||||||
|
validator.payload(&other)?;
|
||||||
|
panic!("unimplemented section in wasm file {:?}", other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ log = "0.4.8"
|
|||||||
rayon = "1.2.1"
|
rayon = "1.2.1"
|
||||||
target-lexicon = "0.12.3"
|
target-lexicon = "0.12.3"
|
||||||
tempfile = "3.3.0"
|
tempfile = "3.3.0"
|
||||||
wasmparser = "0.83.0"
|
wasmparser = "0.84.0"
|
||||||
wasmprinter = "0.2.32"
|
wasmprinter = "0.2.34"
|
||||||
wasmtime = { path = "../wasmtime" }
|
wasmtime = { path = "../wasmtime" }
|
||||||
wasmtime-wast = { path = "../wast" }
|
wasmtime-wast = { path = "../wast" }
|
||||||
wasm-encoder = "0.10.0"
|
wasm-encoder = "0.11.0"
|
||||||
wasm-smith = "0.9.0"
|
wasm-smith = "0.10.0"
|
||||||
wasm-mutate = "0.2"
|
wasm-mutate = "0.2.2"
|
||||||
wasm-spec-interpreter = { path = "./wasm-spec-interpreter", optional = true }
|
wasm-spec-interpreter = { path = "./wasm-spec-interpreter", optional = true }
|
||||||
wasmi = "0.7.0"
|
wasmi = "0.7.0"
|
||||||
|
|
||||||
|
|||||||
@@ -95,9 +95,9 @@ impl TableOps {
|
|||||||
|
|
||||||
// Import the GC function.
|
// Import the GC function.
|
||||||
let mut imports = ImportSection::new();
|
let mut imports = ImportSection::new();
|
||||||
imports.import("", Some("gc"), EntityType::Function(0));
|
imports.import("", "gc", EntityType::Function(0));
|
||||||
imports.import("", Some("take_refs"), EntityType::Function(2));
|
imports.import("", "take_refs", EntityType::Function(2));
|
||||||
imports.import("", Some("make_refs"), EntityType::Function(3));
|
imports.import("", "make_refs", EntityType::Function(3));
|
||||||
|
|
||||||
// Define our table.
|
// Define our table.
|
||||||
let mut tables = TableSection::new();
|
let mut tables = TableSection::new();
|
||||||
@@ -422,10 +422,12 @@ mod tests {
|
|||||||
global.get 0
|
global.get 0
|
||||||
call 1
|
call 1
|
||||||
br 0 (;@1;)
|
br 0 (;@1;)
|
||||||
end)
|
end
|
||||||
|
)
|
||||||
(table (;0;) 20 externref)
|
(table (;0;) 20 externref)
|
||||||
(global (;0;) (mut externref) ref.null extern)
|
(global (;0;) (mut externref) ref.null extern)
|
||||||
(export "run" (func 3)))
|
(export "run" (func 3))
|
||||||
|
)
|
||||||
"#;
|
"#;
|
||||||
eprintln!("expected WAT = {}", expected);
|
eprintln!("expected WAT = {}", expected);
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pretty_env_logger = "0.4.0"
|
|||||||
tempfile = "3.1.0"
|
tempfile = "3.1.0"
|
||||||
os_pipe = "0.9"
|
os_pipe = "0.9"
|
||||||
anyhow = "1.0.19"
|
anyhow = "1.0.19"
|
||||||
wat = "1.0.37"
|
wat = "1.0.42"
|
||||||
cap-std = "0.24.1"
|
cap-std = "0.24.1"
|
||||||
tokio = { version = "1.8.0", features = ["rt-multi-thread"] }
|
tokio = { version = "1.8.0", features = ["rt-multi-thread"] }
|
||||||
|
|
||||||
|
|||||||
@@ -12,4 +12,4 @@ edition = "2021"
|
|||||||
cranelift-entity = { path = "../../cranelift/entity", version = "0.84.0", features = ['enable-serde'] }
|
cranelift-entity = { path = "../../cranelift/entity", version = "0.84.0", features = ['enable-serde'] }
|
||||||
serde = { version = "1.0.94", features = ["derive"] }
|
serde = { version = "1.0.94", features = ["derive"] }
|
||||||
thiserror = "1.0.4"
|
thiserror = "1.0.4"
|
||||||
wasmparser = { version = "0.83.0", default-features = false }
|
wasmparser = { version = "0.84.0", default-features = false }
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ pub enum WasmType {
|
|||||||
FuncRef,
|
FuncRef,
|
||||||
/// ExternRef type
|
/// ExternRef type
|
||||||
ExternRef,
|
ExternRef,
|
||||||
/// ExnRef type
|
|
||||||
ExnRef,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<wasmparser::Type> for WasmType {
|
impl TryFrom<wasmparser::Type> for WasmType {
|
||||||
@@ -45,11 +43,6 @@ impl TryFrom<wasmparser::Type> for WasmType {
|
|||||||
V128 => Ok(WasmType::V128),
|
V128 => Ok(WasmType::V128),
|
||||||
FuncRef => Ok(WasmType::FuncRef),
|
FuncRef => Ok(WasmType::FuncRef),
|
||||||
ExternRef => Ok(WasmType::ExternRef),
|
ExternRef => Ok(WasmType::ExternRef),
|
||||||
ExnRef => Ok(WasmType::ExnRef),
|
|
||||||
EmptyBlockType | Func => Err(WasmError::InvalidWebAssembly {
|
|
||||||
message: "unexpected value type".to_string(),
|
|
||||||
offset: 0,
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,7 +57,6 @@ impl From<WasmType> for wasmparser::Type {
|
|||||||
WasmType::V128 => wasmparser::Type::V128,
|
WasmType::V128 => wasmparser::Type::V128,
|
||||||
WasmType::FuncRef => wasmparser::Type::FuncRef,
|
WasmType::FuncRef => wasmparser::Type::FuncRef,
|
||||||
WasmType::ExternRef => wasmparser::Type::ExternRef,
|
WasmType::ExternRef => wasmparser::Type::ExternRef,
|
||||||
WasmType::ExnRef => wasmparser::Type::ExnRef,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +71,6 @@ impl fmt::Display for WasmType {
|
|||||||
WasmType::V128 => write!(f, "v128"),
|
WasmType::V128 => write!(f, "v128"),
|
||||||
WasmType::ExternRef => write!(f, "externref"),
|
WasmType::ExternRef => write!(f, "externref"),
|
||||||
WasmType::FuncRef => write!(f, "funcref"),
|
WasmType::FuncRef => write!(f, "funcref"),
|
||||||
WasmType::ExnRef => write!(f, "exnref"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -356,8 +347,10 @@ pub struct Tag {
|
|||||||
|
|
||||||
impl From<wasmparser::TagType> for Tag {
|
impl From<wasmparser::TagType> for Tag {
|
||||||
fn from(ty: wasmparser::TagType) -> Tag {
|
fn from(ty: wasmparser::TagType) -> Tag {
|
||||||
Tag {
|
match ty.kind {
|
||||||
ty: TypeIndex::from_u32(ty.type_index),
|
wasmparser::TagKind::Exception => Tag {
|
||||||
|
ty: TypeIndex::from_u32(ty.func_type_idx),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ wasmtime-cache = { path = "../cache", version = "=0.37.0", optional = true }
|
|||||||
wasmtime-fiber = { path = "../fiber", version = "=0.37.0", optional = true }
|
wasmtime-fiber = { path = "../fiber", version = "=0.37.0", optional = true }
|
||||||
wasmtime-cranelift = { path = "../cranelift", version = "=0.37.0", optional = true }
|
wasmtime-cranelift = { path = "../cranelift", version = "=0.37.0", optional = true }
|
||||||
target-lexicon = { version = "0.12.0", default-features = false }
|
target-lexicon = { version = "0.12.0", default-features = false }
|
||||||
wasmparser = "0.83.0"
|
wasmparser = "0.84.0"
|
||||||
anyhow = "1.0.19"
|
anyhow = "1.0.19"
|
||||||
region = "2.2.0"
|
region = "2.2.0"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
cfg-if = "1.0"
|
cfg-if = "1.0"
|
||||||
backtrace = { version = "0.3.61", optional = true }
|
backtrace = { version = "0.3.61", optional = true }
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
wat = { version = "1.0.36", optional = true }
|
wat = { version = "1.0.42", optional = true }
|
||||||
serde = { version = "1.0.94", features = ["derive"] }
|
serde = { version = "1.0.94", features = ["derive"] }
|
||||||
bincode = "1.2.1"
|
bincode = "1.2.1"
|
||||||
indexmap = "1.6"
|
indexmap = "1.6"
|
||||||
|
|||||||
@@ -542,8 +542,7 @@ impl Module {
|
|||||||
///
|
///
|
||||||
/// [binary]: https://webassembly.github.io/spec/core/binary/index.html
|
/// [binary]: https://webassembly.github.io/spec/core/binary/index.html
|
||||||
pub fn validate(engine: &Engine, binary: &[u8]) -> Result<()> {
|
pub fn validate(engine: &Engine, binary: &[u8]) -> Result<()> {
|
||||||
let mut validator = Validator::new();
|
let mut validator = Validator::new_with_features(engine.config().features);
|
||||||
validator.wasm_features(engine.config().features);
|
|
||||||
|
|
||||||
let mut functions = Vec::new();
|
let mut functions = Vec::new();
|
||||||
for payload in Parser::new(0).parse_all(binary) {
|
for payload in Parser::new(0).parse_all(binary) {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ struct WasmFeatures {
|
|||||||
pub reference_types: bool,
|
pub reference_types: bool,
|
||||||
pub multi_value: bool,
|
pub multi_value: bool,
|
||||||
pub bulk_memory: bool,
|
pub bulk_memory: bool,
|
||||||
pub module_linking: bool,
|
pub component_model: bool,
|
||||||
pub simd: bool,
|
pub simd: bool,
|
||||||
pub threads: bool,
|
pub threads: bool,
|
||||||
pub tail_call: bool,
|
pub tail_call: bool,
|
||||||
@@ -78,7 +78,7 @@ impl From<&wasmparser::WasmFeatures> for WasmFeatures {
|
|||||||
reference_types,
|
reference_types,
|
||||||
multi_value,
|
multi_value,
|
||||||
bulk_memory,
|
bulk_memory,
|
||||||
module_linking,
|
component_model,
|
||||||
simd,
|
simd,
|
||||||
threads,
|
threads,
|
||||||
tail_call,
|
tail_call,
|
||||||
@@ -99,7 +99,7 @@ impl From<&wasmparser::WasmFeatures> for WasmFeatures {
|
|||||||
reference_types,
|
reference_types,
|
||||||
multi_value,
|
multi_value,
|
||||||
bulk_memory,
|
bulk_memory,
|
||||||
module_linking,
|
component_model,
|
||||||
simd,
|
simd,
|
||||||
threads,
|
threads,
|
||||||
tail_call,
|
tail_call,
|
||||||
@@ -479,7 +479,7 @@ impl<'a> SerializedModule<'a> {
|
|||||||
reference_types,
|
reference_types,
|
||||||
multi_value,
|
multi_value,
|
||||||
bulk_memory,
|
bulk_memory,
|
||||||
module_linking,
|
component_model,
|
||||||
simd,
|
simd,
|
||||||
threads,
|
threads,
|
||||||
tail_call,
|
tail_call,
|
||||||
@@ -507,9 +507,9 @@ impl<'a> SerializedModule<'a> {
|
|||||||
"WebAssembly bulk memory support",
|
"WebAssembly bulk memory support",
|
||||||
)?;
|
)?;
|
||||||
Self::check_bool(
|
Self::check_bool(
|
||||||
module_linking,
|
component_model,
|
||||||
other.module_linking,
|
other.component_model,
|
||||||
"WebAssembly module linking support",
|
"WebAssembly component model support",
|
||||||
)?;
|
)?;
|
||||||
Self::check_bool(simd, other.simd, "WebAssembly SIMD support")?;
|
Self::check_bool(simd, other.simd, "WebAssembly SIMD support")?;
|
||||||
Self::check_bool(threads, other.threads, "WebAssembly threads support")?;
|
Self::check_bool(threads, other.threads, "WebAssembly threads support")?;
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ impl ValType {
|
|||||||
WasmType::V128 => Self::V128,
|
WasmType::V128 => Self::V128,
|
||||||
WasmType::FuncRef => Self::FuncRef,
|
WasmType::FuncRef => Self::FuncRef,
|
||||||
WasmType::ExternRef => Self::ExternRef,
|
WasmType::ExternRef => Self::ExternRef,
|
||||||
WasmType::ExnRef => unimplemented!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.19"
|
anyhow = "1.0.19"
|
||||||
wasmtime = { path = "../wasmtime", version = "0.37.0", default-features = false, features = ['cranelift'] }
|
wasmtime = { path = "../wasmtime", version = "0.37.0", default-features = false, features = ['cranelift'] }
|
||||||
wast = "39.0.0"
|
wast = "40.0.0"
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
maintenance = { status = "actively-developed" }
|
maintenance = { status = "actively-developed" }
|
||||||
|
|||||||
Reference in New Issue
Block a user