Skip to content

Commit 23674fb

Browse files
feat: added functionality to convert XML description of intrinsics to
intrinsic-test's X86IntrinsicType struct
1 parent c009f9f commit 23674fb

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

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

Lines changed: 9 additions & 0 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
}

crates/intrinsic-test/src/x86/xml_parser.rs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use crate::common::{
2-
argument::Argument, intrinsic::Intrinsic, intrinsic_helpers::IntrinsicTypeDefinition,
3-
};
1+
use crate::common::argument::{Argument, ArgumentList};
2+
use crate::common::intrinsic::Intrinsic;
3+
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition};
4+
45
use serde::{Deserialize, Deserializer};
56
use std::path::Path;
67

@@ -49,6 +50,10 @@ struct Parameter {
4950
type_data: String,
5051
#[serde(rename = "@etype", default)]
5152
etype: String,
53+
#[serde(rename = "@memwidth", default)]
54+
memwidth: u8,
55+
#[serde(rename = "@varname", default)]
56+
var_name: String,
5257
}
5358

5459
#[derive(Deserialize)]
@@ -84,21 +89,39 @@ pub fn get_xml_intrinsics(
8489
Ok(parsed_intrinsics)
8590
}
8691

87-
pub fn xml_to_intrinsic(
88-
mut intr: XMLIntrinsic,
92+
fn xml_to_intrinsic(
93+
intr: XMLIntrinsic,
8994
target: &String,
9095
) -> Result<Intrinsic<X86IntrinsicType>, Box<dyn std::error::Error>> {
9196
let name = intr.name;
9297
let results = X86IntrinsicType::from_c(&intr.return_data.type_data, target)?;
9398

94-
let arguments: Vec<_> = intr
99+
let args: Vec<_> = intr
95100
.parameters
96101
.into_iter()
97102
.enumerate()
98-
.map(|(i, arg)| {
99-
// let arg_name = Argument::<X86IntrinsicType>::type_and_name_from_c(&arg).1;
103+
.map(|(i, param)| {
104+
let constraint = None;
105+
let ty = X86IntrinsicType::from_c(param.type_data.as_str(), target)
106+
.unwrap_or_else(|_| panic!("Failed to parse argument '{i}'"));
107+
108+
let mut arg = Argument::<X86IntrinsicType>::new(i, param.var_name, ty, constraint);
109+
let IntrinsicType {
110+
ref mut constant, ..
111+
} = arg.ty.0;
112+
if param.etype == "IMM" {
113+
*constant = true
114+
}
115+
arg
100116
})
101117
.collect();
102118

103-
todo!("xml_to_intrinsic needs to collect the arguments properly!");
119+
let arguments = ArgumentList::<X86IntrinsicType> { args };
120+
121+
Ok(Intrinsic {
122+
name,
123+
arguments,
124+
results: results,
125+
arch_tags: intr.cpuid,
126+
})
104127
}

0 commit comments

Comments
 (0)