1+ mod compile;
2+ mod config;
13mod intrinsic;
24mod parser;
35mod types;
@@ -6,12 +8,14 @@ use std::fs::{self, File};
68
79use rayon:: prelude:: * ;
810
9- use crate :: common:: SupportedArchitectureTest ;
1011use crate :: common:: cli:: ProcessedCli ;
1112use crate :: common:: compare:: compare_outputs;
13+ use crate :: common:: gen_c:: { write_main_cpp, write_mod_cpp} ;
1214use crate :: common:: intrinsic_helpers:: TypeKind ;
15+ use crate :: common:: { SupportedArchitectureTest , chunk_info} ;
1316
1417use crate :: common:: intrinsic:: Intrinsic ;
18+ use crate :: loongarch:: config:: build_notices;
1519use crate :: loongarch:: parser:: get_loongson_intrinsics;
1620use intrinsic:: LoongArchIntrinsicType ;
1721
@@ -42,7 +46,68 @@ impl SupportedArchitectureTest for LoongArchArchitectureTest {
4246 }
4347
4448 fn build_c_file ( & self ) -> bool {
45- unimplemented ! ( "build_c_file of LoongArchIntrinsicType is not defined!" )
49+ let c_target = "loongarch" ;
50+ let platform_headers = & [ "lasxintrin.h" , "lsxintrin.h" ] ;
51+
52+ let ( chunk_size, chunk_count) = chunk_info ( self . intrinsics . len ( ) ) ;
53+
54+ let cpp_compiler_wrapped = compile:: build_cpp_compilation ( & self . cli_options ) ;
55+
56+ let notice = & build_notices ( "// " ) ;
57+ fs:: create_dir_all ( "c_programs" ) . unwrap ( ) ;
58+ self . intrinsics
59+ . par_chunks ( chunk_size)
60+ . enumerate ( )
61+ . map ( |( i, chunk) | {
62+ let c_filename = format ! ( "c_programs/mod_{i}.cpp" ) ;
63+ let mut file = File :: create ( & c_filename) . unwrap ( ) ;
64+ write_mod_cpp ( & mut file, notice, c_target, platform_headers, chunk) . unwrap ( ) ;
65+
66+ // compile this cpp file into a .o file.
67+ //
68+ // This is done because `cpp_compiler_wrapped` is None when
69+ // the --generate-only flag is passed
70+ if let Some ( cpp_compiler) = cpp_compiler_wrapped. as_ref ( ) {
71+ let output = cpp_compiler
72+ . compile_object_file ( & format ! ( "mod_{i}.cpp" ) , & format ! ( "mod_{i}.o" ) ) ?;
73+ assert ! ( output. status. success( ) , "{output:?}" ) ;
74+ }
75+
76+ Ok ( ( ) )
77+ } )
78+ . collect :: < Result < ( ) , std:: io:: Error > > ( )
79+ . unwrap ( ) ;
80+
81+ let mut file = File :: create ( "c_programs/main.cpp" ) . unwrap ( ) ;
82+ write_main_cpp (
83+ & mut file,
84+ c_target,
85+ "\n " ,
86+ self . intrinsics . iter ( ) . map ( |i| i. name . as_str ( ) ) ,
87+ )
88+ . unwrap ( ) ;
89+
90+ // This is done because `cpp_compiler_wrapped` is None when
91+ // the --generate-only flag is passed
92+ if let Some ( cpp_compiler) = cpp_compiler_wrapped. as_ref ( ) {
93+ // compile this cpp file into a .o file
94+ info ! ( "compiling main.cpp" ) ;
95+ let output = cpp_compiler
96+ . compile_object_file ( "main.cpp" , "intrinsic-test-programs.o" )
97+ . unwrap ( ) ;
98+ assert ! ( output. status. success( ) , "{output:?}" ) ;
99+
100+ let object_files = ( 0 ..chunk_count)
101+ . map ( |i| format ! ( "mod_{i}.o" ) )
102+ . chain ( [ "intrinsic-test-programs.o" . to_owned ( ) ] ) ;
103+
104+ let output = cpp_compiler
105+ . link_executable ( object_files, "intrinsic-test-programs" )
106+ . unwrap ( ) ;
107+ assert ! ( output. status. success( ) , "{output:?}" ) ;
108+ }
109+
110+ true
46111 }
47112
48113 fn build_rust_file ( & self ) -> bool {
0 commit comments