Skip to content

Commit 345d17a

Browse files
committed
optimize C file creation
1 parent 3babc4b commit 345d17a

File tree

3 files changed

+26
-39
lines changed

3 files changed

+26
-39
lines changed

crates/intrinsic-test/src/arm/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
7272
match compiler {
7373
None => true,
7474
Some(compiler) => compile_c_arm(
75-
intrinsics_name_list.as_slice(),
75+
intrinsics_name_list.unwrap().as_slice(),
7676
compiler,
7777
target,
7878
cxx_toolchain_dir,

crates/intrinsic-test/src/common/gen_c.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use itertools::Itertools;
22
use rayon::prelude::*;
3-
use std::collections::BTreeMap;
43
use std::process::Command;
54

65
use super::argument::Argument;
@@ -87,19 +86,6 @@ pub fn compile_c_programs(compiler_commands: &[String]) -> bool {
8786
.is_none()
8887
}
8988

90-
// Creates directory structure and file path mappings
91-
pub fn setup_c_file_paths(identifiers: &Vec<String>) -> BTreeMap<&String, String> {
92-
let _ = std::fs::create_dir("c_programs");
93-
identifiers
94-
.par_iter()
95-
.map(|identifier| {
96-
let c_filename = format!(r#"c_programs/{identifier}.cpp"#);
97-
98-
(identifier, c_filename)
99-
})
100-
.collect::<BTreeMap<&String, String>>()
101-
}
102-
10389
pub fn generate_c_test_loop<T: IntrinsicTypeDefinition + Sized>(
10490
intrinsic: &dyn IntrinsicDefinition<T>,
10591
indentation: Indentation,

crates/intrinsic-test/src/common/write_file.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,46 @@
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+
34
use super::gen_rust::{create_rust_test_program, setup_rust_file_paths};
45
use super::intrinsic::IntrinsicDefinition;
56
use super::intrinsic_helpers::IntrinsicTypeDefinition;
6-
use std::fs::File;
7-
use std::io::Write;
87

98
pub fn write_file(filename: &String, code: String) {
109
let mut file = File::create(filename).unwrap();
1110
file.write_all(code.into_bytes().as_slice()).unwrap();
1211
}
1312

1413
pub fn write_c_testfiles<T: IntrinsicTypeDefinition + Sized>(
15-
intrinsics: &Vec<&dyn IntrinsicDefinition<T>>,
14+
intrinsics: &[&dyn IntrinsicDefinition<T>],
1615
target: &str,
1716
c_target: &str,
1817
headers: &[&str],
1918
notice: &str,
2019
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
2324
.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();
2728

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+
);
4138

42-
intrinsics_name_list
39+
file.write_all(c_code.as_bytes())?;
40+
41+
Ok(identifier)
42+
})
43+
.collect()
4344
}
4445

4546
pub fn write_rust_testfiles<T: IntrinsicTypeDefinition>(

0 commit comments

Comments
 (0)