@@ -7,7 +7,21 @@ use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, T
77impl IntrinsicTypeDefinition for X86IntrinsicType {
88 /// Gets a string containing the typename for this type in C format.
99 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 ( ) )
1125 }
1226
1327 fn c_single_vector_type ( & self ) -> String {
@@ -35,25 +49,26 @@ impl IntrinsicTypeDefinition for X86IntrinsicType {
3549 . replace ( "constexpr" , "" )
3650 . replace ( "const" , "" )
3751 . 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) } )
4156 . last ( ) ;
42-
43- // TODO: add more intrinsics by modifying
57+
58+ // TODO: add more intrinsics by modifying
4459 // functionality below this line.
4560 // Currently all the intrinsics that have an "_"
4661 // is ignored.
4762 if let Some ( _) = s. matches ( "_" ) . next ( ) {
4863 return Err ( String :: from ( "This functionality needs to be implemented" ) ) ;
4964 } ;
50-
65+
5166 // TODO: make the unwrapping safe
5267 let kind = TypeKind :: from_str ( s_split. unwrap ( ) ) . expect ( "Unable to parse type!" ) ;
5368 let mut ptr_constant = false ;
5469 let mut constant = false ;
5570 let mut ptr = false ;
56-
71+
5772 if let Some ( _) = s. matches ( "const*" ) . next ( ) {
5873 ptr_constant = true ;
5974 } ;
@@ -63,7 +78,7 @@ impl IntrinsicTypeDefinition for X86IntrinsicType {
6378 if let Some ( _) = s. matches ( "*" ) . next ( ) {
6479 ptr = true ;
6580 } ;
66-
81+
6782 Ok ( X86IntrinsicType ( IntrinsicType {
6883 ptr,
6984 ptr_constant,
0 commit comments