1use crate::context::TypeId;
4
5#[derive(Clone, Debug, PartialEq, Eq, Hash)]
7pub enum TypeData {
8 Void,
10 Integer(u32),
12 Float(FloatKind),
14 Pointer,
16 Array {
18 element: TypeId,
19 len: u64,
20 },
21 Vector {
23 element: TypeId,
24 len: u32,
25 scalable: bool,
26 },
27 Struct(StructType),
29 Function(FunctionType),
31 Label,
33 Metadata,
35}
36
37#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
39pub enum FloatKind {
40 Half,
42 BFloat,
44 Single,
46 Double,
48 Fp128,
50 X86Fp80,
52}
53
54#[derive(Clone, Debug, PartialEq, Eq, Hash)]
56pub struct StructType {
57 pub name: Option<String>,
59 pub fields: Vec<TypeId>,
61 pub packed: bool,
63}
64
65#[derive(Clone, Debug, PartialEq, Eq, Hash)]
67pub struct FunctionType {
68 pub ret: TypeId,
70 pub params: Vec<TypeId>,
72 pub variadic: bool,
74}
75
76#[cfg(test)]
77mod tests {
78 use super::*;
79 use crate::context::Context;
80
81 #[test]
82 fn type_data_eq() {
83 let a = TypeData::Integer(32);
84 let b = TypeData::Integer(32);
85 assert_eq!(a, b);
86 let c = TypeData::Integer(64);
87 assert_ne!(a, c);
88 }
89
90 #[test]
91 fn struct_type_eq() {
92 let ctx = Context::new();
93 let s1 = StructType {
94 name: None,
95 fields: vec![ctx.i32_ty, ctx.i64_ty],
96 packed: false,
97 };
98 let s2 = StructType {
99 name: None,
100 fields: vec![ctx.i32_ty, ctx.i64_ty],
101 packed: false,
102 };
103 assert_eq!(s1, s2);
104 }
105}