Skip to content

Commit 1f39d69

Browse files
feat: updated IntrinsicType to maintain metadata instead of target, for
varying architecture uses
1 parent dca2fd9 commit 1f39d69

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ fn json_to_intrinsic(
7979
) -> Result<Intrinsic<ArmIntrinsicType>, Box<dyn std::error::Error>> {
8080
let name = intr.name.replace(['[', ']'], "");
8181

82-
let results = ArmIntrinsicType::from_c(&intr.return_type.value, target)?;
82+
let mut results = ArmIntrinsicType::from_c(&intr.return_type.value)?;
83+
results.set_metadata("target", target);
8384

8485
let args = intr
8586
.arguments
@@ -91,8 +92,9 @@ fn json_to_intrinsic(
9192
let metadata = metadata.and_then(|a| a.remove(arg_name));
9293
let arg_prep: Option<ArgPrep> = metadata.and_then(|a| a.try_into().ok());
9394
let constraint: Option<Constraint> = arg_prep.and_then(|a| a.try_into().ok());
94-
let ty = ArmIntrinsicType::from_c(type_name, target)
95+
let mut ty = ArmIntrinsicType::from_c(type_name)
9596
.unwrap_or_else(|_| panic!("Failed to parse argument '{arg}'"));
97+
ty.set_metadata("target", target);
9698

9799
let mut arg =
98100
Argument::<ArmIntrinsicType>::new(i, String::from(arg_name), ty, constraint);

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::collections::HashMap;
2+
13
use super::intrinsic::ArmIntrinsicType;
24
use crate::common::cli::Language;
35
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, Sign, TypeKind};
@@ -40,7 +42,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
4042
bit_len: Some(bl),
4143
simd_len,
4244
vec_len,
43-
target,
45+
metadata,
4446
..
4547
} = &self.0
4648
{
@@ -50,7 +52,8 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
5052
""
5153
};
5254

53-
let choose_workaround = language == Language::C && target.contains("v7");
55+
let choose_workaround = language == Language::C
56+
&& metadata.get("target").is_some_and(|val| val.contains("v7"));
5457
format!(
5558
"vld{len}{quad}_{type}{size}",
5659
type = match k {
@@ -102,15 +105,16 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
102105
}
103106
}
104107

105-
fn from_c(s: &str, target: &str) -> Result<Self, String> {
108+
fn from_c(s: &str) -> Result<Self, String> {
106109
const CONST_STR: &str = "const";
110+
let metadata: HashMap<String, String> = HashMap::new();
107111
if let Some(s) = s.strip_suffix('*') {
108112
let (s, constant) = match s.trim().strip_suffix(CONST_STR) {
109113
Some(stripped) => (stripped, true),
110114
None => (s, false),
111115
};
112116
let s = s.trim_end();
113-
let temp_return = ArmIntrinsicType::from_c(s, target);
117+
let temp_return = ArmIntrinsicType::from_c(s);
114118
temp_return.map(|mut op| {
115119
op.ptr = true;
116120
op.ptr_constant = constant;
@@ -151,7 +155,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
151155
bit_len: Some(bit_len),
152156
simd_len,
153157
vec_len,
154-
target: target.to_string(),
158+
metadata,
155159
}))
156160
} else {
157161
let kind = start.parse::<TypeKind>()?;
@@ -167,7 +171,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
167171
bit_len,
168172
simd_len: None,
169173
vec_len: None,
170-
target: target.to_string(),
174+
metadata,
171175
}))
172176
}
173177
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::HashMap;
12
use std::fmt;
23
use std::ops::Deref;
34
use std::str::FromStr;
@@ -121,7 +122,7 @@ pub struct IntrinsicType {
121122
/// A value of `None` can be assumed to be 1 though.
122123
pub vec_len: Option<u32>,
123124

124-
pub target: String,
125+
pub metadata: HashMap<String, String>,
125126
}
126127

127128
impl IntrinsicType {
@@ -153,6 +154,10 @@ impl IntrinsicType {
153154
self.ptr
154155
}
155156

157+
pub fn set_metadata(&mut self, key: &str, value: &str) {
158+
self.metadata.insert(key.to_string(), value.to_string());
159+
}
160+
156161
pub fn c_scalar_type(&self) -> String {
157162
match self.kind() {
158163
TypeKind::Char(_) => String::from("char"),
@@ -322,7 +327,7 @@ pub trait IntrinsicTypeDefinition: Deref<Target = IntrinsicType> {
322327
fn get_lane_function(&self) -> String;
323328

324329
/// can be implemented in an `impl` block
325-
fn from_c(_s: &str, _target: &str) -> Result<Self, String>
330+
fn from_c(_s: &str) -> Result<Self, String>
326331
where
327332
Self: Sized;
328333

0 commit comments

Comments
 (0)