use crate::ir::entities::DynamicType;
use crate::ir::types::*;
use crate::ir::GlobalValue;
use crate::ir::PrimaryMap;
use crate::ir::Type;
#[cfg(feature = "enable-serde")]
use serde_derive::{Deserialize, Serialize};
#[derive(Clone, PartialEq, Hash)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
pub struct DynamicTypeData {
pub base_vector_ty: Type,
pub dynamic_scale: GlobalValue,
}
impl DynamicTypeData {
pub fn new(base_vector_ty: Type, dynamic_scale: GlobalValue) -> Self {
assert!(base_vector_ty.is_vector());
Self {
base_vector_ty,
dynamic_scale,
}
}
pub fn concrete(&self) -> Option<Type> {
self.base_vector_ty.vector_to_dynamic()
}
}
pub type DynamicTypes = PrimaryMap<DynamicType, DynamicTypeData>;
pub fn dynamic_to_fixed(ty: Type) -> Type {
match ty {
I8X8XN => I8X8,
I8X16XN => I8X16,
I16X4XN => I16X4,
I16X8XN => I16X8,
I32X2XN => I32X2,
I32X4XN => I32X4,
I64X2XN => I64X2,
F32X4XN => F32X4,
F64X2XN => F64X2,
_ => unreachable!("unhandled type: {}", ty),
}
}