Skip to content

Commit 1791b35

Browse files
Updated Argument::from_c to remove ArgPrep specific argument
1 parent 90249a3 commit 1791b35

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

Diff for: crates/intrinsic-test/src/arm/argument.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ use super::format::Indentation;
22
use super::json_parser::ArgPrep;
33
use super::types::{IntrinsicType, TypeKind};
44
use crate::common::types::Language;
5+
use serde::Deserialize;
6+
use serde_json::Value;
7+
use std::collections::HashMap;
58
use std::ops::Range;
69

710
/// An argument for the intrinsic.
@@ -17,7 +20,7 @@ pub struct Argument {
1720
pub constraints: Vec<Constraint>,
1821
}
1922

20-
#[derive(Debug, PartialEq, Clone)]
23+
#[derive(Debug, PartialEq, Clone, Deserialize)]
2124
pub enum Constraint {
2225
Equal(i64),
2326
Range(Range<i64>),
@@ -79,12 +82,26 @@ impl Argument {
7982
}
8083

8184
// ARM-specific
82-
pub fn from_c(pos: usize, arg: &str, arg_prep: Option<ArgPrep>, target: &String) -> Argument {
85+
pub fn from_c(
86+
pos: usize,
87+
arg: &str,
88+
target: &String,
89+
metadata: Option<&mut HashMap<String, Value>>,
90+
) -> Argument {
8391
let (ty, var_name) = Self::type_and_name_from_c(arg);
8492

8593
let ty = IntrinsicType::from_c(ty, target)
8694
.unwrap_or_else(|_| panic!("Failed to parse argument '{arg}'"));
8795

96+
let arg_name = Argument::type_and_name_from_c(&arg).1;
97+
let arg = metadata.and_then(|a| a.remove(arg_name));
98+
let arg_prep: Option<ArgPrep> = arg.and_then(|a| {
99+
if let Value::Object(_) = a {
100+
a.try_into().ok()
101+
} else {
102+
None
103+
}
104+
});
88105
let constraint = arg_prep.and_then(|a| a.try_into().ok());
89106

90107
Argument {

Diff for: crates/intrinsic-test/src/arm/json_parser.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::argument::{Argument, ArgumentList};
22
use super::intrinsic::Intrinsic;
33
use super::types::IntrinsicType;
44
use serde::Deserialize;
5+
use serde_json::Value;
56
use std::collections::HashMap;
67
use std::path::Path;
78

@@ -28,6 +29,14 @@ pub enum ArgPrep {
2829
Nothing {},
2930
}
3031

32+
impl TryFrom<Value> for ArgPrep {
33+
type Error = serde_json::Error;
34+
35+
fn try_from(value: Value) -> Result<Self, Self::Error> {
36+
serde_json::from_value(value)
37+
}
38+
}
39+
3140
#[derive(Deserialize, Debug)]
3241
struct JsonIntrinsic {
3342
#[serde(rename = "SIMD_ISA")]
@@ -36,7 +45,7 @@ struct JsonIntrinsic {
3645
arguments: Vec<String>,
3746
return_type: ReturnType,
3847
#[serde(rename = "Arguments_Preparation")]
39-
args_prep: Option<HashMap<String, ArgPrep>>,
48+
args_prep: Option<HashMap<String, Value>>,
4049
#[serde(rename = "Architectures")]
4150
architectures: Vec<String>,
4251
}
@@ -70,15 +79,13 @@ fn json_to_intrinsic(
7079

7180
let results = IntrinsicType::from_c(&intr.return_type.value, target)?;
7281

73-
let mut args_prep = intr.args_prep.as_mut();
7482
let args = intr
7583
.arguments
7684
.into_iter()
7785
.enumerate()
7886
.map(|(i, arg)| {
79-
let arg_name = Argument::type_and_name_from_c(&arg).1;
80-
let arg_prep = args_prep.as_mut().and_then(|a| a.remove(arg_name));
81-
let mut arg = Argument::from_c(i, &arg, arg_prep, target);
87+
// let arg_name = Argument::type_and_name_from_c(&arg).1;
88+
let mut arg = Argument::from_c(i, &arg, target, intr.args_prep.as_mut());
8289
// The JSON doesn't list immediates as const
8390
if let IntrinsicType::Type {
8491
ref mut constant, ..

0 commit comments

Comments
 (0)