From dd63ebfb68e1a4da2ec5c016eb3c8e773d1fd8c6 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Fri, 29 Mar 2019 15:51:14 +0100 Subject: [PATCH] [meta] Port typeset_singleton tests to the Rust crate; --- cranelift/codegen/meta/src/cdsl/types.rs | 10 ++--- cranelift/codegen/meta/src/cdsl/typevar.rs | 50 +++++++++++++++++++++- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/cranelift/codegen/meta/src/cdsl/types.rs b/cranelift/codegen/meta/src/cdsl/types.rs index 643ecdc4b6..a8aa4020d8 100644 --- a/cranelift/codegen/meta/src/cdsl/types.rs +++ b/cranelift/codegen/meta/src/cdsl/types.rs @@ -21,13 +21,13 @@ static LANE_BASE: u8 = 0x70; // Rust name prefix used for the `rust_name` method. static _RUST_NAME_PREFIX: &'static str = "ir::types::"; -// ValueType variants (i8, i32, ...) are provided in `base::types.rs`. +// ValueType variants (i8, i32, ...) are provided in `shared::types.rs`. /// A concrete SSA value type. /// /// All SSA values have a type that is described by an instance of `ValueType` /// or one of its subclasses. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub enum ValueType { BV(BVType), Lane(LaneType), @@ -147,7 +147,7 @@ impl From for ValueType { } /// A concrete scalar type that can appear as a vector lane too. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq)] pub enum LaneType { BoolType(shared_types::Bool), FloatType(shared_types::Float), @@ -327,7 +327,7 @@ impl Iterator for LaneTypeIterator { /// /// A vector type has a lane type which is an instance of `LaneType`, /// and a positive number of lanes. -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct VectorType { base: LaneType, lanes: u64, @@ -393,7 +393,7 @@ impl fmt::Debug for VectorType { } /// A flat bitvector type. Used for semantics description only. -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct BVType { bits: u64, } diff --git a/cranelift/codegen/meta/src/cdsl/typevar.rs b/cranelift/codegen/meta/src/cdsl/typevar.rs index 54e969b3cf..cb6f18ce56 100644 --- a/cranelift/codegen/meta/src/cdsl/typevar.rs +++ b/cranelift/codegen/meta/src/cdsl/typevar.rs @@ -795,7 +795,55 @@ fn test_forward_images() { } #[test] -fn test_singleton() { +#[should_panic] +fn test_typeset_singleton_panic_nonsingleton_types() { + TypeSetBuilder::new() + .ints(8..8) + .floats(32..32) + .finish() + .get_singleton(); +} + +#[test] +#[should_panic] +fn test_typeset_singleton_panic_nonsingleton_lanes() { + TypeSetBuilder::new() + .simd_lanes(1..2) + .floats(32..32) + .finish() + .get_singleton(); +} + +#[test] +fn test_typeset_singleton() { + use crate::shared::types as shared_types; + assert_eq!( + TypeSetBuilder::new().ints(16..16).finish().get_singleton(), + ValueType::Lane(shared_types::Int::I16.into()) + ); + assert_eq!( + TypeSetBuilder::new() + .floats(64..64) + .finish() + .get_singleton(), + ValueType::Lane(shared_types::Float::F64.into()) + ); + assert_eq!( + TypeSetBuilder::new().bools(1..1).finish().get_singleton(), + ValueType::Lane(shared_types::Bool::B1.into()) + ); + assert_eq!( + TypeSetBuilder::new() + .simd_lanes(4..4) + .ints(32..32) + .finish() + .get_singleton(), + LaneType::from(shared_types::Int::I32).by(4) + ); +} + +#[test] +fn test_typevar_singleton() { use crate::cdsl::types::VectorType; use crate::shared::types as shared_types;