Skip to content

Commit dca2fd9

Browse files
feat: updated Argument<T> type for functional compatibility with other
architectures too
1 parent 044297a commit dca2fd9

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use crate::arm::intrinsic::ArmIntrinsicType;
2+
use crate::common::argument::Argument;
3+
4+
impl Argument<ArmIntrinsicType> {
5+
pub fn type_and_name_from_c(arg: &str) -> (&str, &str) {
6+
let split_index = arg
7+
.rfind([' ', '*'])
8+
.expect("Couldn't split type and argname");
9+
10+
(arg[..split_index + 1].trim_end(), &arg[split_index + 1..])
11+
}
12+
}

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: 7 additions & 5 deletions
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_wrapped = compile::build_cpp_compilation(&self.cli_options);
7374

7475
let notice = &build_notices("// ");
76+
fs::create_dir_all("c_programs").unwrap();
7577
self.intrinsics
7678
.par_chunks(chunk_size)
7779
.enumerate()
@@ -81,7 +83,7 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
8183
write_mod_cpp(&mut file, notice, c_target, platform_headers, chunk).unwrap();
8284

8385
// compile this cpp file into a .o file
84-
if let Some(cpp_compiler) = cpp_compiler_wrapped.as_ref() {
86+
if let Some(cpp_compiler) = cpp_compiler_wrapped.as_ref() {
8587
let output = cpp_compiler
8688
.compile_object_file(&format!("mod_{i}.cpp"), &format!("mod_{i}.o"))?;
8789
assert!(output.status.success(), "{output:?}");
@@ -104,17 +106,17 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
104106
// This is done because `cpp_compiler_wrapped` is None when
105107
// the --generate-only flag is passed
106108
if let Some(cpp_compiler) = cpp_compiler_wrapped.as_ref() {
107-
// compile this cpp file into a .o file
109+
// compile this cpp file into a .o file
108110
info!("compiling main.cpp");
109111
let output = cpp_compiler
110112
.compile_object_file("main.cpp", "intrinsic-test-programs.o")
111113
.unwrap();
112114
assert!(output.status.success(), "{output:?}");
113-
115+
114116
let object_files = (0..chunk_count)
115117
.map(|i| format!("mod_{i}.o"))
116118
.chain(["intrinsic-test-programs.o".to_owned()]);
117-
119+
118120
let output = cpp_compiler
119121
.link_executable(object_files, "intrinsic-test-programs")
120122
.unwrap();

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
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ pub fn compile_rust_programs(toolchain: Option<&str>, target: &str, linker: Opti
130130
/* If there has been a linker explicitly set from the command line then
131131
* we want to set it via setting it in the RUSTFLAGS*/
132132

133-
// This is done because `toolchain` is None when
134-
// the --generate-only flag is passed
133+
// This is done because `toolchain` is None when
134+
// the --generate-only flag is passed
135135
if toolchain.is_none() {
136136
return true;
137137
}

0 commit comments

Comments
 (0)