diff --git a/Cargo.lock b/Cargo.lock index 66d928d5164..c8233284dee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4763,7 +4763,7 @@ dependencies = [ "wasmer-derive", "wasmer-types", "wasmer-vm", - "wasmparser 0.95.0", + "wasmparser 0.83.0", "wat", "winapi", ] @@ -4940,7 +4940,7 @@ dependencies = [ "wasmer-object", "wasmer-types", "wasmer-vm", - "wasmparser 0.95.0", + "wasmparser 0.83.0", "winapi", ] @@ -5436,13 +5436,9 @@ checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" [[package]] name = "wasmparser" -version = "0.95.0" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ea896273ea99b15132414be1da01ab0d8836415083298ecaffbe308eaac87a" -dependencies = [ - "indexmap", - "url", -] +checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" [[package]] name = "wasmparser" diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index 23442c930b1..73e5cd33a26 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.95", default-features = false, optional = true } +wasmparser = { version = "0.83", 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 769e427f326..80f7cccfc21 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, FunctionSectionReader, - GlobalSectionReader, GlobalType as WPGlobalType, ImportSectionReader, MemorySectionReader, - MemoryType as WPMemoryType, NameSectionReader, Parser, Payload, TableSectionReader, TypeRef, - TypeSectionReader, + 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, }; pub type WasmResult = Result; @@ -283,17 +283,15 @@ pub fn translate_module<'data>(data: &'data [u8]) -> WasmResult { - // 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, - )?; - } - } + Payload::CustomSection { + name: "name", + data, + data_offset, + .. + } => parse_name_section( + NameSectionReader::new(data, data_offset).map_err(transform_err)?, + &mut module_info, + )?, _ => {} } @@ -303,15 +301,16 @@ pub fn translate_module<'data>(data: &'data [u8]) -> WasmResult WasmResult { +pub fn wptype_to_type(ty: wasmparser::Type) -> WasmResult { match 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), + 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)), } } @@ -324,9 +323,7 @@ pub fn parse_type_section( module_info.reserve_signatures(count)?; for entry in types { - if let Ok(wasmparser::Type::Func(functype)) = entry { - let params = functype.params(); - let returns = functype.results(); + if let Ok(TypeDef::Func(WPFunctionType { params, returns })) = entry { let sig_params: Vec = params .iter() .map(|ty| { @@ -361,20 +358,23 @@ 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.name; + let field_name = import.field; match import.ty { - TypeRef::Func(sig) => { + ImportSectionEntryType::Function(sig) => { module_info.declare_func_import( SignatureIndex::from_u32(sig), module_name, - field_name, + field_name.unwrap_or_default(), )?; } - TypeRef::Tag(_) => { + ImportSectionEntryType::Module(_) | ImportSectionEntryType::Instance(_) => { + unimplemented!("module linking not implemented yet") + } + ImportSectionEntryType::Tag(_) => { unimplemented!("exception handling not implemented yet") } - TypeRef::Memory(WPMemoryType { + ImportSectionEntryType::Memory(WPMemoryType { shared, memory64, initial, @@ -390,20 +390,20 @@ pub fn parse_import_section<'data>( shared, }, module_name, - field_name, + field_name.unwrap_or_default(), )?; } - TypeRef::Global(ref ty) => { + ImportSectionEntryType::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, + field_name.unwrap_or_default(), )?; } - TypeRef::Table(ref tab) => { + ImportSectionEntryType::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, + field_name.unwrap_or_default(), )?; } } @@ -512,7 +512,7 @@ pub fn parse_export_section<'data>( for entry in exports { let Export { - name, + field, ref kind, index, } = entry.map_err(transform_err)?; @@ -522,17 +522,20 @@ pub fn parse_export_section<'data>( // becomes a concern here. let index = index as usize; match *kind { - ExternalKind::Func => { - module_info.declare_func_export(FunctionIndex::new(index), name)? + ExternalKind::Function => { + module_info.declare_func_export(FunctionIndex::new(index), field)? } ExternalKind::Table => { - module_info.declare_table_export(TableIndex::new(index), name)? + module_info.declare_table_export(TableIndex::new(index), field)? } ExternalKind::Memory => { - module_info.declare_memory_export(MemoryIndex::new(index), name)? + module_info.declare_memory_export(MemoryIndex::new(index), field)? } ExternalKind::Global => { - module_info.declare_global_export(GlobalIndex::new(index), name)? + module_info.declare_global_export(GlobalIndex::new(index), field)? + } + ExternalKind::Type | ExternalKind::Module | ExternalKind::Instance => { + unimplemented!("module linking not implemented yet") } ExternalKind::Tag => { unimplemented!("exception handling not implemented yet") @@ -556,20 +559,20 @@ pub fn parse_name_section<'data>( while let Ok(subsection) = names.read() { match subsection { wasmparser::Name::Function(_function_subsection) => { - //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, - // )?; - // } - //} + // 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)?; + // } + // } } - wasmparser::Name::Module { - name, - name_range: _, - } => { - module_info.declare_module_name(name)?; + wasmparser::Name::Module(module) => { + if let Ok(name) = module.get_name() { + 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 db6424c5d96..79f9ec6e40a 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,10 +533,6 @@ pub enum wasmer_parser_operator_t { F32x4RelaxedMax, F64x2RelaxedMin, F64x2RelaxedMax, - I16x8RelaxedQ15mulrS, - I16x8DotI8x16I7x16S, - I32x4DotI8x16I7x16AddS, - F32x4RelaxedDotBf16x8AddF32x4, } impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t { @@ -1048,8 +1044,8 @@ impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t { O::V128Store16Lane { .. } => Self::V128Store16Lane, O::V128Store32Lane { .. } => Self::V128Store32Lane, O::V128Store64Lane { .. } => Self::V128Store64Lane, - O::I8x16AvgrU => Self::I8x16RoundingAverageU, - O::I16x8AvgrU => Self::I16x8RoundingAverageU, + O::I8x16RoundingAverageU => Self::I8x16RoundingAverageU, + O::I16x8RoundingAverageU => Self::I16x8RoundingAverageU, O::I16x8Q15MulrSatS => Self::I16x8Q15MulrSatS, O::F32x4DemoteF64x2Zero => Self::F32x4DemoteF64x2Zero, O::F64x2PromoteLowF32x4 => Self::F64x2PromoteLowF32x4, @@ -1062,22 +1058,18 @@ impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t { O::I32x4RelaxedTruncSatF32x4U => Self::I32x4RelaxedTruncSatF32x4U, O::I32x4RelaxedTruncSatF64x2SZero => Self::I32x4RelaxedTruncSatF64x2SZero, O::I32x4RelaxedTruncSatF64x2UZero => Self::I32x4RelaxedTruncSatF64x2UZero, - 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::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::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/compiler-cranelift/src/address_map.rs b/lib/compiler-cranelift/src/address_map.rs index 088067cfcd4..2fe92429fd7 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 std::ops::Range; +use wasmer_compiler::wasmparser::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 98f371cca3c..d71153235b8 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::ValType; +use wasmer_compiler::wasmparser::Type; 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: ValType, + ty: Type, ) -> WasmResult { Ok(match ty { - ValType::FuncRef => pos.ins().null(self.reference_type()), - ValType::ExternRef => pos.ins().null(self.reference_type()), + Type::FuncRef => pos.ins().null(self.reference_type()), + Type::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 293283e2b77..fb2de48eb27 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::{MemArg, Operator}; +use wasmer_compiler::wasmparser::{MemoryImmediate, 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 { blockty } => { - let (params, results) = module_translation_state.blocktype_params_results(*blockty)?; + Operator::Block { ty } => { + let (params, results) = module_translation_state.blocktype_params_results(*ty)?; let next = block_with_params(builder, results, environ)?; state.push_block(next, params.len(), results.len()); } - Operator::Loop { blockty } => { - let (params, results) = module_translation_state.blocktype_params_results(*blockty)?; + Operator::Loop { ty } => { + let (params, results) = module_translation_state.blocktype_params_results(*ty)?; 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 { blockty } => { + Operator::If { ty } => { let val = state.pop1(); - let (params, results) = module_translation_state.blocktype_params_results(*blockty)?; + let (params, results) = module_translation_state.blocktype_params_results(*ty)?; 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,13 +293,7 @@ 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(), - *blockty, - ); + state.push_if(destination, else_data, params.len(), results.len(), *ty); } Operator::Else => { let i = state.control_stack.len() - 1; @@ -439,10 +433,10 @@ pub fn translate_operator( state.reachable = false; } Operator::BrIf { relative_depth } => translate_br_if(*relative_depth, builder, state), - Operator::BrTable { targets } => { - let default = targets.default(); + Operator::BrTable { table } => { + let default = table.default(); let mut min_depth = default; - for depth in targets.targets() { + for depth in table.targets() { let depth = depth.map_err(from_binaryreadererror_wasmerror)?; if depth < min_depth { min_depth = depth; @@ -458,10 +452,10 @@ pub fn translate_operator( } }; let val = state.pop1(); - let mut data = JumpTableData::with_capacity(targets.len() as usize); + let mut data = JumpTableData::with_capacity(table.len() as usize); if jump_args_count == 0 { // No jump arguments - for depth in targets.targets() { + for depth in table.targets() { let depth = depth.map_err(from_binaryreadererror_wasmerror)?; let block = { let i = state.control_stack.len() - 1 - (depth as usize); @@ -485,7 +479,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 targets.targets() { + for depth in table.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(), @@ -586,14 +580,10 @@ pub fn translate_operator( state.popn(num_args); state.pushn(inst_results); } - Operator::CallIndirect { - type_index, - table_index, - table_byte: _, - } => { + Operator::CallIndirect { index, table_index } => { // `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, *type_index, environ)?; + let (sigref, num_args) = state.get_indirect_sig(builder.func, *index, environ)?; let table = state.get_or_create_table(builder.func, *table_index, environ)?; let callee = state.pop1(); @@ -606,7 +596,7 @@ pub fn translate_operator( bitcast_arguments(args, &types, builder); let args = state.peekn(num_args); - let sig_idx = SignatureIndex::from_u32(*type_index); + let sig_idx = SignatureIndex::from_u32(*index); let call = environ.translate_call_indirect( builder.cursor(), @@ -1309,11 +1299,11 @@ pub fn translate_operator( Operator::AtomicFence { .. } => { builder.ins().fence(); } - 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)?; + 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)?; let len = state.pop1(); let src_pos = state.pop1(); let dst_pos = state.pop1(); @@ -1336,7 +1326,7 @@ pub fn translate_operator( let dest = state.pop1(); environ.translate_memory_fill(builder.cursor(), heap_index, heap, dest, val, len)?; } - Operator::MemoryInit { data_index, mem } => { + Operator::MemoryInit { segment, mem } => { let heap_index = MemoryIndex::from_u32(*mem); let heap = state.get_heap(builder.func, *mem, environ)?; let len = state.pop1(); @@ -1346,14 +1336,14 @@ pub fn translate_operator( builder.cursor(), heap_index, heap, - *data_index, + *segment, dest, src, len, )?; } - Operator::DataDrop { data_index } => { - environ.translate_data_drop(builder.cursor(), *data_index)?; + Operator::DataDrop { segment } => { + environ.translate_data_drop(builder.cursor(), *segment)?; } Operator::TableSize { table: index } => { let table = state.get_or_create_table(builder.func, *index, environ)?; @@ -1419,7 +1409,7 @@ pub fn translate_operator( environ.translate_table_fill(builder.cursor(), table_index, dest, val, len)?; } Operator::TableInit { - elem_index, + segment, table: table_index, } => { let table = state.get_or_create_table(builder.func, *table_index, environ)?; @@ -1428,7 +1418,7 @@ pub fn translate_operator( let dest = state.pop1(); environ.translate_table_init( builder.cursor(), - *elem_index, + *segment, TableIndex::from_u32(*table_index), table, dest, @@ -1436,8 +1426,8 @@ pub fn translate_operator( len, )?; } - Operator::ElemDrop { elem_index } => { - environ.translate_elem_drop(builder.cursor(), *elem_index)?; + Operator::ElemDrop { segment } => { + environ.translate_elem_drop(builder.cursor(), *segment)?; } Operator::V128Const { value } => { let data = value.bytes().to_vec().into(); @@ -1600,7 +1590,7 @@ pub fn translate_operator( let (a, b) = pop2_with_bitcast(state, type_of(op), builder); state.push1(builder.ins().umax(a, b)) } - Operator::I8x16AvgrU | Operator::I16x8AvgrU => { + Operator::I8x16RoundingAverageU | Operator::I16x8RoundingAverageU => { let (a, b) = pop2_with_bitcast(state, type_of(op), builder); state.push1(builder.ins().avg_round(a, b)) } @@ -2036,22 +2026,18 @@ pub fn translate_operator( | Operator::I32x4RelaxedTruncSatF32x4U | Operator::I32x4RelaxedTruncSatF64x2SZero | Operator::I32x4RelaxedTruncSatF64x2UZero - | Operator::F32x4RelaxedFma - | Operator::F32x4RelaxedFnma - | Operator::F64x2RelaxedFma - | Operator::F64x2RelaxedFnma - | Operator::I8x16RelaxedLaneselect - | Operator::I16x8RelaxedLaneselect - | Operator::I32x4RelaxedLaneselect - | Operator::I64x2RelaxedLaneselect + | Operator::F32x4Fma + | Operator::F32x4Fms + | Operator::F64x2Fma + | Operator::F64x2Fms + | Operator::I8x16LaneSelect + | Operator::I16x8LaneSelect + | Operator::I32x4LaneSelect + | Operator::I64x2LaneSelect | Operator::F32x4RelaxedMin | Operator::F32x4RelaxedMax | Operator::F64x2RelaxedMin - | Operator::F64x2RelaxedMax - | Operator::F32x4RelaxedDotBf16x8AddF32x4 - | Operator::I16x8RelaxedQ15mulrS - | Operator::I16x8DotI8x16I7x16S - | Operator::I32x4DotI8x16I7x16AddS => { + | Operator::F64x2RelaxedMax => { return Err(wasm_unsupported!("proposed relaxed-simd operator {:?}", op)); } }; @@ -2072,7 +2058,7 @@ fn translate_unreachable_operator( ) -> WasmResult<()> { debug_assert!(!state.reachable); match *op { - Operator::If { blockty } => { + Operator::If { ty } => { // Push a placeholder control stack entry. The if isn't reachable, // so we don't have any branches anywhere. state.push_if( @@ -2082,10 +2068,10 @@ fn translate_unreachable_operator( }, 0, 0, - blockty, + ty, ); } - Operator::Loop { blockty: _ } | Operator::Block { blockty: _ } => { + Operator::Loop { ty: _ } | Operator::Block { ty: _ } => { state.push_block(ir::Block::reserved_value(), 0, 0); } Operator::Else => { @@ -2277,7 +2263,7 @@ fn get_heap_addr( /// Prepare for a load; factors out common functionality between load and load_extend operations. fn prepare_load( - memarg: &MemArg, + memarg: &MemoryImmediate, loaded_bytes: u32, builder: &mut FunctionBuilder, state: &mut FuncTranslationState, @@ -2307,7 +2293,7 @@ fn prepare_load( /// Translate a load instruction. fn translate_load( - memarg: &MemArg, + memarg: &MemoryImmediate, opcode: ir::Opcode, result_ty: Type, builder: &mut FunctionBuilder, @@ -2328,7 +2314,7 @@ fn translate_load( /// Translate a store instruction. fn translate_store( - memarg: &MemArg, + memarg: &MemoryImmediate, opcode: ir::Opcode, builder: &mut FunctionBuilder, state: &mut FuncTranslationState, @@ -2373,7 +2359,7 @@ fn translate_icmp(cc: IntCC, builder: &mut FunctionBuilder, state: &mut FuncTran fn fold_atomic_mem_addr( linear_mem_addr: Value, - memarg: &MemArg, + memarg: &MemoryImmediate, access_ty: Type, builder: &mut FunctionBuilder, ) -> Value { @@ -2407,7 +2393,7 @@ fn fold_atomic_mem_addr( // and then compute the final effective address. fn finalise_atomic_mem_addr( linear_mem_addr: Value, - memarg: &MemArg, + memarg: &MemoryImmediate, access_ty: Type, builder: &mut FunctionBuilder, state: &mut FuncTranslationState, @@ -2459,7 +2445,7 @@ fn translate_atomic_rmw( widened_ty: Type, access_ty: Type, op: AtomicRmwOp, - memarg: &MemArg, + memarg: &MemoryImmediate, builder: &mut FunctionBuilder, state: &mut FuncTranslationState, environ: &mut FE, @@ -2505,7 +2491,7 @@ fn translate_atomic_rmw( fn translate_atomic_cas( widened_ty: Type, access_ty: Type, - memarg: &MemArg, + memarg: &MemoryImmediate, builder: &mut FunctionBuilder, state: &mut FuncTranslationState, environ: &mut FE, @@ -2556,7 +2542,7 @@ fn translate_atomic_cas( fn translate_atomic_load( widened_ty: Type, access_ty: Type, - memarg: &MemArg, + memarg: &MemoryImmediate, builder: &mut FunctionBuilder, state: &mut FuncTranslationState, environ: &mut FE, @@ -2595,7 +2581,7 @@ fn translate_atomic_load( fn translate_atomic_store( access_ty: Type, - memarg: &MemArg, + memarg: &MemoryImmediate, builder: &mut FunctionBuilder, state: &mut FuncTranslationState, environ: &mut FE, @@ -2747,7 +2733,7 @@ fn type_of(operator: &Operator) -> Type { | Operator::I8x16MinU | Operator::I8x16MaxS | Operator::I8x16MaxU - | Operator::I8x16AvgrU + | Operator::I8x16RoundingAverageU | Operator::I8x16Bitmask | Operator::I8x16Popcnt => I8X16, @@ -2784,7 +2770,7 @@ fn type_of(operator: &Operator) -> Type { | Operator::I16x8MinU | Operator::I16x8MaxS | Operator::I16x8MaxU - | Operator::I16x8AvgrU + | Operator::I16x8RoundingAverageU | 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 dc0967ef854..68b3a5c1dc4 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, ValType}; +use wasmer_compiler::wasmparser::{Operator, Type}; 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: ValType) -> WasmResult; + fn translate_ref_null(&mut self, pos: FuncCursor, ty: Type) -> 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 4b42bb1e521..773ec78105a 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::BlockType, + blocktype: wasmer_compiler::wasmparser::TypeOrFuncType, /// 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::BlockType, + blocktype: wasmer_compiler::wasmparser::TypeOrFuncType, ) { 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 e3263ce5760..47972a45af7 100644 --- a/lib/compiler-cranelift/src/translator/func_translator.rs +++ b/lib/compiler-cranelift/src/translator/func_translator.rs @@ -16,7 +16,9 @@ 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::{wptype_to_type, FunctionBinaryReader, ModuleTranslationState}; +use wasmer_compiler::{ + wasm_unsupported, wptype_to_type, FunctionBinaryReader, ModuleTranslationState, +}; use wasmer_types::{LocalFunctionIndex, WasmResult}; /// WebAssembly to Cranelift IR function translator. @@ -179,12 +181,12 @@ fn parse_local_decls( fn declare_locals( builder: &mut FunctionBuilder, count: u32, - wasm_type: wasmparser::ValType, + wasm_type: wasmparser::Type, next_local: &mut usize, environ: &mut FE, ) -> WasmResult<()> { // All locals are initialized to 0. - use wasmparser::ValType::*; + use wasmparser::Type::*; let zeroval = match wasm_type { I32 => builder.ins().iconst(ir::types::I32, 0), I64 => builder.ins().iconst(ir::types::I64, 0), @@ -196,6 +198,7 @@ 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 ecc6beb93c4..db0cc50e49f 100644 --- a/lib/compiler-cranelift/src/translator/translation_utils.rs +++ b/lib/compiler-cranelift/src/translator/translation_utils.rs @@ -7,6 +7,7 @@ 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}; @@ -91,30 +92,36 @@ 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::ValType], + params: &[wasmparser::Type], environ: &PE, ) -> WasmResult { let block = builder.create_block(); for ty in params.iter() { match ty { - wasmparser::ValType::I32 => { + wasmparser::Type::I32 => { builder.append_block_param(block, ir::types::I32); } - wasmparser::ValType::I64 => { + wasmparser::Type::I64 => { builder.append_block_param(block, ir::types::I64); } - wasmparser::ValType::F32 => { + wasmparser::Type::F32 => { builder.append_block_param(block, ir::types::F32); } - wasmparser::ValType::F64 => { + wasmparser::Type::F64 => { builder.append_block_param(block, ir::types::F64); } - wasmparser::ValType::ExternRef | wasmparser::ValType::FuncRef => { + wasmparser::Type::ExternRef | wasmparser::Type::FuncRef => { builder.append_block_param(block, environ.reference_type()); } - wasmparser::ValType::V128 => { + wasmparser::Type::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 a311019bc32..cd99c53f208 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::{MemArg, Operator}; +use wasmer_compiler::wasmparser::{MemoryImmediate, 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: &MemArg, + _memarg: &MemoryImmediate, 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: &MemArg, + memarg: &MemoryImmediate, 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: &MemArg, ptr: PointerValue<'ctx>, align: u8) { + fn trap_if_misaligned(&self, _memarg: &MemoryImmediate, ptr: PointerValue<'ctx>, align: u8) { if align <= 1 { return; } @@ -1394,9 +1394,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { if !self.state.reachable { match op { - Operator::Block { blockty: _ } - | Operator::Loop { blockty: _ } - | Operator::If { blockty: _ } => { + Operator::Block { ty: _ } | Operator::Loop { ty: _ } | Operator::If { ty: _ } => { self.unreachable_depth += 1; return Ok(()); } @@ -1422,7 +1420,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 { blockty } => { + Operator::Block { ty } => { let current_block = self .builder .get_insert_block() @@ -1433,7 +1431,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let phis: SmallVec<[PhiValue<'ctx>; 1]> = self .module_translation - .blocktype_params_results(blockty)? + .blocktype_params_results(ty)? .1 .iter() .map(|&wp_ty| { @@ -1449,7 +1447,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.state.push_block(end_block, phis); self.builder.position_at_end(current_block); } - Operator::Loop { blockty } => { + Operator::Loop { ty } => { 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(); @@ -1457,7 +1455,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(blockty)?; + let blocktypes = self.module_translation.blocktype_params_results(ty)?; let phis = blocktypes .1 .iter() @@ -1594,7 +1592,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 targets } => { + Operator::BrTable { ref table } => { let current_block = self .builder .get_insert_block() @@ -1602,7 +1600,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let index = self.state.pop1()?; - let default_frame = self.state.frame_at_depth(targets.default())?; + let default_frame = self.state.frame_at_depth(table.default())?; let phis = if default_frame.is_loop() { default_frame.loop_body_phis() @@ -1615,7 +1613,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { phi.add_incoming(&[(value, current_block)]); } - let cases: Vec<_> = targets + let cases: Vec<_> = table .targets() .enumerate() .map(|(case_index, depth)| { @@ -1651,7 +1649,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { self.state.popn(args_len)?; self.state.reachable = false; } - Operator::If { blockty } => { + Operator::If { ty } => { let current_block = self .builder .get_insert_block() @@ -1665,7 +1663,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let phis = self .module_translation - .blocktype_params_results(blockty)? + .blocktype_params_results(ty)? .1 .iter() .map(|&wp_ty| { @@ -1696,7 +1694,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(blockty)? + .blocktype_params_results(ty)? .0 .iter() .map(|&wp_ty| { @@ -2270,12 +2268,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { .iter() .for_each(|ret| self.state.push1(*ret)); } - Operator::CallIndirect { - type_index, - table_index, - table_byte: _, - } => { - let sigindex = SignatureIndex::from_u32(type_index); + Operator::CallIndirect { index, table_index } => { + let sigindex = SignatureIndex::from_u32(index); let func_type = &self.wasm_module.signatures[sigindex]; let expected_dynamic_sigindex = self.ctx @@ -3952,7 +3946,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } - Operator::I8x16AvgrU => { + Operator::I8x16RoundingAverageU => { 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); @@ -3983,7 +3977,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } - Operator::I16x8AvgrU => { + Operator::I16x8RoundingAverageU => { 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); @@ -8951,7 +8945,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let res = self.builder.build_bitcast(res, self.intrinsics.i128_ty, ""); self.state.push1(res); } - Operator::AtomicFence => { + Operator::AtomicFence { flags: _ } => { // Fence is a nop. // // Fence was added to preserve information about fences from @@ -10952,10 +10946,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 { data_index, mem } => { + Operator::MemoryInit { segment, 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(data_index.into(), false); + let segment = self.intrinsics.i32_ty.const_int(segment.into(), false); self.builder.build_call( self.intrinsics.memory_init, &[ @@ -10969,24 +10963,24 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { "", ); } - Operator::DataDrop { data_index } => { - let segment = self.intrinsics.i32_ty.const_int(data_index.into(), false); + Operator::DataDrop { segment } => { + let segment = self.intrinsics.i32_ty.const_int(segment.into(), false); self.builder.build_call( self.intrinsics.data_drop, &[vmctx.as_basic_value_enum().into(), segment.into()], "", ); } - Operator::MemoryCopy { dst_mem, src_mem } => { + Operator::MemoryCopy { src, dst } => { // ignored until we support multiple memories - let _dst = dst_mem; + let _dst = dst; let (memory_copy, src) = if let Some(local_memory_index) = self .wasm_module - .local_memory_index(MemoryIndex::from_u32(src_mem)) + .local_memory_index(MemoryIndex::from_u32(src)) { (self.intrinsics.memory_copy, local_memory_index.as_u32()) } else { - (self.intrinsics.imported_memory_copy, src_mem) + (self.intrinsics.imported_memory_copy, src) }; let (dest_pos, src_pos, len) = self.state.pop3()?; @@ -11143,9 +11137,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { "", ); } - Operator::TableInit { elem_index, table } => { + Operator::TableInit { segment, table } => { let (dst, src, len) = self.state.pop3()?; - let segment = self.intrinsics.i32_ty.const_int(elem_index as u64, false); + let segment = self.intrinsics.i32_ty.const_int(segment as u64, false); let table = self.intrinsics.i32_ty.const_int(table as u64, false); self.builder.build_call( self.intrinsics.table_init, @@ -11160,8 +11154,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { "", ); } - Operator::ElemDrop { elem_index } => { - let segment = self.intrinsics.i32_ty.const_int(elem_index as u64, false); + Operator::ElemDrop { segment } => { + let segment = self.intrinsics.i32_ty.const_int(segment 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 56744557d06..9b24e3be68f 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::{BlockType as WpTypeOrFuncType, Operator, ValType as WpType}; +use wasmer_compiler::wasmparser::{Operator, Type as WpType, TypeOrFuncType as WpTypeOrFuncType}; use wasmer_compiler::FunctionBodyData; #[cfg(feature = "unwind")] use wasmer_types::CompiledFunctionUnwindInfo; @@ -2711,15 +2711,11 @@ impl<'a, M: Machine> FuncGen<'a, M> { } } } - Operator::CallIndirect { - type_index, - table_index, - table_byte: _, - } => { + Operator::CallIndirect { index, table_index } => { // 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(type_index as usize); + let index = SignatureIndex::new(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(); @@ -2940,7 +2936,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { } } } - Operator::If { blockty } => { + Operator::If { ty } => { let label_end = self.machine.get_label(); let label_else = self.machine.get_label(); @@ -2950,8 +2946,8 @@ impl<'a, M: Machine> FuncGen<'a, M> { label: label_end, loop_like: false, if_else: IfElseState::If(label_else), - returns: match blockty { - WpTypeOrFuncType::Empty => smallvec![], + returns: match ty { + WpTypeOrFuncType::Type(WpType::EmptyBlockType) => smallvec![], WpTypeOrFuncType::Type(inner_ty) => smallvec![inner_ty], _ => { return Err(CompileError::Codegen( @@ -3068,13 +3064,13 @@ impl<'a, M: Machine> FuncGen<'a, M> { } self.machine.emit_label(end_label)?; } - Operator::Block { blockty } => { + Operator::Block { ty } => { let frame = ControlFrame { label: self.machine.get_label(), loop_like: false, if_else: IfElseState::None, - returns: match blockty { - WpTypeOrFuncType::Empty => smallvec![], + returns: match ty { + WpTypeOrFuncType::Type(WpType::EmptyBlockType) => smallvec![], WpTypeOrFuncType::Type(inner_ty) => smallvec![inner_ty], _ => { return Err(CompileError::Codegen( @@ -3089,7 +3085,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { }; self.control_stack.push(frame); } - Operator::Loop { blockty } => { + Operator::Loop { ty } => { self.machine.align_for_loop()?; let label = self.machine.get_label(); let state_diff_id = self.get_state_diff(); @@ -3099,8 +3095,8 @@ impl<'a, M: Machine> FuncGen<'a, M> { label, loop_like: true, if_else: IfElseState::None, - returns: match blockty { - WpTypeOrFuncType::Empty => smallvec![], + returns: match ty { + WpTypeOrFuncType::Type(WpType::EmptyBlockType) => smallvec![], WpTypeOrFuncType::Type(inner_ty) => smallvec![inner_ty], _ => { return Err(CompileError::Codegen( @@ -3154,7 +3150,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { ret, )?; } - Operator::MemoryInit { data_index, mem } => { + Operator::MemoryInit { segment, mem } => { let len = self.value_stack.pop().unwrap(); let src = self.value_stack.pop().unwrap(); let dst = self.value_stack.pop().unwrap(); @@ -3179,10 +3175,10 @@ impl<'a, M: Machine> FuncGen<'a, M> { this.machine .emit_call_register(this.machine.get_grp_for_call()) }, - // [vmctx, memory_index, data_index, dst, src, len] + // [vmctx, memory_index, segment_index, dst, src, len] [ Location::Imm32(mem), - Location::Imm32(data_index), + Location::Imm32(segment), dst, src, len, @@ -3201,7 +3197,7 @@ impl<'a, M: Machine> FuncGen<'a, M> { )?; self.release_locations_only_stack(&[dst, src, len])?; } - Operator::DataDrop { data_index } => { + Operator::DataDrop { segment } => { self.machine.move_location( Size::S64, Location::Memory( @@ -3218,20 +3214,20 @@ impl<'a, M: Machine> FuncGen<'a, M> { this.machine .emit_call_register(this.machine.get_grp_for_call()) }, - // [vmctx, data_index] - iter::once(Location::Imm32(data_index)), + // [vmctx, segment_index] + iter::once(Location::Imm32(segment)), iter::once(WpType::I64), )?; } - Operator::MemoryCopy { dst_mem, src_mem } => { + Operator::MemoryCopy { src, dst } => { // ignore until we support multiple memories - let _dst = dst_mem; + let _dst = dst; 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_mem as usize); + let memory_index = MemoryIndex::new(src as usize); let (memory_copy_index, memory_index) = if self.module.local_memory_index(memory_index).is_some() { ( @@ -4070,12 +4066,12 @@ impl<'a, M: Machine> FuncGen<'a, M> { self.machine.emit_label(after)?; } - Operator::BrTable { ref targets } => { - let default_target = targets.default(); - let targets = targets + Operator::BrTable { ref table } => { + let targets = table .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