|
1 | 1 | use itertools::Itertools; |
2 | 2 | use std::process::Command; |
3 | 3 |
|
| 4 | +use crate::common::argument::ArgumentList; |
4 | 5 | use crate::common::intrinsic::Intrinsic; |
5 | 6 |
|
6 | 7 | use super::indentation::Indentation; |
7 | 8 | use super::intrinsic_helpers::IntrinsicTypeDefinition; |
8 | 9 |
|
9 | 10 | // The number of times each intrinsic will be called. |
10 | | -const PASSES: u32 = 20; |
| 11 | +pub(crate) const PASSES: u32 = 20; |
| 12 | + |
| 13 | +macro_rules! concatln { |
| 14 | + ($($lines:expr),* $(,)?) => { |
| 15 | + concat!($( $lines, "\n" ),*) |
| 16 | + }; |
| 17 | +} |
11 | 18 |
|
12 | 19 | fn write_cargo_toml_header(w: &mut impl std::io::Write, name: &str) -> std::io::Result<()> { |
13 | 20 | writeln!( |
14 | 21 | w, |
15 | | - concat!( |
16 | | - "[package]\n", |
17 | | - "name = \"{name}\"\n", |
18 | | - "version = \"{version}\"\n", |
19 | | - "authors = [{authors}]\n", |
20 | | - "license = \"{license}\"\n", |
21 | | - "edition = \"2018\"\n", |
| 22 | + concatln!( |
| 23 | + "[package]", |
| 24 | + "name = \"{name}\"", |
| 25 | + "version = \"{version}\"", |
| 26 | + "authors = [{authors}]", |
| 27 | + "license = \"{license}\"", |
| 28 | + "edition = \"2018\"", |
22 | 29 | ), |
23 | 30 | name = name, |
24 | 31 | version = env!("CARGO_PKG_VERSION"), |
@@ -118,6 +125,20 @@ pub fn write_lib_rs<T: IntrinsicTypeDefinition>( |
118 | 125 |
|
119 | 126 | writeln!(w, "{definitions}")?; |
120 | 127 |
|
| 128 | + let mut seen = std::collections::HashSet::new(); |
| 129 | + |
| 130 | + for intrinsic in intrinsics { |
| 131 | + for arg in &intrinsic.arguments.args { |
| 132 | + if !arg.has_constraint() && arg.ty.is_rust_vals_array_const() { |
| 133 | + let name = arg.rust_vals_array_name().to_string(); |
| 134 | + |
| 135 | + if seen.insert(name) { |
| 136 | + ArgumentList::gen_arg_rust(arg, w, Indentation::default(), PASSES)?; |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | + |
121 | 142 | for intrinsic in intrinsics { |
122 | 143 | crate::common::gen_rust::create_rust_test_module(w, intrinsic)?; |
123 | 144 | } |
@@ -232,23 +253,23 @@ pub fn generate_rust_test_loop<T: IntrinsicTypeDefinition>( |
232 | 253 | } |
233 | 254 | } |
234 | 255 |
|
235 | | - let indentation2 = indentation.nested(); |
236 | | - let indentation3 = indentation2.nested(); |
237 | | - writeln!( |
| 256 | + write!( |
238 | 257 | w, |
239 | | - "\ |
240 | | - for (id, f) in specializations {{\n\ |
241 | | - for i in 0..{passes} {{\n\ |
242 | | - unsafe {{\n\ |
243 | | - {loaded_args}\ |
244 | | - let __return_value = f({args});\n\ |
245 | | - println!(\"Result {{id}}-{{}}: {{:?}}\", i + 1, {return_value});\n\ |
246 | | - }}\n\ |
247 | | - }}\n\ |
248 | | - }}", |
249 | | - loaded_args = intrinsic.arguments.load_values_rust(indentation3), |
| 258 | + concatln!( |
| 259 | + " for (id, f) in specializations {{", |
| 260 | + " for i in 0..{passes} {{", |
| 261 | + " unsafe {{", |
| 262 | + "{loaded_args}", |
| 263 | + " let __return_value = f({args});", |
| 264 | + " println!(\"Result {{id}}-{{}}: {{:?}}\", i + 1, {return_value});", |
| 265 | + " }}", |
| 266 | + " }}", |
| 267 | + " }}", |
| 268 | + ), |
| 269 | + loaded_args = intrinsic.arguments.load_values_rust(indentation.nest_by(4)), |
250 | 270 | args = intrinsic.arguments.as_call_param_rust(), |
251 | 271 | return_value = intrinsic.results.print_result_rust(), |
| 272 | + passes = passes, |
252 | 273 | ) |
253 | 274 | } |
254 | 275 |
|
|
0 commit comments