Skip to content

Commit da49266

Browse files
Added dynamic dispatch for easier management of <arch>ArchitectureTest structs
1 parent 16e7523 commit da49266

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct ArmArchitectureTest {
2121
}
2222

2323
impl SupportedArchitectureTest for ArmArchitectureTest {
24-
fn create(cli_options: ProcessedCli) -> Self {
24+
fn create(cli_options: ProcessedCli) -> Box<Self> {
2525
let a32 = cli_options.target.contains("v7");
2626
let mut intrinsics = get_neon_intrinsics(&cli_options.filename, &cli_options.target)
2727
.expect("Error parsing input file");
@@ -43,10 +43,10 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
4343
.collect::<Vec<_>>();
4444
intrinsics.dedup();
4545

46-
Self {
46+
Box::new(Self {
4747
intrinsics: intrinsics,
4848
cli_options: cli_options,
49-
}
49+
})
5050
}
5151

5252
fn build_c_file(&self) -> bool {

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ pub mod values;
1616
/// Architectures must support this trait
1717
/// to be successfully tested.
1818
pub trait SupportedArchitectureTest {
19-
fn create(cli_options: ProcessedCli) -> Self;
19+
fn create(cli_options: ProcessedCli) -> Box<Self>
20+
where
21+
Self: Sized;
2022
fn build_c_file(&self) -> bool;
2123
fn build_rust_file(&self) -> bool;
2224
fn compare_outputs(&self) -> bool;

crates/intrinsic-test/src/main.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ fn main() {
1414
let args: Cli = clap::Parser::parse();
1515
let processed_cli_options = ProcessedCli::new(args);
1616

17-
let test_environment_result = 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-
}
23-
24-
_ => None,
25-
};
17+
let test_environment_result: Option<Box<dyn SupportedArchitectureTest>> =
18+
match processed_cli_options.target.as_str() {
19+
"aarch64-unknown-linux-gnu"
20+
| "armv7-unknown-linux-gnueabihf"
21+
| "aarch64_be-unknown-linux-gnu" => {
22+
Some(ArmArchitectureTest::create(processed_cli_options))
23+
}
24+
25+
_ => None,
26+
};
2627

2728
if test_environment_result.is_none() {
2829
std::process::exit(0);

0 commit comments

Comments
 (0)