[meta] Port typeset_singleton tests to the Rust crate;
This commit is contained in:
@@ -21,13 +21,13 @@ static LANE_BASE: u8 = 0x70;
|
|||||||
// Rust name prefix used for the `rust_name` method.
|
// Rust name prefix used for the `rust_name` method.
|
||||||
static _RUST_NAME_PREFIX: &'static str = "ir::types::";
|
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.
|
/// A concrete SSA value type.
|
||||||
///
|
///
|
||||||
/// All SSA values have a type that is described by an instance of `ValueType`
|
/// All SSA values have a type that is described by an instance of `ValueType`
|
||||||
/// or one of its subclasses.
|
/// or one of its subclasses.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum ValueType {
|
pub enum ValueType {
|
||||||
BV(BVType),
|
BV(BVType),
|
||||||
Lane(LaneType),
|
Lane(LaneType),
|
||||||
@@ -147,7 +147,7 @@ impl From<VectorType> for ValueType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A concrete scalar type that can appear as a vector lane too.
|
/// A concrete scalar type that can appear as a vector lane too.
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, PartialEq)]
|
||||||
pub enum LaneType {
|
pub enum LaneType {
|
||||||
BoolType(shared_types::Bool),
|
BoolType(shared_types::Bool),
|
||||||
FloatType(shared_types::Float),
|
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`,
|
/// A vector type has a lane type which is an instance of `LaneType`,
|
||||||
/// and a positive number of lanes.
|
/// and a positive number of lanes.
|
||||||
#[derive(Clone)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct VectorType {
|
pub struct VectorType {
|
||||||
base: LaneType,
|
base: LaneType,
|
||||||
lanes: u64,
|
lanes: u64,
|
||||||
@@ -393,7 +393,7 @@ impl fmt::Debug for VectorType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A flat bitvector type. Used for semantics description only.
|
/// A flat bitvector type. Used for semantics description only.
|
||||||
#[derive(Clone)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct BVType {
|
pub struct BVType {
|
||||||
bits: u64,
|
bits: u64,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -795,7 +795,55 @@ fn test_forward_images() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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::cdsl::types::VectorType;
|
||||||
use crate::shared::types as shared_types;
|
use crate::shared::types as shared_types;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user