@@ -7,7 +7,21 @@ use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, T
7
7
impl IntrinsicTypeDefinition for X86IntrinsicType {
8
8
/// Gets a string containing the typename for this type in C format.
9
9
fn c_type ( & self ) -> String {
10
- todo ! ( "c_type for X86IntrinsicType needs to be implemented!" ) ;
10
+ let part_0 = if self . constant { "const" } else { "" } ;
11
+ let part_1 = match self . kind {
12
+ TypeKind :: Int ( false ) => "unsigned int" ,
13
+ TypeKind :: Char ( false ) => "unsigned char" ,
14
+ TypeKind :: Short ( false ) => "unsigned short" ,
15
+ TypeKind :: Short ( true ) => "short" ,
16
+ _ => self . kind . c_prefix ( ) ,
17
+ } ;
18
+ let part_2 = if self . ptr {
19
+ if self . ptr_constant { "* const" } else { "*" }
20
+ } else {
21
+ ""
22
+ } ;
23
+
24
+ String :: from ( vec ! [ part_0, part_1, part_2] . join ( " " ) . trim ( ) )
11
25
}
12
26
13
27
fn c_single_vector_type ( & self ) -> String {
@@ -35,25 +49,26 @@ impl IntrinsicTypeDefinition for X86IntrinsicType {
35
49
. replace ( "constexpr" , "" )
36
50
. replace ( "const" , "" )
37
51
. replace ( "literal" , "" ) ;
38
-
39
- let s_split = s_copy. split ( " " )
40
- . filter_map ( |s|if s. len ( ) == 0 { None } else { Some ( s) } )
52
+
53
+ let s_split = s_copy
54
+ . split ( " " )
55
+ . filter_map ( |s| if s. len ( ) == 0 { None } else { Some ( s) } )
41
56
. last ( ) ;
42
-
43
- // TODO: add more intrinsics by modifying
57
+
58
+ // TODO: add more intrinsics by modifying
44
59
// functionality below this line.
45
60
// Currently all the intrinsics that have an "_"
46
61
// is ignored.
47
62
if let Some ( _) = s. matches ( "_" ) . next ( ) {
48
63
return Err ( String :: from ( "This functionality needs to be implemented" ) ) ;
49
64
} ;
50
-
65
+
51
66
// TODO: make the unwrapping safe
52
67
let kind = TypeKind :: from_str ( s_split. unwrap ( ) ) . expect ( "Unable to parse type!" ) ;
53
68
let mut ptr_constant = false ;
54
69
let mut constant = false ;
55
70
let mut ptr = false ;
56
-
71
+
57
72
if let Some ( _) = s. matches ( "const*" ) . next ( ) {
58
73
ptr_constant = true ;
59
74
} ;
@@ -63,7 +78,7 @@ impl IntrinsicTypeDefinition for X86IntrinsicType {
63
78
if let Some ( _) = s. matches ( "*" ) . next ( ) {
64
79
ptr = true ;
65
80
} ;
66
-
81
+
67
82
Ok ( X86IntrinsicType ( IntrinsicType {
68
83
ptr,
69
84
ptr_constant,
0 commit comments