Remove some dead code in the cranelift-wasm crate (#5290)
* Remove some dead code in the cranelift-wasm crate * Remove some more dead code
This commit is contained in:
@@ -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<wasmparser::ValType> {
|
||||
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<Self> {
|
||||
let mut wasm_types = PrimaryMap::with_capacity(sigs.len());
|
||||
for &(ref args, ref results) in sigs {
|
||||
let args: Vec<wasmparser::ValType> = args
|
||||
.iter()
|
||||
.map(|&ty| cranelift_to_wasmparser_type(ty))
|
||||
.collect::<Result<_, _>>()?;
|
||||
let results: Vec<wasmparser::ValType> = results
|
||||
.iter()
|
||||
.map(|&ty| cranelift_to_wasmparser_type(ty))
|
||||
.collect::<Result<_, _>>()?;
|
||||
wasm_types.push((args.into_boxed_slice(), results.into_boxed_slice()));
|
||||
}
|
||||
Ok(Self { wasm_types })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<PE: TargetEnvironment + ?Sized>(
|
||||
ty: wasmparser::ValType,
|
||||
environ: &PE,
|
||||
) -> WasmResult<ir::Type> {
|
||||
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<PE: TargetEnvironment + ?Sized>(
|
||||
ty: wasmparser::ValType,
|
||||
environ: &PE,
|
||||
) -> WasmResult<Option<ir::Type>> {
|
||||
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<T>,
|
||||
|
||||
Reference in New Issue
Block a user