Merge pull request #1887 from madhav-madhusoodanan/intrinsic-test-argument-cleanup
Feat: updated Argument<T> type for functional compatibility with other architectures
This commit is contained in:
commit
213fd4e2e6
4 changed files with 32 additions and 30 deletions
15
library/stdarch/crates/intrinsic-test/src/arm/argument.rs
Normal file
15
library/stdarch/crates/intrinsic-test/src/arm/argument.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use crate::arm::intrinsic::ArmIntrinsicType;
|
||||
use crate::common::argument::Argument;
|
||||
|
||||
// This functionality is present due to the nature
|
||||
// of how intrinsics are defined in the JSON source
|
||||
// of ARM intrinsics.
|
||||
impl Argument<ArmIntrinsicType> {
|
||||
pub fn type_and_name_from_c(arg: &str) -> (&str, &str) {
|
||||
let split_index = arg
|
||||
.rfind([' ', '*'])
|
||||
.expect("Couldn't split type and argname");
|
||||
|
||||
(arg[..split_index + 1].trim_end(), &arg[split_index + 1..])
|
||||
}
|
||||
}
|
||||
|
|
@ -86,13 +86,16 @@ fn json_to_intrinsic(
|
|||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(i, arg)| {
|
||||
let arg_name = Argument::<ArmIntrinsicType>::type_and_name_from_c(&arg).1;
|
||||
let (type_name, arg_name) = Argument::<ArmIntrinsicType>::type_and_name_from_c(&arg);
|
||||
let metadata = intr.args_prep.as_mut();
|
||||
let metadata = metadata.and_then(|a| a.remove(arg_name));
|
||||
let arg_prep: Option<ArgPrep> = metadata.and_then(|a| a.try_into().ok());
|
||||
let constraint: Option<Constraint> = arg_prep.and_then(|a| a.try_into().ok());
|
||||
let ty = ArmIntrinsicType::from_c(type_name, target)
|
||||
.unwrap_or_else(|_| panic!("Failed to parse argument '{arg}'"));
|
||||
|
||||
let mut arg = Argument::<ArmIntrinsicType>::from_c(i, &arg, target, constraint);
|
||||
let mut arg =
|
||||
Argument::<ArmIntrinsicType>::new(i, String::from(arg_name), ty, constraint);
|
||||
|
||||
// The JSON doesn't list immediates as const
|
||||
let IntrinsicType {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
mod argument;
|
||||
mod compile;
|
||||
mod config;
|
||||
mod intrinsic;
|
||||
mod json_parser;
|
||||
mod types;
|
||||
|
||||
use std::fs::File;
|
||||
use std::fs::{self, File};
|
||||
|
||||
use rayon::prelude::*;
|
||||
|
||||
|
|
@ -72,6 +73,7 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
|
|||
let cpp_compiler = compile::build_cpp_compilation(&self.cli_options).unwrap();
|
||||
|
||||
let notice = &build_notices("// ");
|
||||
fs::create_dir_all("c_programs").unwrap();
|
||||
self.intrinsics
|
||||
.par_chunks(chunk_size)
|
||||
.enumerate()
|
||||
|
|
|
|||
|
|
@ -20,6 +20,15 @@ impl<T> Argument<T>
|
|||
where
|
||||
T: IntrinsicTypeDefinition,
|
||||
{
|
||||
pub fn new(pos: usize, name: String, ty: T, constraint: Option<Constraint>) -> Self {
|
||||
Argument {
|
||||
pos,
|
||||
name,
|
||||
ty,
|
||||
constraint,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_c_type(&self) -> String {
|
||||
self.ty.c_type()
|
||||
}
|
||||
|
|
@ -36,14 +45,6 @@ where
|
|||
self.constraint.is_some()
|
||||
}
|
||||
|
||||
pub fn type_and_name_from_c(arg: &str) -> (&str, &str) {
|
||||
let split_index = arg
|
||||
.rfind([' ', '*'])
|
||||
.expect("Couldn't split type and argname");
|
||||
|
||||
(arg[..split_index + 1].trim_end(), &arg[split_index + 1..])
|
||||
}
|
||||
|
||||
/// The binding keyword (e.g. "const" or "let") for the array of possible test inputs.
|
||||
fn rust_vals_array_binding(&self) -> impl std::fmt::Display {
|
||||
if self.ty.is_rust_vals_array_const() {
|
||||
|
|
@ -62,25 +63,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub fn from_c(
|
||||
pos: usize,
|
||||
arg: &str,
|
||||
target: &str,
|
||||
constraint: Option<Constraint>,
|
||||
) -> Argument<T> {
|
||||
let (ty, var_name) = Self::type_and_name_from_c(arg);
|
||||
|
||||
let ty =
|
||||
T::from_c(ty, target).unwrap_or_else(|_| panic!("Failed to parse argument '{arg}'"));
|
||||
|
||||
Argument {
|
||||
pos,
|
||||
name: String::from(var_name),
|
||||
ty: ty,
|
||||
constraint,
|
||||
}
|
||||
}
|
||||
|
||||
fn as_call_param_c(&self) -> String {
|
||||
self.ty.as_call_param_c(&self.name)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue