Skip to content

Commit 49d9802

Browse files
feat: updated Argument<T> type for functional compatibility with other
architectures too
1 parent 644e34e commit 49d9802

File tree

4 files changed

+32
-30
lines changed

4 files changed

+32
-30
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use crate::arm::intrinsic::ArmIntrinsicType;
2+
use crate::common::argument::Argument;
3+
4+
// This functionality is present due to the nature
5+
// of how intrinsics are defined in the JSON source
6+
// of ARM intrinsics.
7+
impl Argument<ArmIntrinsicType> {
8+
pub fn type_and_name_from_c(arg: &str) -> (&str, &str) {
9+
let split_index = arg
10+
.rfind([' ', '*'])
11+
.expect("Couldn't split type and argname");
12+
13+
(arg[..split_index + 1].trim_end(), &arg[split_index + 1..])
14+
}
15+
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,16 @@ fn json_to_intrinsic(
8686
.into_iter()
8787
.enumerate()
8888
.map(|(i, arg)| {
89-
let arg_name = Argument::<ArmIntrinsicType>::type_and_name_from_c(&arg).1;
89+
let (type_name, arg_name) = Argument::<ArmIntrinsicType>::type_and_name_from_c(&arg);
9090
let metadata = intr.args_prep.as_mut();
9191
let metadata = metadata.and_then(|a| a.remove(arg_name));
9292
let arg_prep: Option<ArgPrep> = metadata.and_then(|a| a.try_into().ok());
9393
let constraint: Option<Constraint> = arg_prep.and_then(|a| a.try_into().ok());
94+
let ty = ArmIntrinsicType::from_c(type_name, target)
95+
.unwrap_or_else(|_| panic!("Failed to parse argument '{arg}'"));
9496

95-
let mut arg = Argument::<ArmIntrinsicType>::from_c(i, &arg, target, constraint);
97+
let mut arg =
98+
Argument::<ArmIntrinsicType>::new(i, String::from(arg_name), ty, constraint);
9699

97100
// The JSON doesn't list immediates as const
98101
let IntrinsicType {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
mod argument;
12
mod compile;
23
mod config;
34
mod intrinsic;
45
mod json_parser;
56
mod types;
67

7-
use std::fs::File;
8+
use std::fs::{self, File};
89

910
use rayon::prelude::*;
1011

@@ -72,6 +73,7 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
7273
let cpp_compiler = compile::build_cpp_compilation(&self.cli_options).unwrap();
7374

7475
let notice = &build_notices("// ");
76+
fs::create_dir_all("c_programs").unwrap();
7577
self.intrinsics
7678
.par_chunks(chunk_size)
7779
.enumerate()

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

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ impl<T> Argument<T>
2020
where
2121
T: IntrinsicTypeDefinition,
2222
{
23+
pub fn new(pos: usize, name: String, ty: T, constraint: Option<Constraint>) -> Self {
24+
Argument {
25+
pos,
26+
name,
27+
ty,
28+
constraint,
29+
}
30+
}
31+
2332
pub fn to_c_type(&self) -> String {
2433
self.ty.c_type()
2534
}
@@ -36,14 +45,6 @@ where
3645
self.constraint.is_some()
3746
}
3847

39-
pub fn type_and_name_from_c(arg: &str) -> (&str, &str) {
40-
let split_index = arg
41-
.rfind([' ', '*'])
42-
.expect("Couldn't split type and argname");
43-
44-
(arg[..split_index + 1].trim_end(), &arg[split_index + 1..])
45-
}
46-
4748
/// The binding keyword (e.g. "const" or "let") for the array of possible test inputs.
4849
fn rust_vals_array_binding(&self) -> impl std::fmt::Display {
4950
if self.ty.is_rust_vals_array_const() {
@@ -62,25 +63,6 @@ where
6263
}
6364
}
6465

65-
pub fn from_c(
66-
pos: usize,
67-
arg: &str,
68-
target: &str,
69-
constraint: Option<Constraint>,
70-
) -> Argument<T> {
71-
let (ty, var_name) = Self::type_and_name_from_c(arg);
72-
73-
let ty =
74-
T::from_c(ty, target).unwrap_or_else(|_| panic!("Failed to parse argument '{arg}'"));
75-
76-
Argument {
77-
pos,
78-
name: String::from(var_name),
79-
ty: ty,
80-
constraint,
81-
}
82-
}
83-
8466
fn as_call_param_c(&self) -> String {
8567
self.ty.as_call_param_c(&self.name)
8668
}

0 commit comments

Comments
 (0)