|
1 | | -use super::gen_c::create_c_test_program; |
2 | | -use super::gen_c::setup_c_file_paths; |
| 1 | +use std::fs::File; |
| 2 | +use std::io::Write; |
| 3 | + |
3 | 4 | use super::gen_rust::{create_rust_test_program, setup_rust_file_paths}; |
4 | 5 | use super::intrinsic::IntrinsicDefinition; |
5 | 6 | use super::intrinsic_helpers::IntrinsicTypeDefinition; |
6 | | -use std::fs::File; |
7 | | -use std::io::Write; |
8 | 7 |
|
9 | 8 | pub fn write_file(filename: &String, code: String) { |
10 | 9 | let mut file = File::create(filename).unwrap(); |
11 | 10 | file.write_all(code.into_bytes().as_slice()).unwrap(); |
12 | 11 | } |
13 | 12 |
|
14 | 13 | pub fn write_c_testfiles<T: IntrinsicTypeDefinition + Sized>( |
15 | | - intrinsics: &Vec<&dyn IntrinsicDefinition<T>>, |
| 14 | + intrinsics: &[&dyn IntrinsicDefinition<T>], |
16 | 15 | target: &str, |
17 | 16 | c_target: &str, |
18 | 17 | headers: &[&str], |
19 | 18 | notice: &str, |
20 | 19 | arch_specific_definitions: &[&str], |
21 | | -) -> Vec<String> { |
22 | | - let intrinsics_name_list = intrinsics |
| 20 | +) -> std::io::Result<Vec<String>> { |
| 21 | + std::fs::create_dir_all("c_programs")?; |
| 22 | + |
| 23 | + intrinsics |
23 | 24 | .iter() |
24 | | - .map(|i| i.name().clone()) |
25 | | - .collect::<Vec<_>>(); |
26 | | - let filename_mapping = setup_c_file_paths(&intrinsics_name_list); |
| 25 | + .map(|intrinsic| { |
| 26 | + let identifier = intrinsic.name().to_owned(); |
| 27 | + let mut file = File::create(format!("c_programs/{identifier}.cpp")).unwrap(); |
27 | 28 |
|
28 | | - intrinsics.iter().for_each(|&i| { |
29 | | - let c_code = create_c_test_program( |
30 | | - i, |
31 | | - headers, |
32 | | - target, |
33 | | - c_target, |
34 | | - notice, |
35 | | - arch_specific_definitions, |
36 | | - ); |
37 | | - if let Some(filename) = filename_mapping.get(&i.name()) { |
38 | | - write_file(filename, c_code) |
39 | | - }; |
40 | | - }); |
| 29 | + // write_c_test_program(&mut file, intrinsic)?; |
| 30 | + let c_code = crate::common::gen_c::create_c_test_program( |
| 31 | + *intrinsic, |
| 32 | + headers, |
| 33 | + target, |
| 34 | + c_target, |
| 35 | + notice, |
| 36 | + arch_specific_definitions, |
| 37 | + ); |
41 | 38 |
|
42 | | - intrinsics_name_list |
| 39 | + file.write_all(c_code.as_bytes())?; |
| 40 | + |
| 41 | + Ok(identifier) |
| 42 | + }) |
| 43 | + .collect() |
43 | 44 | } |
44 | 45 |
|
45 | 46 | pub fn write_rust_testfiles<T: IntrinsicTypeDefinition>( |
|
0 commit comments