diff --git a/cranelift/faerie/Cargo.toml b/cranelift/faerie/Cargo.toml index 71a5179881..1154d422d6 100644 --- a/cranelift/faerie/Cargo.toml +++ b/cranelift/faerie/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" cranelift-codegen = { path = "../cranelift-codegen", version = "0.30.0" } cranelift-module = { path = "../cranelift-module", version = "0.30.0" } faerie = "0.10.0" -goblin = "0.0.21" +goblin = "0.0.22" failure = "0.1.2" target-lexicon = "0.4.0" diff --git a/cranelift/wasm/Cargo.toml b/cranelift/wasm/Cargo.toml index 0130fcaa7a..7ad1c55d23 100644 --- a/cranelift/wasm/Cargo.toml +++ b/cranelift/wasm/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["webassembly", "wasm"] edition = "2018" [dependencies] -wasmparser = { version = "0.29.2", default-features = false } +wasmparser = { version = "0.31.0", default-features = false } cranelift-codegen = { path = "../cranelift-codegen", version = "0.30.0", default-features = false } cranelift-entity = { path = "../cranelift-entity", version = "0.30.0", default-features = false } cranelift-frontend = { path = "../cranelift-frontend", version = "0.30.0", default-features = false } diff --git a/cranelift/wasm/src/code_translator.rs b/cranelift/wasm/src/code_translator.rs index d0b504dd69..14b27b0275 100644 --- a/cranelift/wasm/src/code_translator.rs +++ b/cranelift/wasm/src/code_translator.rs @@ -25,7 +25,9 @@ use super::{hash_map, HashMap}; use crate::environ::{FuncEnvironment, GlobalVariable, ReturnMode, WasmError, WasmResult}; use crate::state::{ControlStackFrame, TranslationState}; -use crate::translation_utils::{f32_translation, f64_translation, num_return_values, type_to_type}; +use crate::translation_utils::{ + blocktype_to_type, f32_translation, f64_translation, num_return_values, +}; use crate::translation_utils::{FuncIndex, MemoryIndex, SignatureIndex, TableIndex}; use core::{i32, u32}; use cranelift_codegen::ir::condcodes::{FloatCC, IntCC}; @@ -130,7 +132,7 @@ pub fn translate_operator( ***********************************************************************************/ Operator::Block { ty } => { let next = builder.create_ebb(); - if let Ok(ty_cre) = type_to_type(ty) { + if let Ok(ty_cre) = blocktype_to_type(ty) { builder.append_ebb_param(next, ty_cre); } state.push_block(next, num_return_values(ty)); @@ -138,7 +140,7 @@ pub fn translate_operator( Operator::Loop { ty } => { let loop_body = builder.create_ebb(); let next = builder.create_ebb(); - if let Ok(ty_cre) = type_to_type(ty) { + if let Ok(ty_cre) = blocktype_to_type(ty) { builder.append_ebb_param(next, ty_cre); } builder.ins().jump(loop_body, &[]); @@ -156,7 +158,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. - if let Ok(ty_cre) = type_to_type(ty) { + if let Ok(ty_cre) = blocktype_to_type(ty) { builder.append_ebb_param(if_not, ty_cre); } state.push_if(jump_inst, if_not, num_return_values(ty)); diff --git a/cranelift/wasm/src/translation_utils.rs b/cranelift/wasm/src/translation_utils.rs index dc4336c397..18d69c7641 100644 --- a/cranelift/wasm/src/translation_utils.rs +++ b/cranelift/wasm/src/translation_utils.rs @@ -119,6 +119,14 @@ pub fn type_to_type(ty: wasmparser::Type) -> Result { }) } +/// Helper function translating wasmparser block signatures to Cranelift types when possible. +pub fn blocktype_to_type(ty: wasmparser::TypeOrFuncType) -> Result { + match ty { + wasmparser::TypeOrFuncType::Type(ty) => type_to_type(ty), + wasmparser::TypeOrFuncType::FuncType(_) => unimplemented!("multi-value block signatures"), + } +} + /// Turns a `wasmparser` `f32` into a `Cranelift` one. pub fn f32_translation(x: wasmparser::Ieee32) -> ir::immediates::Ieee32 { ir::immediates::Ieee32::with_bits(x.bits()) @@ -130,14 +138,17 @@ pub fn f64_translation(x: wasmparser::Ieee64) -> ir::immediates::Ieee64 { } /// Translate a `wasmparser` type into its `Cranelift` equivalent, when possible -pub fn num_return_values(ty: wasmparser::Type) -> usize { +pub fn num_return_values(ty: wasmparser::TypeOrFuncType) -> usize { match ty { - wasmparser::Type::EmptyBlockType => 0, - wasmparser::Type::I32 - | wasmparser::Type::F32 - | wasmparser::Type::I64 - | wasmparser::Type::F64 => 1, - _ => panic!("unsupported return value type"), + wasmparser::TypeOrFuncType::Type(ty) => match ty { + wasmparser::Type::EmptyBlockType => 0, + wasmparser::Type::I32 + | wasmparser::Type::F32 + | wasmparser::Type::I64 + | wasmparser::Type::F64 => 1, + _ => panic!("unsupported return value type"), + }, + wasmparser::TypeOrFuncType::FuncType(_) => unimplemented!("multi-value block signatures"), } }