Skip to content

Commit 2934899

Browse files
feat: implemented c_type for X86IntrinsicType
1 parent 7047369 commit 2934899

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

crates/intrinsic-test/src/common/intrinsic_helpers.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl TypeKind {
7272
Self::Int(false) => "uint",
7373
Self::Poly => "poly",
7474
Self::Char(true) => "char",
75+
Self::Double => "double",
7576
_ => unreachable!("Not used: {:#?}", self),
7677
}
7778
}
@@ -144,15 +145,15 @@ impl IntrinsicType {
144145
pub fn is_ptr(&self) -> bool {
145146
self.ptr
146147
}
147-
148+
148149
pub fn set_bit_len(&mut self, value: Option<u32>) {
149150
self.bit_len = value;
150151
}
151-
152+
152153
pub fn set_simd_len(&mut self, value: Option<u32>) {
153154
self.simd_len = value;
154155
}
155-
156+
156157
pub fn set_vec_len(&mut self, value: Option<u32>) {
157158
self.vec_len = value;
158159
}

crates/intrinsic-test/src/x86/types.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@ use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, T
77
impl 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

Comments
 (0)