Generate type numbers at meta-time.

We need to generate hash tables keyed by types, so the Python scripts need to
know the index used to represent types in Rust code.

To enforce this, add a new gen_types.py script which generates constant
definitions for the ir/types module.

Also generate constants for common SIMD vector sizes.
This commit is contained in:
Jakob Stoklund Olesen
2016-08-26 12:43:38 -07:00
parent 4b72d0e64d
commit 747dd508df
4 changed files with 80 additions and 36 deletions

View File

@@ -31,38 +31,9 @@ pub struct Type(u8);
/// a SIMD vector.
pub const VOID: Type = Type(0);
/// Integer type with 8 bits.
pub const I8: Type = Type(1);
/// Integer type with 16 bits.
pub const I16: Type = Type(2);
/// Integer type with 32 bits.
pub const I32: Type = Type(3);
/// Integer type with 64 bits.
pub const I64: Type = Type(4);
/// IEEE single precision floating point type.
pub const F32: Type = Type(5);
/// IEEE double precision floating point type.
pub const F64: Type = Type(6);
/// Boolean type. Can't be loaded or stored, but can be used to form SIMD vectors.
pub const B1: Type = Type(7);
/// Boolean type using 8 bits to represent true/false.
pub const B8: Type = Type(8);
/// Boolean type using 16 bits to represent true/false.
pub const B16: Type = Type(9);
/// Boolean type using 32 bits to represent true/false.
pub const B32: Type = Type(10);
/// Boolean type using 64 bits to represent true/false.
pub const B64: Type = Type(11);
// Include code generated by `meta/gen_types.py`. This file contains constant definitions for all
// the scalar types as well as common vector types for 64, 128, 256, and 512-bit SID vectors.
include!(concat!(env!("OUT_DIR"), "/types.rs"));
impl Type {
/// Get the lane type of this SIMD vector type.
@@ -183,6 +154,11 @@ impl Type {
Some(Type(self.0 - 0x10))
}
}
/// Index of this type, for use with hash tables etc.
pub fn index(self) -> usize {
self.0 as usize
}
}
impl Display for Type {
@@ -362,6 +338,10 @@ mod tests {
assert_eq!(B1.by(2).unwrap().half_vector().unwrap().to_string(), "b1");
assert_eq!(I32.half_vector(), None);
assert_eq!(VOID.half_vector(), None);
// Check that the generated constants match the computed vector types.
assert_eq!(I32.by(4), Some(I32X4));
assert_eq!(F64.by(8), Some(F64X8));
}
#[test]