diff --git a/Cargo.lock b/Cargo.lock index c8233284dee..66d928d5164 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", ] @@ -5436,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 73e5cd33a26..23442c930b1 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/c-api/src/wasm_c_api/unstable/parser/operator.rs b/lib/c-api/src/wasm_c_api/unstable/parser/operator.rs index 79f9ec6e40a..db6424c5d96 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/compiler-cranelift/src/address_map.rs b/lib/compiler-cranelift/src/address_map.rs index 2fe92429fd7..088067cfcd4 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 d71153235b8..98f371cca3c 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 fb2de48eb27..293283e2b77 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 68b3a5c1dc4..dc0967ef854 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 773ec78105a..4b42bb1e521 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 47972a45af7..e3263ce5760 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 db0cc50e49f..ecc6beb93c4 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 cd99c53f208..a311019bc32 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 9b24e3be68f..56744557d06 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