diff --git a/cranelift/wasm/src/state/module_state.rs b/cranelift/wasm/src/state/module_state.rs index 8b857bf6a9..db22d82794 100644 --- a/cranelift/wasm/src/state/module_state.rs +++ b/cranelift/wasm/src/state/module_state.rs @@ -1,8 +1,6 @@ -use crate::{SignatureIndex, WasmError, WasmResult}; -use cranelift_codegen::ir::{types, Type}; +use crate::SignatureIndex; use cranelift_entity::PrimaryMap; use std::boxed::Box; -use std::vec::Vec; /// Map of signatures to a function's parameter and return types. pub(crate) type WasmTypes = @@ -23,22 +21,6 @@ pub struct ModuleTranslationState { pub(crate) wasm_types: WasmTypes, } -fn cranelift_to_wasmparser_type(ty: Type) -> WasmResult { - Ok(match ty { - types::I32 => wasmparser::ValType::I32, - types::I64 => wasmparser::ValType::I64, - types::F32 => wasmparser::ValType::F32, - types::F64 => wasmparser::ValType::F64, - types::R32 | types::R64 => wasmparser::ValType::ExternRef, - _ => { - return Err(WasmError::Unsupported(format!( - "Cannot convert Cranelift type to Wasm signature: {:?}", - ty - ))); - } - }) -} - impl ModuleTranslationState { /// Creates a new empty ModuleTranslationState. pub fn new() -> Self { @@ -46,24 +28,4 @@ impl ModuleTranslationState { wasm_types: PrimaryMap::new(), } } - - /// Create a new ModuleTranslationState with the given function signatures, - /// provided in terms of Cranelift types. The provided slice of signatures - /// is indexed by signature number, and contains pairs of (args, results) - /// slices. - pub fn from_func_sigs(sigs: &[(&[Type], &[Type])]) -> WasmResult { - let mut wasm_types = PrimaryMap::with_capacity(sigs.len()); - for &(ref args, ref results) in sigs { - let args: Vec = args - .iter() - .map(|&ty| cranelift_to_wasmparser_type(ty)) - .collect::>()?; - let results: Vec = results - .iter() - .map(|&ty| cranelift_to_wasmparser_type(ty)) - .collect::>()?; - wasm_types.push((args.into_boxed_slice(), results.into_boxed_slice())); - } - Ok(Self { wasm_types }) - } } diff --git a/cranelift/wasm/src/translation_utils.rs b/cranelift/wasm/src/translation_utils.rs index 56c56c8b8f..b319bc6905 100644 --- a/cranelift/wasm/src/translation_utils.rs +++ b/cranelift/wasm/src/translation_utils.rs @@ -9,50 +9,6 @@ use cranelift_frontend::FunctionBuilder; use serde::{Deserialize, Serialize}; use wasmparser::{FuncValidator, WasmFuncType, WasmModuleResources}; -/// WebAssembly table element. Can be a function or a scalar type. -#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] -pub enum TableElementType { - /// A scalar type. - Val(ir::Type), - /// A function. - Func, -} - -/// Helper function translating wasmparser types to Cranelift types when possible. -pub fn type_to_type( - ty: wasmparser::ValType, - environ: &PE, -) -> WasmResult { - match ty { - wasmparser::ValType::I32 => Ok(ir::types::I32), - wasmparser::ValType::I64 => Ok(ir::types::I64), - wasmparser::ValType::F32 => Ok(ir::types::F32), - wasmparser::ValType::F64 => Ok(ir::types::F64), - wasmparser::ValType::V128 => Ok(ir::types::I8X16), - wasmparser::ValType::ExternRef | wasmparser::ValType::FuncRef => { - Ok(environ.reference_type(ty.try_into()?)) - } - } -} - -/// Helper function translating wasmparser possible table types to Cranelift types when possible, -/// or None for Func tables. -pub fn tabletype_to_type( - ty: wasmparser::ValType, - environ: &PE, -) -> WasmResult> { - match ty { - wasmparser::ValType::I32 => Ok(Some(ir::types::I32)), - wasmparser::ValType::I64 => Ok(Some(ir::types::I64)), - wasmparser::ValType::F32 => Ok(Some(ir::types::F32)), - wasmparser::ValType::F64 => Ok(Some(ir::types::F64)), - wasmparser::ValType::V128 => Ok(Some(ir::types::I8X16)), - wasmparser::ValType::ExternRef => Ok(Some(environ.reference_type(ty.try_into()?))), - wasmparser::ValType::FuncRef => Ok(None), - } -} - /// Get the parameter and result types for the given Wasm blocktype. pub fn blocktype_params_results<'a, T>( validator: &'a FuncValidator,