|
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 | + |
4 | 5 | use serde::{Deserialize, Deserializer};
|
5 | 6 | use std::path::Path;
|
6 | 7 |
|
|
19 | 20 | }
|
20 | 21 | }
|
21 | 22 |
|
| 23 | +// Custom deserializer function to convert strings to u16 |
| 24 | +fn string_to_u16<'de, D>(deserializer: D) -> Result<u16, D::Error> |
| 25 | +where |
| 26 | + D: Deserializer<'de>, |
| 27 | +{ |
| 28 | + let s = String::deserialize(deserializer)?; |
| 29 | + return Ok(s.as_str().parse::<u16>().unwrap_or(0u16)); |
| 30 | +} |
| 31 | + |
22 | 32 | #[derive(Deserialize)]
|
23 | 33 | struct Data {
|
24 | 34 | #[serde(rename = "intrinsic", default)]
|
@@ -49,6 +59,10 @@ struct Parameter {
|
49 | 59 | type_data: String,
|
50 | 60 | #[serde(rename = "@etype", default)]
|
51 | 61 | etype: String,
|
| 62 | + #[serde(rename = "@memwidth", default, deserialize_with = "string_to_u16")] |
| 63 | + memwidth: u16, |
| 64 | + #[serde(rename = "@varname", default)] |
| 65 | + var_name: String, |
52 | 66 | }
|
53 | 67 |
|
54 | 68 | #[derive(Deserialize)]
|
@@ -84,21 +98,39 @@ pub fn get_xml_intrinsics(
|
84 | 98 | Ok(parsed_intrinsics)
|
85 | 99 | }
|
86 | 100 |
|
87 |
| -pub fn xml_to_intrinsic( |
88 |
| - mut intr: XMLIntrinsic, |
| 101 | +fn xml_to_intrinsic( |
| 102 | + intr: XMLIntrinsic, |
89 | 103 | target: &String,
|
90 | 104 | ) -> Result<Intrinsic<X86IntrinsicType>, Box<dyn std::error::Error>> {
|
91 | 105 | let name = intr.name;
|
92 | 106 | let results = X86IntrinsicType::from_c(&intr.return_data.type_data, target)?;
|
93 | 107 |
|
94 |
| - let arguments: Vec<_> = intr |
| 108 | + let args: Vec<_> = intr |
95 | 109 | .parameters
|
96 | 110 | .into_iter()
|
97 | 111 | .enumerate()
|
98 |
| - .map(|(i, arg)| { |
99 |
| - // let arg_name = Argument::<X86IntrinsicType>::type_and_name_from_c(&arg).1; |
| 112 | + .map(|(i, param)| { |
| 113 | + let constraint = None; |
| 114 | + let ty = X86IntrinsicType::from_c(param.type_data.as_str(), target) |
| 115 | + .unwrap_or_else(|_| panic!("Failed to parse argument '{i}'")); |
| 116 | + |
| 117 | + let mut arg = Argument::<X86IntrinsicType>::new(i, param.var_name, ty, constraint); |
| 118 | + let IntrinsicType { |
| 119 | + ref mut constant, .. |
| 120 | + } = arg.ty.0; |
| 121 | + if param.etype == "IMM" { |
| 122 | + *constant = true |
| 123 | + } |
| 124 | + arg |
100 | 125 | })
|
101 | 126 | .collect();
|
102 | 127 |
|
103 |
| - todo!("xml_to_intrinsic needs to collect the arguments properly!"); |
| 128 | + let arguments = ArgumentList::<X86IntrinsicType> { args }; |
| 129 | + |
| 130 | + Ok(Intrinsic { |
| 131 | + name, |
| 132 | + arguments, |
| 133 | + results: results, |
| 134 | + arch_tags: intr.cpuid, |
| 135 | + }) |
104 | 136 | }
|
0 commit comments