diff options
Diffstat (limited to 'library/stdarch/crates/intrinsic-test')
4 files changed, 49 insertions, 57 deletions
diff --git a/library/stdarch/crates/intrinsic-test/Cargo.toml b/library/stdarch/crates/intrinsic-test/Cargo.toml index d977dd659..c7a18f77f 100644 --- a/library/stdarch/crates/intrinsic-test/Cargo.toml +++ b/library/stdarch/crates/intrinsic-test/Cargo.toml @@ -12,10 +12,10 @@ lazy_static = "1.4.0" serde = { version = "1", features = ["derive"] } serde_json = "1.0" csv = "1.1" -clap = "2.33.3" +clap = { version = "4.4", features = ["derive"] } regex = "1.4.2" log = "0.4.11" -pretty_env_logger = "0.4.0" +pretty_env_logger = "0.5.0" rayon = "1.5.0" diff = "0.1.12" -itertools = "0.10.1" +itertools = "0.11.0" diff --git a/library/stdarch/crates/intrinsic-test/README.md b/library/stdarch/crates/intrinsic-test/README.md index 8a8ddab40..2b3f0c75a 100644 --- a/library/stdarch/crates/intrinsic-test/README.md +++ b/library/stdarch/crates/intrinsic-test/README.md @@ -4,15 +4,17 @@ each produces the same result from random inputs. # Usage ``` USAGE: - intrinsic-test [OPTIONS] <INPUT> + intrinsic-test [FLAGS] [OPTIONS] <INPUT> FLAGS: + --a32 Run tests for A32 instrinsics instead of A64 -h, --help Prints help information -V, --version Prints version information OPTIONS: --cppcompiler <CPPCOMPILER> The C++ compiler to use for compiling the c++ code [default: clang++] --runner <RUNNER> Run the C programs under emulation with this command + --skip <SKIP> Filename for a list of intrinsics to skip (one per line) --toolchain <TOOLCHAIN> The rust toolchain to use for building the rust code ARGS: diff --git a/library/stdarch/crates/intrinsic-test/src/json_parser.rs b/library/stdarch/crates/intrinsic-test/src/json_parser.rs index bc6fa4a9e..8b3c7869c 100644 --- a/library/stdarch/crates/intrinsic-test/src/json_parser.rs +++ b/library/stdarch/crates/intrinsic-test/src/json_parser.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::path::Path; use serde::Deserialize; @@ -41,7 +42,7 @@ struct JsonIntrinsic { architectures: Vec<String>, } -pub fn get_neon_intrinsics(filename: &str) -> Result<Vec<Intrinsic>, Box<dyn std::error::Error>> { +pub fn get_neon_intrinsics(filename: &Path) -> Result<Vec<Intrinsic>, Box<dyn std::error::Error>> { let file = std::fs::File::open(filename)?; let reader = std::io::BufReader::new(file); let json: Vec<JsonIntrinsic> = serde_json::from_reader(reader).expect("Couldn't parse JSON"); diff --git a/library/stdarch/crates/intrinsic-test/src/main.rs b/library/stdarch/crates/intrinsic-test/src/main.rs index 76d2da3ab..15bc021c7 100644 --- a/library/stdarch/crates/intrinsic-test/src/main.rs +++ b/library/stdarch/crates/intrinsic-test/src/main.rs @@ -4,9 +4,9 @@ extern crate log; use std::fs::File; use std::io::Write; +use std::path::PathBuf; use std::process::Command; -use clap::{App, Arg}; use intrinsic::Intrinsic; use itertools::Itertools; use rayon::prelude::*; @@ -320,58 +320,47 @@ path = "{intrinsic}/main.rs""#, } } +/// Intrinsic test tool +#[derive(clap::Parser)] +#[command( + name = "Intrinsic test tool", + about = "Generates Rust and C programs for intrinsics and compares the output" +)] +struct Cli { + /// The input file containing the intrinsics + input: PathBuf, + + /// The rust toolchain to use for building the rust code + #[arg(long)] + toolchain: Option<String>, + + /// The C++ compiler to use for compiling the c++ code + #[arg(long, default_value_t = String::from("clang++"))] + cppcompiler: String, + + /// Run the C programs under emulation with this command + #[arg(long)] + runner: Option<String>, + + /// Filename for a list of intrinsics to skip (one per line) + #[arg(long)] + skip: Option<PathBuf>, + + /// Run tests for A32 instrinsics instead of A64 + #[arg(long)] + a32: bool, +} + fn main() { pretty_env_logger::init(); - let matches = App::new("Intrinsic test tool") - .about("Generates Rust and C programs for intrinsics and compares the output") - .arg( - Arg::with_name("INPUT") - .help("The input file containing the intrinsics") - .required(true) - .index(1), - ) - .arg( - Arg::with_name("TOOLCHAIN") - .takes_value(true) - .long("toolchain") - .help("The rust toolchain to use for building the rust code"), - ) - .arg( - Arg::with_name("CPPCOMPILER") - .takes_value(true) - .default_value("clang++") - .long("cppcompiler") - .help("The C++ compiler to use for compiling the c++ code"), - ) - .arg( - Arg::with_name("RUNNER") - .takes_value(true) - .long("runner") - .help("Run the C programs under emulation with this command"), - ) - .arg( - Arg::with_name("SKIP") - .takes_value(true) - .long("skip") - .help("Filename for a list of intrinsics to skip (one per line)"), - ) - .arg( - Arg::with_name("A32") - .takes_value(false) - .long("a32") - .help("Run tests for A32 instrinsics instead of A64"), - ) - .get_matches(); - - let filename = matches.value_of("INPUT").unwrap(); - let toolchain = matches - .value_of("TOOLCHAIN") - .map_or("".into(), |t| format!("+{t}")); + let args: Cli = clap::Parser::parse(); - let cpp_compiler = matches.value_of("CPPCOMPILER").unwrap(); - let c_runner = matches.value_of("RUNNER").unwrap_or(""); - let skip = if let Some(filename) = matches.value_of("SKIP") { + let filename = args.input; + let toolchain = args.toolchain.map_or_else(String::new, |t| format!("+{t}")); + let cpp_compiler = args.cppcompiler; + let c_runner = args.runner.unwrap_or_else(String::new); + let skip = if let Some(filename) = args.skip { let data = std::fs::read_to_string(&filename).expect("Failed to open file"); data.lines() .map(str::trim) @@ -381,8 +370,8 @@ fn main() { } else { Default::default() }; - let a32 = matches.is_present("A32"); - let mut intrinsics = get_neon_intrinsics(filename).expect("Error parsing input file"); + let a32 = args.a32; + let mut intrinsics = get_neon_intrinsics(&filename).expect("Error parsing input file"); intrinsics.sort_by(|a, b| a.name.cmp(&b.name)); @@ -409,7 +398,7 @@ fn main() { let notices = build_notices("// "); - if !build_c(¬ices, &intrinsics, cpp_compiler, a32) { + if !build_c(¬ices, &intrinsics, &cpp_compiler, a32) { std::process::exit(2); } |