[meta] Port typeset_singleton tests to the Rust crate;

This commit is contained in:
Benjamin Bouvier
2019-03-29 15:51:14 +01:00
parent ac37cb9bf5
commit dd63ebfb68
2 changed files with 54 additions and 6 deletions

View File

@@ -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<VectorType> 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,
}

View File

@@ -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;