Skip to content

Commit 8b3ee28

Browse files
feat: cleaned the IntrinsicType struct and associated functions.
Changes: 1. Removed `from_c` from the IntrinsicType definition. 2. Moved the `from_c` arm-specific definition to an ArmIntrinsicType-specific impl block
1 parent 3ff4f70 commit 8b3ee28

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

crates/intrinsic-test/src/arm/intrinsic.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@ use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, S
55
use std::ops::{Deref, DerefMut};
66

77
#[derive(Debug, Clone, PartialEq)]
8-
pub struct ArmIntrinsicType(pub IntrinsicType);
8+
pub struct ArmIntrinsicType {
9+
pub data: IntrinsicType,
10+
pub target: String,
11+
}
912

1013
impl Deref for ArmIntrinsicType {
1114
type Target = IntrinsicType;
1215

1316
fn deref(&self) -> &Self::Target {
14-
&self.0
17+
&self.data
1518
}
1619
}
1720

1821
impl DerefMut for ArmIntrinsicType {
1922
fn deref_mut(&mut self) -> &mut Self::Target {
20-
&mut self.0
23+
&mut self.data
2124
}
2225
}
2326

crates/intrinsic-test/src/arm/json_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn json_to_intrinsic(
100100
// The JSON doesn't list immediates as const
101101
let IntrinsicType {
102102
ref mut constant, ..
103-
} = arg.ty.0;
103+
} = arg.ty.data;
104104
if arg.name.starts_with("imm") {
105105
*constant = true
106106
}

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, S
55
impl IntrinsicTypeDefinition for ArmIntrinsicType {
66
/// Gets a string containing the typename for this type in C format.
77
fn c_type(&self) -> String {
8-
let prefix = self.0.kind.c_prefix();
9-
let const_prefix = if self.0.constant { "const " } else { "" };
8+
let prefix = self.kind.c_prefix();
9+
let const_prefix = if self.constant { "const " } else { "" };
1010

1111
if let (Some(bit_len), simd_len, vec_len) =
12-
(self.0.bit_len, self.0.simd_len, self.0.vec_len)
12+
(self.bit_len, self.simd_len, self.vec_len)
1313
{
1414
match (simd_len, vec_len) {
1515
(None, None) => format!("{const_prefix}{prefix}{bit_len}_t"),
@@ -23,10 +23,10 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
2323
}
2424

2525
fn c_single_vector_type(&self) -> String {
26-
if let (Some(bit_len), Some(simd_len)) = (self.0.bit_len, self.0.simd_len) {
26+
if let (Some(bit_len), Some(simd_len)) = (self.bit_len, self.simd_len) {
2727
format!(
2828
"{prefix}{bit_len}x{simd_len}_t",
29-
prefix = self.0.kind.c_prefix()
29+
prefix = self.kind.c_prefix()
3030
)
3131
} else {
3232
unreachable!("Shouldn't be called on this type")
@@ -40,17 +40,16 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
4040
bit_len: Some(bl),
4141
simd_len,
4242
vec_len,
43-
target,
4443
..
45-
} = &self.0
44+
} = &self.data
4645
{
4746
let quad = if simd_len.unwrap_or(1) * bl > 64 {
4847
"q"
4948
} else {
5049
""
5150
};
5251

53-
let choose_workaround = language == Language::C && target.contains("v7");
52+
let choose_workaround = language == Language::C && self.target.contains("v7");
5453
format!(
5554
"vld{len}{quad}_{type}{size}",
5655
type = match k {
@@ -78,7 +77,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
7877
bit_len: Some(bl),
7978
simd_len,
8079
..
81-
} = &self.0
80+
} = &self.data
8281
{
8382
let quad = if (simd_len.unwrap_or(1) * bl) > 64 {
8483
"q"
@@ -101,8 +100,10 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
101100
todo!("get_lane_function IntrinsicType: {:#?}", self)
102101
}
103102
}
103+
}
104104

105-
fn from_c(s: &str, target: &str) -> Result<Self, String> {
105+
impl ArmIntrinsicType {
106+
pub fn from_c(s: &str, target: &str) -> Result<Self, String> {
106107
const CONST_STR: &str = "const";
107108
if let Some(s) = s.strip_suffix('*') {
108109
let (s, constant) = match s.trim().strip_suffix(CONST_STR) {
@@ -143,32 +144,34 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
143144
),
144145
None => None,
145146
};
146-
Ok(ArmIntrinsicType(IntrinsicType {
147+
Ok(ArmIntrinsicType{
148+
data: IntrinsicType {
147149
ptr: false,
148150
ptr_constant: false,
149151
constant,
150152
kind: arg_kind,
151153
bit_len: Some(bit_len),
152154
simd_len,
153155
vec_len,
154-
target: target.to_string(),
155-
}))
156+
},
157+
target: target.to_string()})
156158
} else {
157159
let kind = start.parse::<TypeKind>()?;
158160
let bit_len = match kind {
159161
TypeKind::Int(_) => Some(32),
160162
_ => None,
161163
};
162-
Ok(ArmIntrinsicType(IntrinsicType {
164+
Ok(ArmIntrinsicType{
165+
data: IntrinsicType {
163166
ptr: false,
164167
ptr_constant: false,
165168
constant,
166169
kind: start.parse::<TypeKind>()?,
167170
bit_len,
168171
simd_len: None,
169172
vec_len: None,
170-
target: target.to_string(),
171-
}))
173+
},
174+
target: target.to_string()})
172175
}
173176
}
174177
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ pub struct IntrinsicType {
120120
/// rows encoded in the type (e.g. uint8x8_t).
121121
/// A value of `None` can be assumed to be 1 though.
122122
pub vec_len: Option<u32>,
123-
124-
pub target: String,
125123
}
126124

127125
impl IntrinsicType {
@@ -321,11 +319,6 @@ pub trait IntrinsicTypeDefinition: Deref<Target = IntrinsicType> {
321319
/// can be implemented in an `impl` block
322320
fn get_lane_function(&self) -> String;
323321

324-
/// can be implemented in an `impl` block
325-
fn from_c(_s: &str, _target: &str) -> Result<Self, String>
326-
where
327-
Self: Sized;
328-
329322
/// Gets a string containing the typename for this type in C format.
330323
/// can be directly defined in `impl` blocks
331324
fn c_type(&self) -> String;

0 commit comments

Comments
 (0)