|
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 |
|
@@ -49,6 +50,10 @@ struct Parameter {
|
49 | 50 | type_data: String,
|
50 | 51 | #[serde(rename = "@etype", default)]
|
51 | 52 | etype: String,
|
| 53 | + #[serde(rename = "@memwidth", default)] |
| 54 | + memwidth: u8, |
| 55 | + #[serde(rename = "@varname", default)] |
| 56 | + var_name: String, |
52 | 57 | }
|
53 | 58 |
|
54 | 59 | #[derive(Deserialize)]
|
@@ -84,21 +89,39 @@ pub fn get_xml_intrinsics(
|
84 | 89 | Ok(parsed_intrinsics)
|
85 | 90 | }
|
86 | 91 |
|
87 |
| -pub fn xml_to_intrinsic( |
88 |
| - mut intr: XMLIntrinsic, |
| 92 | +fn xml_to_intrinsic( |
| 93 | + intr: XMLIntrinsic, |
89 | 94 | target: &String,
|
90 | 95 | ) -> Result<Intrinsic<X86IntrinsicType>, Box<dyn std::error::Error>> {
|
91 | 96 | let name = intr.name;
|
92 | 97 | let results = X86IntrinsicType::from_c(&intr.return_data.type_data, target)?;
|
93 | 98 |
|
94 |
| - let arguments: Vec<_> = intr |
| 99 | + let args: Vec<_> = intr |
95 | 100 | .parameters
|
96 | 101 | .into_iter()
|
97 | 102 | .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 |
100 | 116 | })
|
101 | 117 | .collect();
|
102 | 118 |
|
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 | + }) |
104 | 127 | }
|
0 commit comments