Skip to content

Commit d70ef4f

Browse files
committed
move compare_outputs implementation into SupportedArchitectureTest definition
1 parent 589515b commit d70ef4f

File tree

3 files changed

+47
-40
lines changed

3 files changed

+47
-40
lines changed

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

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::fs::{self, File};
1010
use rayon::prelude::*;
1111

1212
use crate::common::cli::ProcessedCli;
13-
use crate::common::compare::compare_outputs;
1413
use crate::common::gen_c::{write_main_cpp, write_mod_cpp};
1514
use crate::common::gen_rust::{
1615
compile_rust_programs, write_bin_cargo_toml, write_lib_cargo_toml, write_lib_rs, write_main_rs,
@@ -28,7 +27,17 @@ pub struct ArmArchitectureTest {
2827
}
2928

3029
impl SupportedArchitectureTest for ArmArchitectureTest {
31-
fn create(cli_options: ProcessedCli) -> Box<Self> {
30+
type IntrinsicImpl = ArmIntrinsicType;
31+
32+
fn cli_options(&self) -> &ProcessedCli {
33+
&self.cli_options
34+
}
35+
36+
fn intrinsics(&self) -> &[Intrinsic<ArmIntrinsicType>] {
37+
&self.intrinsics
38+
}
39+
40+
fn create(cli_options: ProcessedCli) -> Self {
3241
let a32 = cli_options.target.contains("v7");
3342
let mut intrinsics = get_neon_intrinsics(&cli_options.filename, &cli_options.target)
3443
.expect("Error parsing input file");
@@ -50,10 +59,10 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
5059
.collect::<Vec<_>>();
5160
intrinsics.dedup();
5261

53-
Box::new(Self {
62+
Self {
5463
intrinsics,
5564
cli_options,
56-
})
65+
}
5766
}
5867

5968
fn build_c_file(&self) -> bool {
@@ -177,22 +186,4 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
177186

178187
compile_rust_programs(toolchain, target, linker)
179188
}
180-
181-
fn compare_outputs(&self) -> bool {
182-
if self.cli_options.toolchain.is_some() {
183-
let intrinsics_name_list = self
184-
.intrinsics
185-
.iter()
186-
.map(|i| i.name.clone())
187-
.collect::<Vec<_>>();
188-
189-
compare_outputs(
190-
&intrinsics_name_list,
191-
&self.cli_options.runner,
192-
&self.cli_options.target,
193-
)
194-
} else {
195-
true
196-
}
197-
}
198189
}

library/stdarch/crates/intrinsic-test/src/common/mod.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use cli::ProcessedCli;
22

3+
use crate::common::{intrinsic::Intrinsic, intrinsic_helpers::IntrinsicTypeDefinition};
4+
35
pub mod argument;
46
pub mod cli;
57
pub mod compare;
@@ -15,12 +17,33 @@ pub mod values;
1517
/// Architectures must support this trait
1618
/// to be successfully tested.
1719
pub trait SupportedArchitectureTest {
18-
fn create(cli_options: ProcessedCli) -> Box<Self>
19-
where
20-
Self: Sized;
20+
type IntrinsicImpl: IntrinsicTypeDefinition;
21+
22+
fn cli_options(&self) -> &ProcessedCli;
23+
fn intrinsics(&self) -> &[Intrinsic<Self::IntrinsicImpl>];
24+
25+
fn create(cli_options: ProcessedCli) -> Self;
26+
2127
fn build_c_file(&self) -> bool;
2228
fn build_rust_file(&self) -> bool;
23-
fn compare_outputs(&self) -> bool;
29+
30+
fn compare_outputs(&self) -> bool {
31+
if self.cli_options().toolchain.is_some() {
32+
let intrinsics_name_list = self
33+
.intrinsics()
34+
.iter()
35+
.map(|i| i.name.clone())
36+
.collect::<Vec<_>>();
37+
38+
compare::compare_outputs(
39+
&intrinsics_name_list,
40+
&self.cli_options().runner,
41+
&self.cli_options().target,
42+
)
43+
} else {
44+
true
45+
}
46+
}
2447
}
2548

2649
pub fn chunk_info(intrinsic_count: usize) -> (usize, usize) {

library/stdarch/crates/intrinsic-test/src/main.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,16 @@ fn main() {
1313
let args: Cli = clap::Parser::parse();
1414
let processed_cli_options = ProcessedCli::new(args);
1515

16-
let test_environment_result: Option<Box<dyn SupportedArchitectureTest>> =
17-
match processed_cli_options.target.as_str() {
18-
"aarch64-unknown-linux-gnu"
19-
| "armv7-unknown-linux-gnueabihf"
20-
| "aarch64_be-unknown-linux-gnu" => {
21-
Some(ArmArchitectureTest::create(processed_cli_options))
22-
}
16+
match processed_cli_options.target.as_str() {
17+
"aarch64-unknown-linux-gnu"
18+
| "armv7-unknown-linux-gnueabihf"
19+
| "aarch64_be-unknown-linux-gnu" => run(ArmArchitectureTest::create(processed_cli_options)),
2320

24-
_ => None,
25-
};
26-
27-
if test_environment_result.is_none() {
28-
std::process::exit(0);
21+
_ => std::process::exit(0),
2922
}
23+
}
3024

31-
let test_environment = test_environment_result.unwrap();
32-
25+
fn run(test_environment: impl SupportedArchitectureTest) {
3326
info!("building C binaries");
3427
if !test_environment.build_c_file() {
3528
std::process::exit(2);

0 commit comments

Comments
 (0)