1
+ mod compile;
2
+ mod config;
1
3
mod intrinsic;
2
4
mod parser;
3
5
mod types;
@@ -6,12 +8,14 @@ use std::fs::{self, File};
6
8
7
9
use rayon:: prelude:: * ;
8
10
9
- use crate :: common:: SupportedArchitectureTest ;
11
+ use crate :: common:: gen_c:: { write_main_cpp, write_mod_cpp} ;
12
+ use crate :: common:: { chunk_info, SupportedArchitectureTest } ;
10
13
use crate :: common:: cli:: ProcessedCli ;
11
14
use crate :: common:: compare:: compare_outputs;
12
15
use crate :: common:: intrinsic_helpers:: TypeKind ;
13
16
14
17
use crate :: common:: intrinsic:: Intrinsic ;
18
+ use crate :: loongarch:: config:: build_notices;
15
19
use crate :: loongarch:: parser:: get_loongson_intrinsics;
16
20
use intrinsic:: LoongArchIntrinsicType ;
17
21
@@ -42,7 +46,68 @@ impl SupportedArchitectureTest for LoongArchArchitectureTest {
42
46
}
43
47
44
48
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
46
111
}
47
112
48
113
fn build_rust_file ( & self ) -> bool {
0 commit comments