Skip to content

Commit e0b0301

Browse files
chore: code consolidation
1 parent 3e46d80 commit e0b0301

File tree

12 files changed

+133
-138
lines changed

12 files changed

+133
-138
lines changed

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use std::ops::Range;
2-
31
use super::format::Indentation;
42
use super::json_parser::ArgPrep;
53
use super::types::{IntrinsicType, TypeKind};
64
use crate::common::types::Language;
5+
use std::ops::Range;
76

87
/// An argument for the intrinsic.
98
#[derive(Debug, PartialEq, Clone)]

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ pub fn build_notices(line_prefix: &str) -> String {
88
)
99
}
1010

11-
pub const POLY128_OSTREAM_DEF: &str =
12-
r#"std::ostream& operator<<(std::ostream& os, poly128_t value) {
11+
pub const POLY128_OSTREAM_DEF: &str = r#"std::ostream& operator<<(std::ostream& os, poly128_t value) {
1312
std::stringstream temp;
1413
do {
1514
int n = value % 10;

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
use itertools::Itertools;
2-
use rayon::prelude::*;
3-
use std::io::Write;
4-
51
use super::argument::Argument;
62
use super::config::{AARCH_CONFIGURATIONS, POLY128_OSTREAM_DEF, build_notices};
73
use super::format::Indentation;
84
use super::intrinsic::Intrinsic;
95
use crate::common::gen_c::{compile_c, create_c_files, generate_c_program};
106
use crate::common::gen_rust::{compile_rust, create_rust_files, generate_rust_program};
7+
use itertools::Itertools;
8+
use rayon::prelude::*;
9+
use std::io::Write;
1110

1211
// The number of times each intrinsic will be called.
1312
const PASSES: u32 = 20;

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
use super::argument::ArgumentList;
12
use super::format::Indentation;
23
use super::types::{IntrinsicType, TypeKind};
34

4-
use super::argument::ArgumentList;
5-
65
/// An intrinsic
76
#[derive(Debug, PartialEq, Clone)]
87
pub struct Intrinsic {

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use std::collections::HashMap;
2-
use std::path::Path;
3-
4-
use serde::Deserialize;
5-
61
use super::argument::{Argument, ArgumentList};
72
use super::intrinsic::Intrinsic;
83
use super::types::IntrinsicType;
4+
use serde::Deserialize;
5+
use std::collections::HashMap;
6+
use std::path::Path;
97

108
#[derive(Deserialize, Debug)]
119
#[serde(deny_unknown_fields)]

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ mod intrinsic;
66
mod json_parser;
77
mod types;
88

9-
use crate::common::cli::ProcessedCli;
9+
use crate::common::SupportedArchitectureTest;
1010
use crate::common::compare::compare_outputs;
11-
use crate::common::supporting_test::SupportedArchitectureTest;
11+
use crate::common::types::ProcessedCli;
1212
use functions::{build_c, build_rust};
1313
use intrinsic::Intrinsic;
1414
use json_parser::get_neon_intrinsics;

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

-101
This file was deleted.

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1+
use super::types::FailureReason;
12
use rayon::prelude::*;
23
use std::process::Command;
34

4-
enum FailureReason {
5-
RunC(String),
6-
RunRust(String),
7-
Difference(String, String, String),
8-
}
9-
105
pub fn compare_outputs(
116
intrinsic_name_list: &Vec<String>,
127
toolchain: &str,
+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
pub mod cli;
1+
use crate::common::types::ProcessedCli;
2+
23
pub mod compare;
34
pub mod gen_c;
45
pub mod gen_rust;
5-
pub mod supporting_test;
66
pub mod types;
77
pub mod values;
8+
9+
/// Architectures must support this trait
10+
/// to be successfully tested.
11+
pub trait SupportedArchitectureTest {
12+
fn create(cli_options: ProcessedCli) -> Self;
13+
fn build_c_file(&self) -> bool;
14+
fn build_rust_file(&self) -> bool;
15+
fn compare_outputs(&self) -> bool;
16+
}

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

-10
This file was deleted.
+108
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,113 @@
1+
use itertools::Itertools;
2+
use std::path::PathBuf;
3+
14
#[derive(Debug, PartialEq)]
25
pub enum Language {
36
Rust,
47
C,
58
}
9+
10+
pub enum FailureReason {
11+
RunC(String),
12+
RunRust(String),
13+
Difference(String, String, String),
14+
}
15+
16+
/// Intrinsic test tool
17+
#[derive(clap::Parser)]
18+
#[command(
19+
name = "Intrinsic test tool",
20+
about = "Generates Rust and C programs for intrinsics and compares the output"
21+
)]
22+
pub struct Cli {
23+
/// The input file containing the intrinsics
24+
pub input: PathBuf,
25+
26+
/// The rust toolchain to use for building the rust code
27+
#[arg(long)]
28+
pub toolchain: Option<String>,
29+
30+
/// The C++ compiler to use for compiling the c++ code
31+
#[arg(long, default_value_t = String::from("clang++"))]
32+
pub cppcompiler: String,
33+
34+
/// Run the C programs under emulation with this command
35+
#[arg(long)]
36+
pub runner: Option<String>,
37+
38+
/// Filename for a list of intrinsics to skip (one per line)
39+
#[arg(long)]
40+
pub skip: Option<PathBuf>,
41+
42+
/// Regenerate test programs, but don't build or run them
43+
#[arg(long)]
44+
pub generate_only: bool,
45+
46+
/// Pass a target the test suite
47+
#[arg(long, default_value_t = String::from("aarch64-unknown-linux-gnu"))]
48+
pub target: String,
49+
50+
/// Set the linker
51+
#[arg(long)]
52+
pub linker: Option<String>,
53+
54+
/// Set the sysroot for the C++ compiler
55+
#[arg(long)]
56+
pub cxx_toolchain_dir: Option<String>,
57+
}
58+
59+
pub struct ProcessedCli {
60+
pub filename: PathBuf,
61+
pub toolchain: Option<String>,
62+
pub cpp_compiler: Option<String>,
63+
pub c_runner: String,
64+
pub target: String,
65+
pub linker: Option<String>,
66+
pub cxx_toolchain_dir: Option<String>,
67+
pub skip: Vec<String>,
68+
}
69+
70+
impl ProcessedCli {
71+
pub fn new(cli_options: Cli) -> Self {
72+
let filename = cli_options.input;
73+
let c_runner = cli_options.runner.unwrap_or_default();
74+
let target = cli_options.target;
75+
let linker = cli_options.linker;
76+
let cxx_toolchain_dir = cli_options.cxx_toolchain_dir;
77+
78+
let skip = if let Some(filename) = cli_options.skip {
79+
let data = std::fs::read_to_string(&filename).expect("Failed to open file");
80+
data.lines()
81+
.map(str::trim)
82+
.filter(|s| !s.contains('#'))
83+
.map(String::from)
84+
.collect_vec()
85+
} else {
86+
Default::default()
87+
};
88+
89+
let (toolchain, cpp_compiler) = if cli_options.generate_only {
90+
(None, None)
91+
} else {
92+
(
93+
Some(
94+
cli_options
95+
.toolchain
96+
.map_or_else(String::new, |t| format!("+{t}")),
97+
),
98+
Some(cli_options.cppcompiler),
99+
)
100+
};
101+
102+
Self {
103+
toolchain: toolchain,
104+
cpp_compiler: cpp_compiler,
105+
c_runner: c_runner,
106+
target: target,
107+
linker: linker,
108+
cxx_toolchain_dir: cxx_toolchain_dir,
109+
skip: skip,
110+
filename: filename,
111+
}
112+
}
113+
}

crates/intrinsic-test/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ mod arm;
66
mod common;
77

88
use arm::ArmTestProcessor;
9-
use common::cli::{Cli, ProcessedCli};
10-
use common::supporting_test::SupportedArchitectureTest;
9+
use common::SupportedArchitectureTest;
10+
use common::types::{Cli, ProcessedCli};
1111

1212
fn main() {
1313
pretty_env_logger::init();

0 commit comments

Comments
 (0)