diff --git a/Cargo.lock b/Cargo.lock index 1c52f17cb..66d928d51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -616,18 +616,18 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.91.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc952b310b24444fc14ab8b9cbe3fafd7e7329e3eec84c3a9b11d2b5cf6f3be1" +checksum = "2a2ab4512dfd3a6f4be184403a195f76e81a8a9f9e6c898e19d2dc3ce20e0115" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.91.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e73470419b33011e50dbf0f6439cbccbaabe9381de172da4e1b6efcda4bb8fa7" +checksum = "98b022ed2a5913a38839dfbafe6cf135342661293b08049843362df4301261dc" dependencies = [ "arrayvec 0.7.2", "bumpalo", @@ -647,24 +647,24 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.91.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "911a1872464108a11ac9965c2b079e61bbdf1bc2e0b9001264264add2e12a38f" +checksum = "639307b45434ad112a98f8300c0f0ab085cbefcd767efcdef9ef19d4c0756e74" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.91.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e036f3f07adb24a86fb46e977e8fe03b18bb16b1eada949cf2c48283e5f8a862" +checksum = "278e52e29c53fcf32431ef08406c295699a70306d05a0715c5b1bf50e33a9ab7" [[package]] name = "cranelift-egraph" -version = "0.91.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d6c623f4b5d2a6bad32c403f03765d4484a827eb93ee78f8cb6219ef118fd59" +checksum = "624b54323b06e675293939311943ba82d323bb340468ce1889be5da7932c8d73" dependencies = [ "cranelift-entity", "fxhash", @@ -676,15 +676,15 @@ dependencies = [ [[package]] name = "cranelift-entity" -version = "0.91.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74385eb5e405b3562f0caa7bcc4ab9a93c7958dd5bcd0e910bffb7765eacd6fc" +checksum = "9a59bcbca89c3f1b70b93ab3cbba5e5e0cbf3e63dadb23c7525cb142e21a9d4c" [[package]] name = "cranelift-frontend" -version = "0.91.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a4ac920422ee36bff2c66257fec861765e3d95a125cdf58d8c0f3bba7e40e61" +checksum = "0d70abacb8cfef3dc8ff7e8836e9c1d70f7967dfdac824a4cd5e30223415aca6" dependencies = [ "cranelift-codegen", "hashbrown 0.12.3", @@ -695,9 +695,9 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.91.0" +version = "0.91.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c541263fb37ad2baa53ec8c37218ee5d02fa0984670d9419dedd8002ea68ff08" +checksum = "393bc73c451830ff8dbb3a07f61843d6cb41a084f9996319917c0b291ed785bb" [[package]] name = "crc" @@ -1587,7 +1587,7 @@ dependencies = [ "atomic-polyfill", "hash32", "rustc_version 0.4.0", - "spin 0.9.5", + "spin 0.9.6", "stable_deref_trait", ] @@ -3606,9 +3606,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spin" -version = "0.9.5" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dccf47db1b41fa1573ed27ccf5e08e3ca771cb994f776668c5ebda893b248fc" +checksum = "b5d6e0250b93c8427a177b849d144a96d5acc57006149479403d7861ab721e34" dependencies = [ "lock_api", ] @@ -4763,7 +4763,7 @@ dependencies = [ "wasmer-derive", "wasmer-types", "wasmer-vm", - "wasmparser 0.83.0", + "wasmparser 0.95.0", "wat", "winapi", ] @@ -4940,7 +4940,7 @@ dependencies = [ "wasmer-object", "wasmer-types", "wasmer-vm", - "wasmparser 0.83.0", + "wasmparser 0.95.0", "winapi", ] @@ -5217,6 +5217,7 @@ dependencies = [ "libc", "pin-project-lite", "slab", + "tempfile", "thiserror", "tokio", "tracing", @@ -5435,9 +5436,13 @@ checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" [[package]] name = "wasmparser" -version = "0.83.0" +version = "0.95.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" +checksum = "f2ea896273ea99b15132414be1da01ab0d8836415083298ecaffbe308eaac87a" +dependencies = [ + "indexmap", + "url", +] [[package]] name = "wasmparser" diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index 73e5cd33a..23442c930 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -68,7 +68,7 @@ js-sys = "0.3.51" #web-sys = { version = "0.3.51", features = [ "console" ] } wasmer-derive = { path = "../derive", version = "=3.2.0-alpha.1" } # - Optional dependencies for `js`. -wasmparser = { version = "0.83", default-features = false, optional = true } +wasmparser = { version = "0.95", default-features = false, optional = true } hashbrown = { version = "0.11", optional = true } serde-wasm-bindgen = { version = "0.4.5" } serde = { version = "1.0", features = ["derive"] } diff --git a/lib/api/src/js/module_info_polyfill.rs b/lib/api/src/js/module_info_polyfill.rs index 80f7cccfc..769e427f3 100644 --- a/lib/api/src/js/module_info_polyfill.rs +++ b/lib/api/src/js/module_info_polyfill.rs @@ -14,10 +14,10 @@ use wasmer_types::{ }; use wasmparser::{ - self, BinaryReaderError, Export, ExportSectionReader, ExternalKind, FuncType as WPFunctionType, - FunctionSectionReader, GlobalSectionReader, GlobalType as WPGlobalType, ImportSectionEntryType, - ImportSectionReader, MemorySectionReader, MemoryType as WPMemoryType, NameSectionReader, - Parser, Payload, TableSectionReader, TypeDef, TypeSectionReader, + self, BinaryReaderError, Export, ExportSectionReader, ExternalKind, FunctionSectionReader, + GlobalSectionReader, GlobalType as WPGlobalType, ImportSectionReader, MemorySectionReader, + MemoryType as WPMemoryType, NameSectionReader, Parser, Payload, TableSectionReader, TypeRef, + TypeSectionReader, }; pub type WasmResult = Result; @@ -283,15 +283,17 @@ pub fn translate_module<'data>(data: &'data [u8]) -> WasmResult parse_name_section( - NameSectionReader::new(data, data_offset).map_err(transform_err)?, - &mut module_info, - )?, + Payload::CustomSection(sectionreader) => { + // We still add the custom section data, but also read it as name section reader + let name = sectionreader.name(); + if name == "name" { + parse_name_section( + NameSectionReader::new(sectionreader.data(), sectionreader.data_offset()) + .map_err(transform_err)?, + &mut module_info, + )?; + } + } _ => {} } @@ -301,16 +303,15 @@ pub fn translate_module<'data>(data: &'data [u8]) -> WasmResult WasmResult { +pub fn wptype_to_type(ty: wasmparser::ValType) -> WasmResult { match ty { - wasmparser::Type::I32 => Ok(Type::I32), - wasmparser::Type::I64 => Ok(Type::I64), - wasmparser::Type::F32 => Ok(Type::F32), - wasmparser::Type::F64 => Ok(Type::F64), - wasmparser::Type::V128 => Ok(Type::V128), - wasmparser::Type::ExternRef => Ok(Type::ExternRef), - wasmparser::Type::FuncRef => Ok(Type::FuncRef), - ty => Err(format!("wptype_to_type: wasmparser type {:?}", ty)), + wasmparser::ValType::I32 => Ok(Type::I32), + wasmparser::ValType::I64 => Ok(Type::I64), + wasmparser::ValType::F32 => Ok(Type::F32), + wasmparser::ValType::F64 => Ok(Type::F64), + wasmparser::ValType::V128 => Ok(Type::V128), + wasmparser::ValType::ExternRef => Ok(Type::ExternRef), + wasmparser::ValType::FuncRef => Ok(Type::FuncRef), } } @@ -323,7 +324,9 @@ pub fn parse_type_section( module_info.reserve_signatures(count)?; for entry in types { - if let Ok(TypeDef::Func(WPFunctionType { params, returns })) = entry { + if let Ok(wasmparser::Type::Func(functype)) = entry { + let params = functype.params(); + let returns = functype.results(); let sig_params: Vec = params .iter() .map(|ty| { @@ -358,23 +361,20 @@ pub fn parse_import_section<'data>( for entry in imports { let import = entry.map_err(transform_err)?; let module_name = import.module; - let field_name = import.field; + let field_name = import.name; match import.ty { - ImportSectionEntryType::Function(sig) => { + TypeRef::Func(sig) => { module_info.declare_func_import( SignatureIndex::from_u32(sig), module_name, - field_name.unwrap_or_default(), + field_name, )?; } - ImportSectionEntryType::Module(_) | ImportSectionEntryType::Instance(_) => { - unimplemented!("module linking not implemented yet") - } - ImportSectionEntryType::Tag(_) => { + TypeRef::Tag(_) => { unimplemented!("exception handling not implemented yet") } - ImportSectionEntryType::Memory(WPMemoryType { + TypeRef::Memory(WPMemoryType { shared, memory64, initial, @@ -390,20 +390,20 @@ pub fn parse_import_section<'data>( shared, }, module_name, - field_name.unwrap_or_default(), + field_name, )?; } - ImportSectionEntryType::Global(ref ty) => { + TypeRef::Global(ref ty) => { module_info.declare_global_import( GlobalType { ty: wptype_to_type(ty.content_type).unwrap(), mutability: ty.mutable.into(), }, module_name, - field_name.unwrap_or_default(), + field_name, )?; } - ImportSectionEntryType::Table(ref tab) => { + TypeRef::Table(ref tab) => { module_info.declare_table_import( TableType { ty: wptype_to_type(tab.element_type).unwrap(), @@ -411,7 +411,7 @@ pub fn parse_import_section<'data>( maximum: tab.maximum, }, module_name, - field_name.unwrap_or_default(), + field_name, )?; } } @@ -512,7 +512,7 @@ pub fn parse_export_section<'data>( for entry in exports { let Export { - field, + name, ref kind, index, } = entry.map_err(transform_err)?; @@ -522,20 +522,17 @@ pub fn parse_export_section<'data>( // becomes a concern here. let index = index as usize; match *kind { - ExternalKind::Function => { - module_info.declare_func_export(FunctionIndex::new(index), field)? + ExternalKind::Func => { + module_info.declare_func_export(FunctionIndex::new(index), name)? } ExternalKind::Table => { - module_info.declare_table_export(TableIndex::new(index), field)? + module_info.declare_table_export(TableIndex::new(index), name)? } ExternalKind::Memory => { - module_info.declare_memory_export(MemoryIndex::new(index), field)? + module_info.declare_memory_export(MemoryIndex::new(index), name)? } ExternalKind::Global => { - module_info.declare_global_export(GlobalIndex::new(index), field)? - } - ExternalKind::Type | ExternalKind::Module | ExternalKind::Instance => { - unimplemented!("module linking not implemented yet") + module_info.declare_global_export(GlobalIndex::new(index), name)? } ExternalKind::Tag => { unimplemented!("exception handling not implemented yet") @@ -559,20 +556,20 @@ pub fn parse_name_section<'data>( while let Ok(subsection) = names.read() { match subsection { wasmparser::Name::Function(_function_subsection) => { - // if let Some(function_names) = function_subsection - // .get_map() - // .ok() - // .and_then(parse_function_name_subsection) - // { - // for (index, name) in function_names { - // module_info.declare_function_name(index, name)?; - // } - // } + //for naming in function_subsection.into_iter().flatten() { + // if naming.index != std::u32::MAX { + // environ.declare_function_name( + // FunctionIndex::from_u32(naming.index), + // naming.name, + // )?; + // } + //} } - wasmparser::Name::Module(module) => { - if let Ok(name) = module.get_name() { - module_info.declare_module_name(name)?; - } + wasmparser::Name::Module { + name, + name_range: _, + } => { + module_info.declare_module_name(name)?; } wasmparser::Name::Local(_) => {} wasmparser::Name::Label(_) diff --git a/lib/c-api/src/wasm_c_api/unstable/parser/operator.rs b/lib/c-api/src/wasm_c_api/unstable/parser/operator.rs index 79f9ec6e4..db6424c5d 100644 --- a/lib/c-api/src/wasm_c_api/unstable/parser/operator.rs +++ b/lib/c-api/src/wasm_c_api/unstable/parser/operator.rs @@ -533,6 +533,10 @@ pub enum wasmer_parser_operator_t { F32x4RelaxedMax, F64x2RelaxedMin, F64x2RelaxedMax, + I16x8RelaxedQ15mulrS, + I16x8DotI8x16I7x16S, + I32x4DotI8x16I7x16AddS, + F32x4RelaxedDotBf16x8AddF32x4, } impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t { @@ -1044,8 +1048,8 @@ impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t { O::V128Store16Lane { .. } => Self::V128Store16Lane, O::V128Store32Lane { .. } => Self::V128Store32Lane, O::V128Store64Lane { .. } => Self::V128Store64Lane, - O::I8x16RoundingAverageU => Self::I8x16RoundingAverageU, - O::I16x8RoundingAverageU => Self::I16x8RoundingAverageU, + O::I8x16AvgrU => Self::I8x16RoundingAverageU, + O::I16x8AvgrU => Self::I16x8RoundingAverageU, O::I16x8Q15MulrSatS => Self::I16x8Q15MulrSatS, O::F32x4DemoteF64x2Zero => Self::F32x4DemoteF64x2Zero, O::F64x2PromoteLowF32x4 => Self::F64x2PromoteLowF32x4, @@ -1058,18 +1062,22 @@ impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t { O::I32x4RelaxedTruncSatF32x4U => Self::I32x4RelaxedTruncSatF32x4U, O::I32x4RelaxedTruncSatF64x2SZero => Self::I32x4RelaxedTruncSatF64x2SZero, O::I32x4RelaxedTruncSatF64x2UZero => Self::I32x4RelaxedTruncSatF64x2UZero, - O::F32x4Fma => Self::F32x4Fma, - O::F32x4Fms => Self::F32x4Fms, - O::F64x2Fma => Self::F64x2Fma, - O::F64x2Fms => Self::F64x2Fms, - O::I8x16LaneSelect => Self::I8x16LaneSelect, - O::I16x8LaneSelect => Self::I16x8LaneSelect, - O::I32x4LaneSelect => Self::I32x4LaneSelect, - O::I64x2LaneSelect => Self::I64x2LaneSelect, + O::F32x4RelaxedFma => Self::F32x4Fma, + O::F32x4RelaxedFnma => Self::F32x4Fms, + O::F64x2RelaxedFma => Self::F64x2Fma, + O::F64x2RelaxedFnma => Self::F64x2Fms, + O::I8x16RelaxedLaneselect => Self::I8x16LaneSelect, + O::I16x8RelaxedLaneselect => Self::I16x8LaneSelect, + O::I32x4RelaxedLaneselect => Self::I32x4LaneSelect, + O::I64x2RelaxedLaneselect => Self::I64x2LaneSelect, O::F32x4RelaxedMin => Self::F32x4RelaxedMin, O::F32x4RelaxedMax => Self::F32x4RelaxedMax, O::F64x2RelaxedMin => Self::F64x2RelaxedMin, O::F64x2RelaxedMax => Self::F64x2RelaxedMax, + O::I16x8RelaxedQ15mulrS => Self::I16x8RelaxedQ15mulrS, + O::I16x8DotI8x16I7x16S => Self::I16x8DotI8x16I7x16S, + O::I32x4DotI8x16I7x16AddS => Self::I32x4DotI8x16I7x16AddS, + O::F32x4RelaxedDotBf16x8AddF32x4 => Self::F32x4RelaxedDotBf16x8AddF32x4, } } } diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 2075775fe..3ea888205 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -127,15 +127,15 @@ pub(crate) struct CrossCompile { use_system_linker: bool, /// Cross-compilation library path (path to libwasmer.a / wasmer.lib) - #[clap(long = "library-path", requires = "target")] + #[clap(long = "library-path")] library_path: Option, /// Cross-compilation tarball library path - #[clap(long = "tarball", requires = "target")] + #[clap(long = "tarball")] tarball: Option, /// Specify `zig` binary path (defaults to `zig` in $PATH if not present) - #[clap(long = "zig-binary-path", requires = "target", env)] + #[clap(long = "zig-binary-path", env)] zig_binary_path: Option, } diff --git a/lib/compiler-cranelift/Cargo.toml b/lib/compiler-cranelift/Cargo.toml index 12122ea3c..25967ea43 100644 --- a/lib/compiler-cranelift/Cargo.toml +++ b/lib/compiler-cranelift/Cargo.toml @@ -14,9 +14,9 @@ edition = "2018" [dependencies] wasmer-compiler = { path = "../compiler", version = "=3.2.0-alpha.1", features = ["translator", "compiler"], default-features = false } wasmer-types = { path = "../types", version = "=3.2.0-alpha.1", default-features = false, features = ["std"] } -cranelift-entity = { version = "0.91.0", default-features = false } -cranelift-codegen = { version = "0.91.0", default-features = false, features = ["x86", "arm64"] } -cranelift-frontend = { version = "0.91.0", default-features = false } +cranelift-entity = { version = "0.91.1", default-features = false } +cranelift-codegen = { version = "0.91.1", default-features = false, features = ["x86", "arm64"] } +cranelift-frontend = { version = "0.91.1", default-features = false } tracing = "0.1" hashbrown = { version = "0.11", optional = true } rayon = { version = "1.5", optional = true } @@ -26,7 +26,7 @@ smallvec = "1.6" target-lexicon = { version = "0.12.2", default-features = false } [dev-dependencies] -cranelift-codegen = { version = "0.91.0", features = ["all-arch"] } +cranelift-codegen = { version = "0.91.1", features = ["all-arch"] } lazy_static = "1.4" [badges] diff --git a/lib/compiler-cranelift/src/address_map.rs b/lib/compiler-cranelift/src/address_map.rs index 2fe92429f..088067cfc 100644 --- a/lib/compiler-cranelift/src/address_map.rs +++ b/lib/compiler-cranelift/src/address_map.rs @@ -3,12 +3,12 @@ use cranelift_codegen::Context; use cranelift_codegen::MachSrcLoc; -use wasmer_compiler::wasmparser::Range; +use std::ops::Range; use wasmer_types::{FunctionAddressMap, InstructionAddressMap, SourceLoc}; pub fn get_function_address_map( context: &Context, - range: Range, + range: Range, body_len: usize, ) -> FunctionAddressMap { let mut instructions = Vec::new(); diff --git a/lib/compiler-cranelift/src/func_environ.rs b/lib/compiler-cranelift/src/func_environ.rs index d71153235..98f371cca 100644 --- a/lib/compiler-cranelift/src/func_environ.rs +++ b/lib/compiler-cranelift/src/func_environ.rs @@ -13,7 +13,7 @@ use cranelift_codegen::ir::{AbiParam, ArgumentPurpose, Function, InstBuilder, Si use cranelift_codegen::isa::TargetFrontendConfig; use cranelift_frontend::FunctionBuilder; use std::convert::TryFrom; -use wasmer_compiler::wasmparser::Type; +use wasmer_compiler::wasmparser::ValType; use wasmer_types::entity::EntityRef; use wasmer_types::entity::PrimaryMap; use wasmer_types::VMBuiltinFunctionIndex; @@ -999,11 +999,11 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro fn translate_ref_null( &mut self, mut pos: cranelift_codegen::cursor::FuncCursor, - ty: Type, + ty: ValType, ) -> WasmResult { Ok(match ty { - Type::FuncRef => pos.ins().null(self.reference_type()), - Type::ExternRef => pos.ins().null(self.reference_type()), + ValType::FuncRef => pos.ins().null(self.reference_type()), + ValType::ExternRef => pos.ins().null(self.reference_type()), _ => { return Err(WasmError::Unsupported( "`ref.null T` that is not a `funcref` or an `externref`".into(), diff --git a/lib/compiler-cranelift/src/translator/code_translator.rs b/lib/compiler-cranelift/src/translator/code_translator.rs index fb2de48eb..293283e2b 100644 --- a/lib/compiler-cranelift/src/translator/code_translator.rs +++ b/lib/compiler-cranelift/src/translator/code_translator.rs @@ -92,7 +92,7 @@ use cranelift_frontend::{FunctionBuilder, Variable}; use smallvec::SmallVec; use std::vec::Vec; -use wasmer_compiler::wasmparser::{MemoryImmediate, Operator}; +use wasmer_compiler::wasmparser::{MemArg, Operator}; use wasmer_compiler::{from_binaryreadererror_wasmerror, wasm_unsupported, ModuleTranslationState}; use wasmer_types::{ FunctionIndex, GlobalIndex, MemoryIndex, SignatureIndex, TableIndex, WasmResult, @@ -235,13 +235,13 @@ pub fn translate_operator( * block and have already been translated) and modify the value stack to use the * possible `Block`'s arguments values. ***********************************************************************************/ - Operator::Block { ty } => { - let (params, results) = module_translation_state.blocktype_params_results(*ty)?; + Operator::Block { blockty } => { + let (params, results) = module_translation_state.blocktype_params_results(*blockty)?; let next = block_with_params(builder, results, environ)?; state.push_block(next, params.len(), results.len()); } - Operator::Loop { ty } => { - let (params, results) = module_translation_state.blocktype_params_results(*ty)?; + Operator::Loop { blockty } => { + let (params, results) = module_translation_state.blocktype_params_results(*blockty)?; let loop_body = block_with_params(builder, params, environ)?; let next = block_with_params(builder, results, environ)?; canonicalise_then_jump(builder, loop_body, state.peekn(params.len())); @@ -257,10 +257,10 @@ pub fn translate_operator( builder.switch_to_block(loop_body); environ.translate_loop_header(builder.cursor())?; } - Operator::If { ty } => { + Operator::If { blockty } => { let val = state.pop1(); - let (params, results) = module_translation_state.blocktype_params_results(*ty)?; + let (params, results) = module_translation_state.blocktype_params_results(*blockty)?; let (destination, else_data) = if params == results { // It is possible there is no `else` block, so we will only // allocate a block for it if/when we find the `else`. For now, @@ -293,7 +293,13 @@ pub fn translate_operator( // and we add nothing; // - either the If have an Else clause, in that case the destination of this jump // instruction will be changed later when we translate the Else operator. - state.push_if(destination, else_data, params.len(), results.len(), *ty); + state.push_if( + destination, + else_data, + params.len(), + results.len(), + *blockty, + ); } Operator::Else => { let i = state.control_stack.len() - 1; @@ -433,10 +439,10 @@ pub fn translate_operator( state.reachable = false; } Operator::BrIf { relative_depth } => translate_br_if(*relative_depth, builder, state), - Operator::BrTable { table } => { - let default = table.default(); + Operator::BrTable { targets } => { + let default = targets.default(); let mut min_depth = default; - for depth in table.targets() { + for depth in targets.targets() { let depth = depth.map_err(from_binaryreadererror_wasmerror)?; if depth < min_depth { min_depth = depth; @@ -452,10 +458,10 @@ pub fn translate_operator( } }; let val = state.pop1(); - let mut data = JumpTableData::with_capacity(table.len() as usize); + let mut data = JumpTableData::with_capacity(targets.len() as usize); if jump_args_count == 0 { // No jump arguments - for depth in table.targets() { + for depth in targets.targets() { let depth = depth.map_err(from_binaryreadererror_wasmerror)?; let block = { let i = state.control_stack.len() - 1 - (depth as usize); @@ -479,7 +485,7 @@ pub fn translate_operator( let return_count = jump_args_count; let mut dest_block_sequence = vec![]; let mut dest_block_map = HashMap::new(); - for depth in table.targets() { + for depth in targets.targets() { let depth = depth.map_err(from_binaryreadererror_wasmerror)?; let branch_block = match dest_block_map.entry(depth as usize) { hash_map::Entry::Occupied(entry) => *entry.get(), @@ -580,10 +586,14 @@ pub fn translate_operator( state.popn(num_args); state.pushn(inst_results); } - Operator::CallIndirect { index, table_index } => { + Operator::CallIndirect { + type_index, + table_index, + table_byte: _, + } => { // `index` is the index of the function's signature and `table_index` is the index of // 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, *type_index, environ)?; let table = state.get_or_create_table(builder.func, *table_index, environ)?; let callee = state.pop1(); @@ -596,7 +606,7 @@ pub fn translate_operator( bitcast_arguments(args, &types, builder); let args = state.peekn(num_args); - let sig_idx = SignatureIndex::from_u32(*index); + let sig_idx = SignatureIndex::from_u32(*type_index); let call = environ.translate_call_indirect( builder.cursor(), @@ -1299,11 +1309,11 @@ pub fn translate_operator( Operator::AtomicFence { .. } => { builder.ins().fence(); } - Operator::MemoryCopy { src, dst } => { - let src_index = MemoryIndex::from_u32(*src); - let dst_index = MemoryIndex::from_u32(*dst); - let src_heap = state.get_heap(builder.func, *src, environ)?; - let dst_heap = state.get_heap(builder.func, *dst, environ)?; + Operator::MemoryCopy { dst_mem, src_mem } => { + let src_index = MemoryIndex::from_u32(*src_mem); + let dst_index = MemoryIndex::from_u32(*dst_mem); + let src_heap = state.get_heap(builder.func, *src_mem, environ)?; + let dst_heap = state.get_heap(builder.func, *dst_mem, environ)?; let len = state.pop1(); let src_pos = state.pop1(); let dst_pos = state.pop1(); @@ -1326,7 +1336,7 @@ pub fn translate_operator( let dest = state.pop1(); environ.translate_memory_fill(builder.cursor(), heap_index, heap, dest, val, len)?; } - Operator::MemoryInit { segment, mem } => { + Operator::MemoryInit { data_index, mem } => { let heap_index = MemoryIndex::from_u32(*mem); let heap = state.get_heap(builder.func, *mem, environ)?; let len = state.pop1(); @@ -1336,14 +1346,14 @@ pub fn translate_operator( builder.cursor(), heap_index, heap, - *segment, + *data_index, dest, src, len, )?; } - Operator::DataDrop { segment } => { - environ.translate_data_drop(builder.cursor(), *segment)?; + Operator::DataDrop { data_index } => { + environ.translate_data_drop(builder.cursor(), *data_index)?; } Operator::TableSize { table: index } => { let table = state.get_or_create_table(builder.func, *index, environ)?; @@ -1409,7 +1419,7 @@ pub fn translate_operator( environ.translate_table_fill(builder.cursor(), table_index, dest, val, len)?; } Operator::TableInit { - segment, + elem_index, table: table_index, } => { let table = state.get_or_create_table(builder.func, *table_index, environ)?; @@ -1418,7 +1428,7 @@ pub fn translate_operator( let dest = state.pop1(); environ.translate_table_init( builder.cursor(), - *segment, + *elem_index, TableIndex::from_u32(*table_index), table, dest, @@ -1426,8 +1436,8 @@ pub fn translate_operator( len, )?; } - Operator::ElemDrop { segment } => { - environ.translate_elem_drop(builder.cursor(), *segment)?; + Operator::ElemDrop { elem_index } => { + environ.translate_elem_drop(builder.cursor(), *elem_index)?; } Operator::V128Const { value } => { let data = value.bytes().to_vec().into(); @@ -1590,7 +1600,7 @@ pub fn translate_operator( let (a, b) = pop2_with_bitcast(state, type_of(op), builder); state.push1(builder.ins().umax(a, b)) } - Operator::I8x16RoundingAverageU | Operator::I16x8RoundingAverageU => { + Operator::I8x16AvgrU | Operator::I16x8AvgrU => { let (a, b) = pop2_with_bitcast(state, type_of(op), builder); state.push1(builder.ins().avg_round(a, b)) } @@ -2026,18 +2036,22 @@ pub fn translate_operator( | Operator::I32x4RelaxedTruncSatF32x4U | Operator::I32x4RelaxedTruncSatF64x2SZero | Operator::I32x4RelaxedTruncSatF64x2UZero - | Operator::F32x4Fma - | Operator::F32x4Fms - | Operator::F64x2Fma - | Operator::F64x2Fms - | Operator::I8x16LaneSelect - | Operator::I16x8LaneSelect - | Operator::I32x4LaneSelect - | Operator::I64x2LaneSelect + | Operator::F32x4RelaxedFma + | Operator::F32x4RelaxedFnma + | Operator::F64x2RelaxedFma + | Operator::F64x2RelaxedFnma + | Operator::I8x16RelaxedLaneselect + | Operator::I16x8RelaxedLaneselect + | Operator::I32x4RelaxedLaneselect + | Operator::I64x2RelaxedLaneselect | Operator::F32x4RelaxedMin | Operator::F32x4RelaxedMax | Operator::F64x2RelaxedMin - | Operator::F64x2RelaxedMax => { + | Operator::F64x2RelaxedMax + | Operator::F32x4RelaxedDotBf16x8AddF32x4 + | Operator::I16x8RelaxedQ15mulrS + | Operator::I16x8DotI8x16I7x16S + | Operator::I32x4DotI8x16I7x16AddS => { return Err(wasm_unsupported!("proposed relaxed-simd operator {:?}", op)); } }; @@ -2058,7 +2072,7 @@ fn translate_unreachable_operator( ) -> WasmResult<()> { debug_assert!(!state.reachable); match *op { - Operator::If { ty } => { + Operator::If { blockty } => { // Push a placeholder control stack entry. The if isn't reachable, // so we don't have any branches anywhere. state.push_if( @@ -2068,10 +2082,10 @@ fn translate_unreachable_operator( }, 0, 0, - ty, + blockty, ); } - Operator::Loop { ty: _ } | Operator::Block { ty: _ } => { + Operator::Loop { blockty: _ } | Operator::Block { blockty: _ } => { state.push_block(ir::Block::reserved_value(), 0, 0); } Operator::Else => { @@ -2263,7 +2277,7 @@ fn get_heap_addr( /// Prepare for a load; factors out common functionality between load and load_extend operations. fn prepare_load( - memarg: &MemoryImmediate, + memarg: &MemArg, loaded_bytes: u32, builder: &mut FunctionBuilder, state: &mut FuncTranslationState, @@ -2293,7 +2307,7 @@ fn prepare_load( /// Translate a load instruction. fn translate_load( - memarg: &MemoryImmediate, + memarg: &MemArg, opcode: ir::Opcode, result_ty: Type, builder: &mut FunctionBuilder, @@ -2314,7 +2328,7 @@ fn translate_load( /// Translate a store instruction. fn translate_store( - memarg: &MemoryImmediate, + memarg: &MemArg, opcode: ir::Opcode, builder: &mut FunctionBuilder, state: &mut FuncTranslationState, @@ -2359,7 +2373,7 @@ fn translate_icmp(cc: IntCC, builder: &mut FunctionBuilder, state: &mut FuncTran fn fold_atomic_mem_addr( linear_mem_addr: Value, - memarg: &MemoryImmediate, + memarg: &MemArg, access_ty: Type, builder: &mut FunctionBuilder, ) -> Value { @@ -2393,7 +2407,7 @@ fn fold_atomic_mem_addr( // and then compute the final effective address. fn finalise_atomic_mem_addr( linear_mem_addr: Value, - memarg: &MemoryImmediate, + memarg: &MemArg, access_ty: Type, builder: &mut FunctionBuilder, state: &mut FuncTranslationState, @@ -2445,7 +2459,7 @@ fn translate_atomic_rmw( widened_ty: Type, access_ty: Type, op: AtomicRmwOp, - memarg: &MemoryImmediate, + memarg: &MemArg, builder: &mut FunctionBuilder, state: &mut FuncTranslationState, environ: &mut FE, @@ -2491,7 +2505,7 @@ fn translate_atomic_rmw( fn translate_atomic_cas( widened_ty: Type, access_ty: Type, - memarg: &MemoryImmediate, + memarg: &MemArg, builder: &mut FunctionBuilder, state: &mut FuncTranslationState, environ: &mut FE, @@ -2542,7 +2556,7 @@ fn translate_atomic_cas( fn translate_atomic_load( widened_ty: Type, access_ty: Type, - memarg: &MemoryImmediate, + memarg: &MemArg, builder: &mut FunctionBuilder, state: &mut FuncTranslationState, environ: &mut FE, @@ -2581,7 +2595,7 @@ fn translate_atomic_load( fn translate_atomic_store( access_ty: Type, - memarg: &MemoryImmediate, + memarg: &MemArg, builder: &mut FunctionBuilder, state: &mut FuncTranslationState, environ: &mut FE, @@ -2733,7 +2747,7 @@ fn type_of(operator: &Operator) -> Type { | Operator::I8x16MinU | Operator::I8x16MaxS | Operator::I8x16MaxU - | Operator::I8x16RoundingAverageU + | Operator::I8x16AvgrU | Operator::I8x16Bitmask | Operator::I8x16Popcnt => I8X16, @@ -2770,7 +2784,7 @@ fn type_of(operator: &Operator) -> Type { | Operator::I16x8MinU | Operator::I16x8MaxS | Operator::I16x8MaxU - | Operator::I16x8RoundingAverageU + | Operator::I16x8AvgrU | Operator::I16x8Mul | Operator::I16x8Bitmask => I16X8, diff --git a/lib/compiler-cranelift/src/translator/func_environ.rs b/lib/compiler-cranelift/src/translator/func_environ.rs index 68b3a5c1d..dc0967ef8 100644 --- a/lib/compiler-cranelift/src/translator/func_environ.rs +++ b/lib/compiler-cranelift/src/translator/func_environ.rs @@ -12,7 +12,7 @@ use cranelift_codegen::ir::immediates::Offset32; use cranelift_codegen::ir::{self, InstBuilder}; use cranelift_codegen::isa::TargetFrontendConfig; use cranelift_frontend::FunctionBuilder; -use wasmer_compiler::wasmparser::{Operator, Type}; +use wasmer_compiler::wasmparser::{Operator, ValType}; use wasmer_types::{ FunctionIndex, FunctionType, GlobalIndex, LocalFunctionIndex, MemoryIndex, SignatureIndex, TableIndex, Type as WasmerType, WasmResult, @@ -359,7 +359,7 @@ pub trait FuncEnvironment: TargetEnvironment { /// null sentinel is not a null reference type pointer for your type. If you /// override this method, then you should also override /// `translate_ref_is_null` as well. - fn translate_ref_null(&mut self, pos: FuncCursor, ty: Type) -> WasmResult; + fn translate_ref_null(&mut self, pos: FuncCursor, ty: ValType) -> WasmResult; // { // let _ = ty; // Ok(pos.ins().null(self.reference_type(ty))) diff --git a/lib/compiler-cranelift/src/translator/func_state.rs b/lib/compiler-cranelift/src/translator/func_state.rs index 773ec7810..4b42bb1e5 100644 --- a/lib/compiler-cranelift/src/translator/func_state.rs +++ b/lib/compiler-cranelift/src/translator/func_state.rs @@ -63,7 +63,7 @@ pub enum ControlStackFrame { num_return_values: usize, original_stack_size: usize, exit_is_branched_to: bool, - blocktype: wasmer_compiler::wasmparser::TypeOrFuncType, + blocktype: wasmer_compiler::wasmparser::BlockType, /// Was the head of the `if` reachable? head_is_reachable: bool, /// What was the reachability at the end of the consequent? @@ -419,7 +419,7 @@ impl FuncTranslationState { else_data: ElseData, num_param_types: usize, num_result_types: usize, - blocktype: wasmer_compiler::wasmparser::TypeOrFuncType, + blocktype: wasmer_compiler::wasmparser::BlockType, ) { debug_assert!(num_param_types <= self.stack.len()); diff --git a/lib/compiler-cranelift/src/translator/func_translator.rs b/lib/compiler-cranelift/src/translator/func_translator.rs index 47972a45a..e3263ce57 100644 --- a/lib/compiler-cranelift/src/translator/func_translator.rs +++ b/lib/compiler-cranelift/src/translator/func_translator.rs @@ -16,9 +16,7 @@ use cranelift_codegen::ir::{self, Block, InstBuilder, ValueLabel}; use cranelift_codegen::timing; use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable}; use wasmer_compiler::wasmparser; -use wasmer_compiler::{ - wasm_unsupported, wptype_to_type, FunctionBinaryReader, ModuleTranslationState, -}; +use wasmer_compiler::{wptype_to_type, FunctionBinaryReader, ModuleTranslationState}; use wasmer_types::{LocalFunctionIndex, WasmResult}; /// WebAssembly to Cranelift IR function translator. @@ -181,12 +179,12 @@ fn parse_local_decls( fn declare_locals( builder: &mut FunctionBuilder, count: u32, - wasm_type: wasmparser::Type, + wasm_type: wasmparser::ValType, next_local: &mut usize, environ: &mut FE, ) -> WasmResult<()> { // All locals are initialized to 0. - use wasmparser::Type::*; + use wasmparser::ValType::*; let zeroval = match wasm_type { I32 => builder.ins().iconst(ir::types::I32, 0), I64 => builder.ins().iconst(ir::types::I64, 0), @@ -198,7 +196,6 @@ fn declare_locals( } ExternRef => builder.ins().null(environ.reference_type()), FuncRef => builder.ins().null(environ.reference_type()), - ty => return Err(wasm_unsupported!("unsupported local type {:?}", ty)), }; let wasmer_ty = wptype_to_type(wasm_type).unwrap(); diff --git a/lib/compiler-cranelift/src/translator/translation_utils.rs b/lib/compiler-cranelift/src/translator/translation_utils.rs index db0cc50e4..ecc6beb93 100644 --- a/lib/compiler-cranelift/src/translator/translation_utils.rs +++ b/lib/compiler-cranelift/src/translator/translation_utils.rs @@ -7,7 +7,6 @@ use cranelift_codegen::binemit::Reloc; use cranelift_codegen::ir::{self, AbiParam}; use cranelift_codegen::isa::TargetFrontendConfig; use cranelift_frontend::FunctionBuilder; -use wasmer_compiler::wasm_unsupported; use wasmer_compiler::wasmparser; use wasmer_types::{FunctionType, LibCall, RelocationKind, Type, WasmError, WasmResult}; @@ -92,36 +91,30 @@ pub fn irreloc_to_relocationkind(reloc: Reloc) -> RelocationKind { /// Create a `Block` with the given Wasm parameters. pub fn block_with_params( builder: &mut FunctionBuilder, - params: &[wasmparser::Type], + params: &[wasmparser::ValType], environ: &PE, ) -> WasmResult { let block = builder.create_block(); for ty in params.iter() { match ty { - wasmparser::Type::I32 => { + wasmparser::ValType::I32 => { builder.append_block_param(block, ir::types::I32); } - wasmparser::Type::I64 => { + wasmparser::ValType::I64 => { builder.append_block_param(block, ir::types::I64); } - wasmparser::Type::F32 => { + wasmparser::ValType::F32 => { builder.append_block_param(block, ir::types::F32); } - wasmparser::Type::F64 => { + wasmparser::ValType::F64 => { builder.append_block_param(block, ir::types::F64); } - wasmparser::Type::ExternRef | wasmparser::Type::FuncRef => { + wasmparser::ValType::ExternRef | wasmparser::ValType::FuncRef => { builder.append_block_param(block, environ.reference_type()); } - wasmparser::Type::V128 => { + wasmparser::ValType::V128 => { 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) diff --git a/lib/compiler-llvm/src/translator/code.rs b/lib/compiler-llvm/src/translator/code.rs index cd99c53f2..a311019bc 100644 --- a/lib/compiler-llvm/src/translator/code.rs +++ b/lib/compiler-llvm/src/translator/code.rs @@ -25,7 +25,7 @@ use crate::abi::{get_abi, Abi}; use crate::config::{CompiledKind, LLVM}; use crate::object_file::{load_object_file, CompiledFunction}; use std::convert::TryFrom; -use wasmer_compiler::wasmparser::{MemoryImmediate, Operator}; +use wasmer_compiler::wasmparser::{MemArg, Operator}; use wasmer_compiler::{ from_binaryreadererror_wasmerror, wptype_to_type, FunctionBinaryReader, FunctionBodyData, MiddlewareBinaryReader, ModuleMiddlewareChain, ModuleTranslationState, @@ -1028,7 +1028,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { fn annotate_user_memaccess( &mut self, memory_index: MemoryIndex, - _memarg: &MemoryImmediate, + _memarg: &MemArg, alignment: u32, memaccess: InstructionValue<'ctx>, ) -> Result<(), CompileError> { @@ -1051,7 +1051,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { fn resolve_memory_ptr( &mut self, memory_index: MemoryIndex, - memarg: &MemoryImmediate, + memarg: &MemArg, ptr_ty: PointerType<'ctx>, var_offset: IntValue<'ctx>, value_size: usize, @@ -1174,7 +1174,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .into_pointer_value()) } - fn trap_if_misaligned(&self, _memarg: &MemoryImmediate, ptr: PointerValue<'ctx>, align: u8) { + fn trap_if_misaligned(&self, _memarg: &MemArg, ptr: PointerValue<'ctx>, align: u8) { if align <= 1 { return; } @@ -1394,7 +1394,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { if !self.state.reachable { match op { - Operator::Block { ty: _ } | Operator::Loop { ty: _ } | Operator::If { ty: _ } => { + Operator::Block { blockty: _ } + | Operator::Loop { blockty: _ } + | Operator::If { blockty: _ } => { self.unreachable_depth += 1; return Ok(()); } @@ -1420,7 +1422,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { * Control Flow instructions. * https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#control-flow-instructions ***************************/ - Operator::Block { ty } => { + Operator::Block { blockty } => { let current_block = self .builder .get_insert_block() @@ -1431,7 +1433,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let phis: SmallVec<[PhiValue<'ctx>; 1]> = self .module_translation - .blocktype_params_results(ty)? + .blocktype_params_results(blockty)? .1 .iter() .map(|&wp_ty| { @@ -1447,7 +1449,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.state.push_block(end_block, phis); self.builder.position_at_end(current_block); } - Operator::Loop { ty } => { + Operator::Loop { blockty } => { let loop_body = self.context.append_basic_block(self.function, "loop_body"); let loop_next = self.context.append_basic_block(self.function, "loop_outer"); let pre_loop_block = self.builder.get_insert_block().unwrap(); @@ -1455,7 +1457,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.builder.build_unconditional_branch(loop_body); self.builder.position_at_end(loop_next); - let blocktypes = self.module_translation.blocktype_params_results(ty)?; + let blocktypes = self.module_translation.blocktype_params_results(blockty)?; let phis = blocktypes .1 .iter() @@ -1592,7 +1594,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .build_conditional_branch(cond_value, *frame.br_dest(), else_block); self.builder.position_at_end(else_block); } - Operator::BrTable { ref table } => { + Operator::BrTable { ref targets } => { let current_block = self .builder .get_insert_block() @@ -1600,7 +1602,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let index = self.state.pop1()?; - let default_frame = self.state.frame_at_depth(table.default())?; + let default_frame = self.state.frame_at_depth(targets.default())?; let phis = if default_frame.is_loop() { default_frame.loop_body_phis() @@ -1613,7 +1615,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { phi.add_incoming(&[(value, current_block)]); } - let cases: Vec<_> = table + let cases: Vec<_> = targets .targets() .enumerate() .map(|(case_index, depth)| { @@ -1649,7 +1651,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.state.popn(args_len)?; self.state.reachable = false; } - Operator::If { ty } => { + Operator::If { blockty } => { let current_block = self .builder .get_insert_block() @@ -1663,7 +1665,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let phis = self .module_translation - .blocktype_params_results(ty)? + .blocktype_params_results(blockty)? .1 .iter() .map(|&wp_ty| { @@ -1694,7 +1696,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.builder.position_at_end(if_else_block); let block_param_types = self .module_translation - .blocktype_params_results(ty)? + .blocktype_params_results(blockty)? .0 .iter() .map(|&wp_ty| { @@ -2268,8 +2270,12 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .iter() .for_each(|ret| self.state.push1(*ret)); } - Operator::CallIndirect { index, table_index } => { - let sigindex = SignatureIndex::from_u32(index); + Operator::CallIndirect { + type_index, + table_index, + table_byte: _, + } => { + let sigindex = SignatureIndex::from_u32(type_index); let func_type = &self.wasm_module.signatures[sigindex]; let expected_dynamic_sigindex = self.ctx @@ -3946,7 +3952,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } - Operator::I8x16RoundingAverageU => { + Operator::I8x16AvgrU => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i8x16(v1, i1); let (v2, _) = self.v128_into_i8x16(v2, i2); @@ -3977,7 +3983,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } - Operator::I16x8RoundingAverageU => { + Operator::I16x8AvgrU => { let ((v1, i1), (v2, i2)) = self.state.pop2_extra()?; let (v1, _) = self.v128_into_i16x8(v1, i1); let (v2, _) = self.v128_into_i16x8(v2, i2); @@ -8945,7 +8951,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } - Operator::AtomicFence { flags: _ } => { + Operator::AtomicFence => { // Fence is a nop. // // Fence was added to preserve information about fences from @@ -10946,10 +10952,10 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { size.add_attribute(AttributeLoc::Function, self.intrinsics.readonly); self.state.push1(size.try_as_basic_value().left().unwrap()); } - Operator::MemoryInit { segment, mem } => { + Operator::MemoryInit { data_index, mem } => { let (dest, src, len) = self.state.pop3()?; let mem = self.intrinsics.i32_ty.const_int(mem.into(), false); - let segment = self.intrinsics.i32_ty.const_int(segment.into(), false); + let segment = self.intrinsics.i32_ty.const_int(data_index.into(), false); self.builder.build_call( self.intrinsics.memory_init, &[ @@ -10963,24 +10969,24 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { "", ); } - Operator::DataDrop { segment } => { - let segment = self.intrinsics.i32_ty.const_int(segment.into(), false); + Operator::DataDrop { data_index } => { + let segment = self.intrinsics.i32_ty.const_int(data_index.into(), false); self.builder.build_call( self.intrinsics.data_drop, &[vmctx.as_basic_value_enum().into(), segment.into()], "", ); } - Operator::MemoryCopy { src, dst } => { + Operator::MemoryCopy { dst_mem, src_mem } => { // ignored until we support multiple memories - let _dst = dst; + let _dst = dst_mem; let (memory_copy, src) = if let Some(local_memory_index) = self .wasm_module - .local_memory_index(MemoryIndex::from_u32(src)) + .local_memory_index(MemoryIndex::from_u32(src_mem)) { (self.intrinsics.memory_copy, local_memory_index.as_u32()) } else { - (self.intrinsics.imported_memory_copy, src) + (self.intrinsics.imported_memory_copy, src_mem) }; let (dest_pos, src_pos, len) = self.state.pop3()?; @@ -11137,9 +11143,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { "", ); } - Operator::TableInit { segment, table } => { + Operator::TableInit { elem_index, table } => { let (dst, src, len) = self.state.pop3()?; - let segment = self.intrinsics.i32_ty.const_int(segment as u64, false); + let segment = self.intrinsics.i32_ty.const_int(elem_index as u64, false); let table = self.intrinsics.i32_ty.const_int(table as u64, false); self.builder.build_call( self.intrinsics.table_init, @@ -11154,8 +11160,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { "", ); } - Operator::ElemDrop { segment } => { - let segment = self.intrinsics.i32_ty.const_int(segment as u64, false); + Operator::ElemDrop { elem_index } => { + let segment = self.intrinsics.i32_ty.const_int(elem_index as u64, false); self.builder.build_call( self.intrinsics.elem_drop, &[self.ctx.basic().into(), segment.into()], diff --git a/lib/compiler-singlepass/src/codegen.rs b/lib/compiler-singlepass/src/codegen.rs index 9b24e3be6..56744557d 100644 --- a/lib/compiler-singlepass/src/codegen.rs +++ b/lib/compiler-singlepass/src/codegen.rs @@ -11,7 +11,7 @@ use gimli::write::Address; use smallvec::{smallvec, SmallVec}; use std::cmp; use std::iter; -use wasmer_compiler::wasmparser::{Operator, Type as WpType, TypeOrFuncType as WpTypeOrFuncType}; +use wasmer_compiler::wasmparser::{BlockType as WpTypeOrFuncType, Operator, ValType as WpType}; use wasmer_compiler::FunctionBodyData; #[cfg(feature = "unwind")] use wasmer_types::CompiledFunctionUnwindInfo; @@ -2711,11 +2711,15 @@ impl<'a, M: Machine> FuncGen<'a, M> { } } } - Operator::CallIndirect { index, table_index } => { + Operator::CallIndirect { + type_index, + table_index, + table_byte: _, + } => { // TODO: removed restriction on always being table idx 0; // does any code depend on this? let table_index = TableIndex::new(table_index as _); - let index = SignatureIndex::new(index as usize); + let index = SignatureIndex::new(type_index as usize); let sig = self.module.signatures.get(index).unwrap(); let param_types: SmallVec<[WpType; 8]> = sig.params().iter().cloned().map(type_to_wp_type).collect(); @@ -2936,7 +2940,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { } } } - Operator::If { ty } => { + Operator::If { blockty } => { let label_end = self.machine.get_label(); let label_else = self.machine.get_label(); @@ -2946,8 +2950,8 @@ impl<'a, M: Machine> FuncGen<'a, M> { label: label_end, loop_like: false, if_else: IfElseState::If(label_else), - returns: match ty { - WpTypeOrFuncType::Type(WpType::EmptyBlockType) => smallvec![], + returns: match blockty { + WpTypeOrFuncType::Empty => smallvec![], WpTypeOrFuncType::Type(inner_ty) => smallvec![inner_ty], _ => { return Err(CompileError::Codegen( @@ -3064,13 +3068,13 @@ impl<'a, M: Machine> FuncGen<'a, M> { } self.machine.emit_label(end_label)?; } - Operator::Block { ty } => { + Operator::Block { blockty } => { let frame = ControlFrame { label: self.machine.get_label(), loop_like: false, if_else: IfElseState::None, - returns: match ty { - WpTypeOrFuncType::Type(WpType::EmptyBlockType) => smallvec![], + returns: match blockty { + WpTypeOrFuncType::Empty => smallvec![], WpTypeOrFuncType::Type(inner_ty) => smallvec![inner_ty], _ => { return Err(CompileError::Codegen( @@ -3085,7 +3089,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { }; self.control_stack.push(frame); } - Operator::Loop { ty } => { + Operator::Loop { blockty } => { self.machine.align_for_loop()?; let label = self.machine.get_label(); let state_diff_id = self.get_state_diff(); @@ -3095,8 +3099,8 @@ impl<'a, M: Machine> FuncGen<'a, M> { label, loop_like: true, if_else: IfElseState::None, - returns: match ty { - WpTypeOrFuncType::Type(WpType::EmptyBlockType) => smallvec![], + returns: match blockty { + WpTypeOrFuncType::Empty => smallvec![], WpTypeOrFuncType::Type(inner_ty) => smallvec![inner_ty], _ => { return Err(CompileError::Codegen( @@ -3150,7 +3154,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { ret, )?; } - Operator::MemoryInit { segment, mem } => { + Operator::MemoryInit { data_index, mem } => { let len = self.value_stack.pop().unwrap(); let src = self.value_stack.pop().unwrap(); let dst = self.value_stack.pop().unwrap(); @@ -3175,10 +3179,10 @@ impl<'a, M: Machine> FuncGen<'a, M> { this.machine .emit_call_register(this.machine.get_grp_for_call()) }, - // [vmctx, memory_index, segment_index, dst, src, len] + // [vmctx, memory_index, data_index, dst, src, len] [ Location::Imm32(mem), - Location::Imm32(segment), + Location::Imm32(data_index), dst, src, len, @@ -3197,7 +3201,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { )?; self.release_locations_only_stack(&[dst, src, len])?; } - Operator::DataDrop { segment } => { + Operator::DataDrop { data_index } => { self.machine.move_location( Size::S64, Location::Memory( @@ -3214,20 +3218,20 @@ impl<'a, M: Machine> FuncGen<'a, M> { this.machine .emit_call_register(this.machine.get_grp_for_call()) }, - // [vmctx, segment_index] - iter::once(Location::Imm32(segment)), + // [vmctx, data_index] + iter::once(Location::Imm32(data_index)), iter::once(WpType::I64), )?; } - Operator::MemoryCopy { src, dst } => { + Operator::MemoryCopy { dst_mem, src_mem } => { // ignore until we support multiple memories - let _dst = dst; + let _dst = dst_mem; let len = self.value_stack.pop().unwrap(); let src_pos = self.value_stack.pop().unwrap(); let dst_pos = self.value_stack.pop().unwrap(); self.release_locations_only_regs(&[len, src_pos, dst_pos])?; - let memory_index = MemoryIndex::new(src as usize); + let memory_index = MemoryIndex::new(src_mem as usize); let (memory_copy_index, memory_index) = if self.module.local_memory_index(memory_index).is_some() { ( @@ -4066,12 +4070,12 @@ impl<'a, M: Machine> FuncGen<'a, M> { self.machine.emit_label(after)?; } - Operator::BrTable { ref table } => { - let targets = table + Operator::BrTable { ref targets } => { + let default_target = targets.default(); + let targets = targets .targets() .collect::, _>>() .map_err(|e| CompileError::Codegen(format!("BrTable read_table: {:?}", e)))?; - let default_target = table.default(); let cond = self.pop_value_released()?; let table_label = self.machine.get_label(); let mut table: Vec