@@ -5,19 +5,11 @@ mod intrinsic;
55mod json_parser;
66mod types;
77
8- use std:: fs:: File ;
9-
10- use rayon:: prelude:: * ;
11-
8+ use crate :: common:: SupportedArchitectureTest ;
129use crate :: common:: cli:: ProcessedCli ;
1310use crate :: common:: compile_c:: CppCompilation ;
14- use crate :: common:: gen_c:: { write_main_cpp, write_mod_cpp} ;
15- use crate :: common:: gen_rust:: {
16- compile_rust_programs, write_bin_cargo_toml, write_lib_cargo_toml, write_lib_rs, write_main_rs,
17- } ;
1811use crate :: common:: intrinsic:: Intrinsic ;
1912use crate :: common:: intrinsic_helpers:: TypeKind ;
20- use crate :: common:: { SupportedArchitectureTest , chunk_info} ;
2113use intrinsic:: ArmIntrinsicType ;
2214use json_parser:: get_neon_intrinsics;
2315
@@ -76,135 +68,4 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
7668 fn cpp_compilation ( & self ) -> Option < CppCompilation > {
7769 compile:: build_cpp_compilation ( & self . cli_options )
7870 }
79-
80- fn build_c_file ( & self ) -> bool {
81- let c_target = "aarch64" ;
82-
83- let ( chunk_size, chunk_count) = chunk_info ( self . intrinsics ( ) . len ( ) ) ;
84-
85- let cpp_compiler_wrapped = self . cpp_compilation ( ) ;
86-
87- std:: fs:: create_dir_all ( "c_programs" ) . unwrap ( ) ;
88- self . intrinsics ( )
89- . par_chunks ( chunk_size)
90- . enumerate ( )
91- . map ( |( i, chunk) | {
92- let c_filename = format ! ( "c_programs/mod_{i}.cpp" ) ;
93- let mut file = File :: create ( & c_filename) . unwrap ( ) ;
94- write_mod_cpp (
95- & mut file,
96- Self :: NOTICE ,
97- c_target,
98- Self :: PLATFORM_C_HEADERS ,
99- chunk,
100- )
101- . unwrap ( ) ;
102-
103- // compile this cpp file into a .o file.
104- //
105- // This is done because `cpp_compiler_wrapped` is None when
106- // the --generate-only flag is passed
107- if let Some ( cpp_compiler) = cpp_compiler_wrapped. as_ref ( ) {
108- let output = cpp_compiler
109- . compile_object_file ( & format ! ( "mod_{i}.cpp" ) , & format ! ( "mod_{i}.o" ) ) ?;
110- assert ! ( output. status. success( ) , "{output:?}" ) ;
111- }
112-
113- Ok ( ( ) )
114- } )
115- . collect :: < Result < ( ) , std:: io:: Error > > ( )
116- . unwrap ( ) ;
117-
118- let mut file = File :: create ( "c_programs/main.cpp" ) . unwrap ( ) ;
119- write_main_cpp (
120- & mut file,
121- c_target,
122- Self :: PLATFORM_C_DEFINITIONS ,
123- self . intrinsics ( ) . iter ( ) . map ( |i| i. name . as_str ( ) ) ,
124- )
125- . unwrap ( ) ;
126-
127- // This is done because `cpp_compiler_wrapped` is None when
128- // the --generate-only flag is passed
129- if let Some ( cpp_compiler) = cpp_compiler_wrapped. as_ref ( ) {
130- // compile this cpp file into a .o file
131- info ! ( "compiling main.cpp" ) ;
132- let output = cpp_compiler
133- . compile_object_file ( "main.cpp" , "intrinsic-test-programs.o" )
134- . unwrap ( ) ;
135- assert ! ( output. status. success( ) , "{output:?}" ) ;
136-
137- let object_files = ( 0 ..chunk_count)
138- . map ( |i| format ! ( "mod_{i}.o" ) )
139- . chain ( [ "intrinsic-test-programs.o" . to_owned ( ) ] ) ;
140-
141- let output = cpp_compiler
142- . link_executable ( object_files, "intrinsic-test-programs" )
143- . unwrap ( ) ;
144- assert ! ( output. status. success( ) , "{output:?}" ) ;
145- }
146-
147- true
148- }
149-
150- fn build_rust_file ( & self ) -> bool {
151- std:: fs:: create_dir_all ( "rust_programs/src" ) . unwrap ( ) ;
152-
153- let architecture = if self . cli_options . target . contains ( "v7" ) {
154- "arm"
155- } else {
156- "aarch64"
157- } ;
158-
159- let ( chunk_size, chunk_count) = chunk_info ( self . intrinsics . len ( ) ) ;
160-
161- let mut cargo = File :: create ( "rust_programs/Cargo.toml" ) . unwrap ( ) ;
162- write_bin_cargo_toml ( & mut cargo, chunk_count) . unwrap ( ) ;
163-
164- let mut main_rs = File :: create ( "rust_programs/src/main.rs" ) . unwrap ( ) ;
165- write_main_rs (
166- & mut main_rs,
167- chunk_count,
168- Self :: PLATFORM_RUST_CFGS ,
169- "" ,
170- self . intrinsics . iter ( ) . map ( |i| i. name . as_str ( ) ) ,
171- )
172- . unwrap ( ) ;
173-
174- let target = & self . cli_options . target ;
175- let toolchain = self . cli_options . toolchain . as_deref ( ) ;
176- let linker = self . cli_options . linker . as_deref ( ) ;
177-
178- self . intrinsics
179- . par_chunks ( chunk_size)
180- . enumerate ( )
181- . map ( |( i, chunk) | {
182- std:: fs:: create_dir_all ( format ! ( "rust_programs/mod_{i}/src" ) ) ?;
183-
184- let rust_filename = format ! ( "rust_programs/mod_{i}/src/lib.rs" ) ;
185- trace ! ( "generating `{rust_filename}`" ) ;
186- let mut file = File :: create ( rust_filename) ?;
187-
188- write_lib_rs (
189- & mut file,
190- architecture,
191- Self :: NOTICE ,
192- Self :: PLATFORM_RUST_CFGS ,
193- Self :: PLATFORM_RUST_DEFINITIONS ,
194- chunk,
195- ) ?;
196-
197- let toml_filename = format ! ( "rust_programs/mod_{i}/Cargo.toml" ) ;
198- trace ! ( "generating `{toml_filename}`" ) ;
199- let mut file = File :: create ( toml_filename) . unwrap ( ) ;
200-
201- write_lib_cargo_toml ( & mut file, & format ! ( "mod_{i}" ) ) ?;
202-
203- Ok ( ( ) )
204- } )
205- . collect :: < Result < ( ) , std:: io:: Error > > ( )
206- . unwrap ( ) ;
207-
208- compile_rust_programs ( toolchain, target, linker)
209- }
21071}
0 commit comments