@@ -9,14 +9,20 @@ use super::cli::Language;
99use super :: indentation:: Indentation ;
1010use super :: values:: value_for_array;
1111
12+ #[ derive( Debug , PartialEq , Copy , Clone ) ]
13+ pub enum Sign {
14+ Signed ,
15+ Unsigned ,
16+ }
17+
1218#[ derive( Debug , PartialEq , Copy , Clone ) ]
1319pub enum TypeKind {
1420 BFloat ,
1521 Float ,
1622
1723 // if signed, then the inner value is true
18- Int ( bool ) ,
19- Char ( bool ) ,
24+ Int ( Sign ) ,
25+ Char ( Sign ) ,
2026 Poly ,
2127 Void ,
2228 Mask ,
@@ -29,10 +35,12 @@ impl FromStr for TypeKind {
2935 match s {
3036 "bfloat" | "BF16" => Ok ( Self :: BFloat ) ,
3137 "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+ }
3341 "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 ) ) ,
3644 "void" => Ok ( Self :: Void ) ,
3745 "MASK" => Ok ( Self :: Mask ) ,
3846 _ => Err ( format ! ( "Impossible to parse argument kind {s}" ) ) ,
@@ -48,12 +56,12 @@ impl fmt::Display for TypeKind {
4856 match self {
4957 Self :: BFloat => "bfloat" ,
5058 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" ,
5361 Self :: Poly => "poly" ,
5462 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" ,
5765 Self :: Mask => "mask" ,
5866 }
5967 )
@@ -65,10 +73,10 @@ impl TypeKind {
6573 pub fn c_prefix ( & self ) -> & str {
6674 match self {
6775 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" ,
7078 Self :: Poly => "poly" ,
71- Self :: Char ( true ) => "char" ,
79+ Self :: Char ( Sign :: Signed ) => "char" ,
7280 _ => unreachable ! ( "Not used: {:#?}" , self ) ,
7381 }
7482 }
@@ -77,8 +85,8 @@ impl TypeKind {
7785 pub fn rust_prefix ( & self ) -> & str {
7886 match self {
7987 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" ,
8290 Self :: Poly => "u" ,
8391 _ => unreachable ! ( "Unused type kind: {:#?}" , self ) ,
8492 }
@@ -180,8 +188,8 @@ impl IntrinsicType {
180188 bit_len : Some ( 8 ) ,
181189 ..
182190 } => 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)" ,
185193 TypeKind :: Poly => "(unsigned int)(uint8_t)" ,
186194 _ => "" ,
187195 } ,
@@ -241,7 +249,8 @@ impl IntrinsicType {
241249 . format_with( ",\n " , |i, fmt| {
242250 let src = value_for_array( * bit_len, i) ;
243251 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+ {
245254 // `src` is a two's complement representation of a negative value.
246255 let mask = !0u64 >> ( 64 - * bit_len) ;
247256 let ones_compl = src ^ mask;
0 commit comments