Added dynamic dispatch for easier management of <arch>ArchitectureTest structs

This commit is contained in:
Madhav Madhusoodanan 2025-04-19 23:19:07 +05:30 committed by Amanieu d'Antras
parent 587d8cebda
commit 8d0141ee19
3 changed files with 15 additions and 12 deletions

View file

@ -21,7 +21,7 @@ pub struct ArmArchitectureTest {
}
impl SupportedArchitectureTest for ArmArchitectureTest {
fn create(cli_options: ProcessedCli) -> Self {
fn create(cli_options: ProcessedCli) -> Box<Self> {
let a32 = cli_options.target.contains("v7");
let mut intrinsics = get_neon_intrinsics(&cli_options.filename, &cli_options.target)
.expect("Error parsing input file");
@ -43,10 +43,10 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
.collect::<Vec<_>>();
intrinsics.dedup();
Self {
Box::new(Self {
intrinsics: intrinsics,
cli_options: cli_options,
}
})
}
fn build_c_file(&self) -> bool {

View file

@ -16,7 +16,9 @@ pub mod values;
/// Architectures must support this trait
/// to be successfully tested.
pub trait SupportedArchitectureTest {
fn create(cli_options: ProcessedCli) -> Self;
fn create(cli_options: ProcessedCli) -> Box<Self>
where
Self: Sized;
fn build_c_file(&self) -> bool;
fn build_rust_file(&self) -> bool;
fn compare_outputs(&self) -> bool;

View file

@ -14,15 +14,16 @@ fn main() {
let args: Cli = clap::Parser::parse();
let processed_cli_options = ProcessedCli::new(args);
let test_environment_result = match processed_cli_options.target.as_str() {
"aarch64-unknown-linux-gnu"
| "armv7-unknown-linux-gnueabihf"
| "aarch64_be-unknown-linux-gnu" => {
Some(ArmArchitectureTest::create(processed_cli_options))
}
let test_environment_result: Option<Box<dyn SupportedArchitectureTest>> =
match processed_cli_options.target.as_str() {
"aarch64-unknown-linux-gnu"
| "armv7-unknown-linux-gnueabihf"
| "aarch64_be-unknown-linux-gnu" => {
Some(ArmArchitectureTest::create(processed_cli_options))
}
_ => None,
};
_ => None,
};
if test_environment_result.is_none() {
std::process::exit(0);