@@ -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,8 +66,8 @@ 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" ,
62
72
_ => unreachable ! ( "Not used: {:#?}" , self ) ,
63
73
}
@@ -67,8 +77,8 @@ impl TypeKind {
67
77
pub fn rust_prefix ( & self ) -> & str {
68
78
match self {
69
79
Self :: Float => "f" ,
70
- Self :: Int => "i" ,
71
- Self :: UInt => "u" ,
80
+ Self :: Int ( true ) => "i" ,
81
+ Self :: Int ( false ) => "u" ,
72
82
Self :: Poly => "u" ,
73
83
_ => unreachable ! ( "Unused type kind: {:#?}" , self ) ,
74
84
}
@@ -155,8 +165,8 @@ impl IntrinsicType {
155
165
bit_len : Some ( 8 ) ,
156
166
..
157
167
} => match kind {
158
- TypeKind :: Int => "(int)" ,
159
- TypeKind :: UInt => "(unsigned int)" ,
168
+ TypeKind :: Int ( true ) => "(int)" ,
169
+ TypeKind :: Int ( false ) => "(unsigned int)" ,
160
170
TypeKind :: Poly => "(unsigned int)(uint8_t)" ,
161
171
_ => "" ,
162
172
} ,
@@ -185,7 +195,7 @@ impl IntrinsicType {
185
195
match self {
186
196
IntrinsicType {
187
197
bit_len : Some ( bit_len @ ( 8 | 16 | 32 | 64 ) ) ,
188
- kind : kind @ ( TypeKind :: Int | TypeKind :: UInt | TypeKind :: Poly ) ,
198
+ kind : kind @ ( TypeKind :: Int ( _ ) | TypeKind :: Poly ) ,
189
199
simd_len,
190
200
vec_len,
191
201
..
@@ -201,7 +211,7 @@ impl IntrinsicType {
201
211
. format_with( ",\n " , |i, fmt| {
202
212
let src = value_for_array( * bit_len, i) ;
203
213
assert!( src == 0 || src. ilog2( ) < * bit_len) ;
204
- if * kind == TypeKind :: Int && ( src >> ( * bit_len - 1 ) ) != 0 {
214
+ if * kind == TypeKind :: Int ( true ) && ( src >> ( * bit_len - 1 ) ) != 0 {
205
215
// `src` is a two's complement representation of a negative value.
206
216
let mask = !0u64 >> ( 64 - * bit_len) ;
207
217
let ones_compl = src ^ mask;
@@ -257,7 +267,7 @@ impl IntrinsicType {
257
267
..
258
268
} => false ,
259
269
IntrinsicType {
260
- kind : TypeKind :: Int | TypeKind :: UInt | TypeKind :: Poly ,
270
+ kind : TypeKind :: Int ( _ ) | TypeKind :: Poly ,
261
271
..
262
272
} => true ,
263
273
_ => unimplemented ! ( ) ,
0 commit comments