use crate::core::ir::PrimitiveType;
pub(crate) fn needs_i64_cast(p: &PrimitiveType) -> bool {
matches!(p, PrimitiveType::U64 | PrimitiveType::Usize | PrimitiveType::Isize)
}
pub(crate) fn needs_i32_cast(p: &PrimitiveType) -> bool {
matches!(
p,
PrimitiveType::U8 | PrimitiveType::U16 | PrimitiveType::U32 | PrimitiveType::I8 | PrimitiveType::I16
)
}
pub(crate) fn needs_f64_cast(p: &PrimitiveType) -> bool {
matches!(
p,
PrimitiveType::U64 | PrimitiveType::I64 | PrimitiveType::Usize | PrimitiveType::Isize | PrimitiveType::F32
)
}
pub(crate) fn core_prim_str(p: &PrimitiveType) -> &'static str {
match p {
PrimitiveType::U64 => "u64",
PrimitiveType::Usize => "usize",
PrimitiveType::Isize => "isize",
PrimitiveType::F32 => "f32",
PrimitiveType::Bool => "bool",
PrimitiveType::U8 => "u8",
PrimitiveType::U16 => "u16",
PrimitiveType::U32 => "u32",
PrimitiveType::I8 => "i8",
PrimitiveType::I16 => "i16",
PrimitiveType::I32 => "i32",
PrimitiveType::I64 => "i64",
PrimitiveType::F64 => "f64",
}
}
pub(crate) fn binding_prim_str(p: &PrimitiveType) -> &'static str {
match p {
PrimitiveType::U64 | PrimitiveType::Usize | PrimitiveType::Isize => "i64",
PrimitiveType::F32 => "f64",
PrimitiveType::Bool => "bool",
PrimitiveType::U8 | PrimitiveType::U16 | PrimitiveType::U32 => "i32",
PrimitiveType::I8 | PrimitiveType::I16 | PrimitiveType::I32 => "i32",
PrimitiveType::I64 => "i64",
PrimitiveType::F64 => "f64",
}
}