11use std:: fs:: File ;
22use std:: io:: Write ;
33
4- use super :: gen_rust:: { create_rust_test_program, setup_rust_file_paths } ;
4+ use super :: gen_rust:: create_rust_test_program;
55use super :: intrinsic:: IntrinsicDefinition ;
66use super :: intrinsic_helpers:: IntrinsicTypeDefinition ;
77
8- pub fn write_file ( filename : & String , code : String ) {
9- let mut file = File :: create ( filename) . unwrap ( ) ;
10- file. write_all ( code. into_bytes ( ) . as_slice ( ) ) . unwrap ( ) ;
11- }
12-
13- pub fn write_c_testfiles < T : IntrinsicTypeDefinition + Sized > (
14- intrinsics : & [ & dyn IntrinsicDefinition < T > ] ,
8+ pub fn write_c_testfiles < ' a , T , I > (
9+ intrinsics : I ,
1510 target : & str ,
1611 c_target : & str ,
1712 headers : & [ & str ] ,
1813 notice : & str ,
1914 arch_specific_definitions : & [ & str ] ,
20- ) -> std:: io:: Result < Vec < String > > {
15+ ) -> std:: io:: Result < Vec < String > >
16+ where
17+ T : IntrinsicTypeDefinition + Sized + ' a ,
18+ I : Iterator < Item = & ' a dyn IntrinsicDefinition < T > > ,
19+ {
2120 std:: fs:: create_dir_all ( "c_programs" ) ?;
2221
2322 intrinsics
24- . iter ( )
2523 . map ( |intrinsic| {
2624 let identifier = intrinsic. name ( ) . to_owned ( ) ;
2725 let mut file = File :: create ( format ! ( "c_programs/{identifier}.cpp" ) ) . unwrap ( ) ;
2826
2927 // write_c_test_program(&mut file, intrinsic)?;
3028 let c_code = crate :: common:: gen_c:: create_c_test_program (
31- * intrinsic,
29+ intrinsic,
3230 headers,
3331 target,
3432 c_target,
@@ -43,25 +41,34 @@ pub fn write_c_testfiles<T: IntrinsicTypeDefinition + Sized>(
4341 . collect ( )
4442}
4543
46- pub fn write_rust_testfiles < T : IntrinsicTypeDefinition > (
47- intrinsics : Vec < & dyn IntrinsicDefinition < T > > ,
44+ pub fn write_rust_testfiles < ' a , T , I > (
45+ intrinsics : I ,
4846 rust_target : & str ,
4947 notice : & str ,
5048 definitions : & str ,
5149 cfg : & str ,
52- ) -> Vec < String > {
53- let intrinsics_name_list = intrinsics
54- . iter ( )
55- . map ( |i| i. name ( ) . clone ( ) )
56- . collect :: < Vec < _ > > ( ) ;
57- let filename_mapping = setup_rust_file_paths ( & intrinsics_name_list) ;
50+ ) -> std:: io:: Result < Vec < String > >
51+ where
52+ T : IntrinsicTypeDefinition + Sized + ' a ,
53+ I : Iterator < Item = & ' a dyn IntrinsicDefinition < T > > ,
54+ {
55+ std:: fs:: create_dir_all ( "rust_programs" ) ?;
56+
57+ intrinsics
58+ . map ( |intrinsic| {
59+ let identifier = intrinsic. name ( ) . to_owned ( ) ;
5860
59- intrinsics. iter ( ) . for_each ( |& i| {
60- let rust_code = create_rust_test_program ( i, rust_target, notice, definitions, cfg) ;
61- if let Some ( filename) = filename_mapping. get ( & i. name ( ) ) {
62- write_file ( filename, rust_code)
63- }
64- } ) ;
61+ let rust_dir = format ! ( "rust_programs/{identifier}" ) ;
62+ std:: fs:: create_dir_all ( & rust_dir) ?;
63+ let rust_filename = format ! ( "{rust_dir}/main.rs" ) ;
64+ let mut file = File :: create ( rust_filename) . unwrap ( ) ;
6565
66- intrinsics_name_list
66+ let rust_code =
67+ create_rust_test_program ( intrinsic, rust_target, notice, definitions, cfg) ;
68+
69+ file. write_all ( rust_code. as_bytes ( ) ) ?;
70+
71+ Ok ( identifier)
72+ } )
73+ . collect ( )
6774}
0 commit comments