@@ -9,14 +9,20 @@ use super::cli::Language;
9
9
use super :: indentation:: Indentation ;
10
10
use super :: values:: value_for_array;
11
11
12
+ #[ derive( Debug , PartialEq , Copy , Clone ) ]
13
+ pub enum Sign {
14
+ Signed ,
15
+ Unsigned ,
16
+ }
17
+
12
18
#[ derive( Debug , PartialEq , Copy , Clone ) ]
13
19
pub enum TypeKind {
14
20
BFloat ,
15
21
Float ,
16
22
17
23
// if signed, then the inner value is true
18
- Int ( bool ) ,
19
- Char ( bool ) ,
24
+ Int ( Sign ) ,
25
+ Char ( Sign ) ,
20
26
Poly ,
21
27
Void ,
22
28
Mask ,
@@ -29,10 +35,12 @@ impl FromStr for TypeKind {
29
35
match s {
30
36
"bfloat" | "BF16" => Ok ( Self :: BFloat ) ,
31
37
"float" | "double" | "FP16" | "FP32" | "FP64" => Ok ( Self :: Float ) ,
32
- "int" | "long" | "short" | "SI8" | "SI16" | "SI32" | "SI64" => Ok ( Self :: Int ( true ) ) ,
38
+ "int" | "long" | "short" | "SI8" | "SI16" | "SI32" | "SI64" => {
39
+ Ok ( Self :: Int ( Sign :: Signed ) )
40
+ }
33
41
"poly" => Ok ( Self :: Poly ) ,
34
- "char" => Ok ( Self :: Char ( true ) ) ,
35
- "uint" | "unsigned" | "UI8" | "UI16" | "UI32" | "UI64" => Ok ( Self :: Int ( false ) ) ,
42
+ "char" => Ok ( Self :: Char ( Sign :: Signed ) ) ,
43
+ "uint" | "unsigned" | "UI8" | "UI16" | "UI32" | "UI64" => Ok ( Self :: Int ( Sign :: Unsigned ) ) ,
36
44
"void" => Ok ( Self :: Void ) ,
37
45
"MASK" => Ok ( Self :: Mask ) ,
38
46
_ => Err ( format ! ( "Impossible to parse argument kind {s}" ) ) ,
@@ -48,12 +56,12 @@ impl fmt::Display for TypeKind {
48
56
match self {
49
57
Self :: BFloat => "bfloat" ,
50
58
Self :: Float => "float" ,
51
- Self :: Int ( true ) => "int" ,
52
- Self :: Int ( false ) => "uint" ,
59
+ Self :: Int ( Sign :: Signed ) => "int" ,
60
+ Self :: Int ( Sign :: Unsigned ) => "uint" ,
53
61
Self :: Poly => "poly" ,
54
62
Self :: Void => "void" ,
55
- Self :: Char ( true ) => "char" ,
56
- Self :: Char ( false ) => "unsigned char" ,
63
+ Self :: Char ( Sign :: Signed ) => "char" ,
64
+ Self :: Char ( Sign :: Unsigned ) => "unsigned char" ,
57
65
Self :: Mask => "mask" ,
58
66
}
59
67
)
@@ -65,10 +73,10 @@ impl TypeKind {
65
73
pub fn c_prefix ( & self ) -> & str {
66
74
match self {
67
75
Self :: Float => "float" ,
68
- Self :: Int ( true ) => "int" ,
69
- Self :: Int ( false ) => "uint" ,
76
+ Self :: Int ( Sign :: Signed ) => "int" ,
77
+ Self :: Int ( Sign :: Unsigned ) => "uint" ,
70
78
Self :: Poly => "poly" ,
71
- Self :: Char ( true ) => "char" ,
79
+ Self :: Char ( Sign :: Signed ) => "char" ,
72
80
_ => unreachable ! ( "Not used: {:#?}" , self ) ,
73
81
}
74
82
}
@@ -77,8 +85,8 @@ impl TypeKind {
77
85
pub fn rust_prefix ( & self ) -> & str {
78
86
match self {
79
87
Self :: Float => "f" ,
80
- Self :: Int ( true ) => "i" ,
81
- Self :: Int ( false ) => "u" ,
88
+ Self :: Int ( Sign :: Signed ) => "i" ,
89
+ Self :: Int ( Sign :: Unsigned ) => "u" ,
82
90
Self :: Poly => "u" ,
83
91
_ => unreachable ! ( "Unused type kind: {:#?}" , self ) ,
84
92
}
@@ -180,8 +188,8 @@ impl IntrinsicType {
180
188
bit_len : Some ( 8 ) ,
181
189
..
182
190
} => match kind {
183
- TypeKind :: Int ( true ) => "(int)" ,
184
- TypeKind :: Int ( false ) => "(unsigned int)" ,
191
+ TypeKind :: Int ( Sign :: Signed ) => "(int)" ,
192
+ TypeKind :: Int ( Sign :: Unsigned ) => "(unsigned int)" ,
185
193
TypeKind :: Poly => "(unsigned int)(uint8_t)" ,
186
194
_ => "" ,
187
195
} ,
@@ -241,7 +249,8 @@ impl IntrinsicType {
241
249
. format_with( ",\n " , |i, fmt| {
242
250
let src = value_for_array( * bit_len, i) ;
243
251
assert!( src == 0 || src. ilog2( ) < * bit_len) ;
244
- if * kind == TypeKind :: Int ( true ) && ( src >> ( * bit_len - 1 ) ) != 0 {
252
+ if * kind == TypeKind :: Int ( Sign :: Signed ) && ( src >> ( * bit_len - 1 ) ) != 0
253
+ {
245
254
// `src` is a two's complement representation of a negative value.
246
255
let mask = !0u64 >> ( 64 - * bit_len) ;
247
256
let ones_compl = src ^ mask;
0 commit comments