@@ -12,8 +12,12 @@ use super::values::value_for_array;
12
12
pub enum TypeKind {
13
13
BFloat ,
14
14
Float ,
15
- Int ,
16
- UInt ,
15
+ Double ,
16
+
17
+ // if signed, then the inner value is true
18
+ Int ( bool ) ,
19
+ Char ( bool ) ,
20
+ Short ( bool ) ,
17
21
Poly ,
18
22
Void ,
19
23
}
@@ -25,9 +29,10 @@ impl FromStr for TypeKind {
25
29
match s {
26
30
"bfloat" => Ok ( Self :: BFloat ) ,
27
31
"float" => Ok ( Self :: Float ) ,
28
- "int" => Ok ( Self :: Int ) ,
32
+ "int" => Ok ( Self :: Int ( true ) ) ,
29
33
"poly" => Ok ( Self :: Poly ) ,
30
- "uint" | "unsigned" => Ok ( Self :: UInt ) ,
34
+ "char" => Ok ( Self :: Char ( true ) ) ,
35
+ "uint" | "unsigned" => Ok ( Self :: Int ( false ) ) ,
31
36
"void" => Ok ( Self :: Void ) ,
32
37
_ => Err ( format ! ( "Impossible to parse argument kind {s}" ) ) ,
33
38
}
@@ -42,10 +47,15 @@ impl fmt::Display for TypeKind {
42
47
match self {
43
48
Self :: BFloat => "bfloat" ,
44
49
Self :: Float => "float" ,
45
- Self :: Int => "int" ,
46
- Self :: UInt => "uint" ,
50
+ Self :: Double => "double" ,
51
+ Self :: Int ( true ) => "int" ,
52
+ Self :: Int ( false ) => "uint" ,
47
53
Self :: Poly => "poly" ,
48
54
Self :: Void => "void" ,
55
+ Self :: Char ( true ) => "char" ,
56
+ Self :: Char ( false ) => "unsigned char" ,
57
+ Self :: Short ( true ) => "short" ,
58
+ Self :: Short ( false ) => "unsigned short" ,
49
59
}
50
60
)
51
61
}
@@ -56,9 +66,11 @@ impl TypeKind {
56
66
pub fn c_prefix ( & self ) -> & str {
57
67
match self {
58
68
Self :: Float => "float" ,
59
- Self :: Int => "int" ,
60
- Self :: UInt => "uint" ,
69
+ Self :: Int ( true ) => "int" ,
70
+ Self :: Int ( false ) => "uint" ,
61
71
Self :: Poly => "poly" ,
72
+ Self :: Char ( true ) => "char" ,
73
+ Self :: Char ( false ) => "unsigned char" ,
62
74
_ => unreachable ! ( "Not used: {:#?}" , self ) ,
63
75
}
64
76
}
@@ -67,8 +79,8 @@ impl TypeKind {
67
79
pub fn rust_prefix ( & self ) -> & str {
68
80
match self {
69
81
Self :: Float => "f" ,
70
- Self :: Int => "i" ,
71
- Self :: UInt => "u" ,
82
+ Self :: Int ( true ) => "i" ,
83
+ Self :: Int ( false ) => "u" ,
72
84
Self :: Poly => "u" ,
73
85
_ => unreachable ! ( "Unused type kind: {:#?}" , self ) ,
74
86
}
@@ -132,6 +144,18 @@ impl IntrinsicType {
132
144
self . ptr
133
145
}
134
146
147
+ pub fn set_bit_len ( & mut self , value : Option < u32 > ) {
148
+ self . bit_len = value;
149
+ }
150
+
151
+ pub fn set_simd_len ( & mut self , value : Option < u32 > ) {
152
+ self . simd_len = value;
153
+ }
154
+
155
+ pub fn set_vec_len ( & mut self , value : Option < u32 > ) {
156
+ self . vec_len = value;
157
+ }
158
+
135
159
pub fn c_scalar_type ( & self ) -> String {
136
160
format ! (
137
161
"{prefix}{bits}_t" ,
@@ -155,8 +179,8 @@ impl IntrinsicType {
155
179
bit_len : Some ( 8 ) ,
156
180
..
157
181
} => match kind {
158
- TypeKind :: Int => "(int)" ,
159
- TypeKind :: UInt => "(unsigned int)" ,
182
+ TypeKind :: Int ( true ) => "(int)" ,
183
+ TypeKind :: Int ( false ) => "(unsigned int)" ,
160
184
TypeKind :: Poly => "(unsigned int)(uint8_t)" ,
161
185
_ => "" ,
162
186
} ,
@@ -185,7 +209,7 @@ impl IntrinsicType {
185
209
match self {
186
210
IntrinsicType {
187
211
bit_len : Some ( bit_len @ ( 8 | 16 | 32 | 64 ) ) ,
188
- kind : kind @ ( TypeKind :: Int | TypeKind :: UInt | TypeKind :: Poly ) ,
212
+ kind : kind @ ( TypeKind :: Int ( _ ) | TypeKind :: Poly ) ,
189
213
simd_len,
190
214
vec_len,
191
215
..
@@ -201,7 +225,7 @@ impl IntrinsicType {
201
225
. format_with( ",\n " , |i, fmt| {
202
226
let src = value_for_array( * bit_len, i) ;
203
227
assert!( src == 0 || src. ilog2( ) < * bit_len) ;
204
- if * kind == TypeKind :: Int && ( src >> ( * bit_len - 1 ) ) != 0 {
228
+ if * kind == TypeKind :: Int ( true ) && ( src >> ( * bit_len - 1 ) ) != 0 {
205
229
// `src` is a two's complement representation of a negative value.
206
230
let mask = !0u64 >> ( 64 - * bit_len) ;
207
231
let ones_compl = src ^ mask;
@@ -257,7 +281,7 @@ impl IntrinsicType {
257
281
..
258
282
} => false ,
259
283
IntrinsicType {
260
- kind : TypeKind :: Int | TypeKind :: UInt | TypeKind :: Poly ,
284
+ kind : TypeKind :: Int ( _ ) | TypeKind :: Poly ,
261
285
..
262
286
} => true ,
263
287
_ => unimplemented ! ( ) ,
0 commit comments