about summary refs log tree commit diff
path: root/library/stdarch
diff options
context:
space:
mode:
authorEduardo Sánchez Muñoz <eduardosm-dev@e64.io>2023-10-03 20:07:20 +0200
committerAmanieu d'Antras <amanieu@gmail.com>2023-10-10 14:47:43 +0100
commiteef659efee09c1cbe2368fdae39c3cf094f79b43 (patch)
tree25a3bd6c1b5544b1da42dbeaff673feea5ac68f3 /library/stdarch
parent6698a597c00deb90cd75967988861860765d58ba (diff)
downloadrust-eef659efee09c1cbe2368fdae39c3cf094f79b43.tar.gz
rust-eef659efee09c1cbe2368fdae39c3cf094f79b43.zip
Bump clap to 4.4
Also define args with derive style instead of builder style.
Diffstat (limited to 'library/stdarch')
-rw-r--r--library/stdarch/crates/intrinsic-test/Cargo.toml2
-rw-r--r--library/stdarch/crates/intrinsic-test/README.md4
-rw-r--r--library/stdarch/crates/intrinsic-test/src/json_parser.rs3
-rw-r--r--library/stdarch/crates/intrinsic-test/src/main.rs93
4 files changed, 47 insertions, 55 deletions
diff --git a/library/stdarch/crates/intrinsic-test/Cargo.toml b/library/stdarch/crates/intrinsic-test/Cargo.toml
index d977dd659bc..94797d2d657 100644
--- a/library/stdarch/crates/intrinsic-test/Cargo.toml
+++ b/library/stdarch/crates/intrinsic-test/Cargo.toml
@@ -12,7 +12,7 @@ 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"
diff --git a/library/stdarch/crates/intrinsic-test/README.md b/library/stdarch/crates/intrinsic-test/README.md
index 8a8ddab404b..2b3f0c75a22 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 bc6fa4a9ede..8b3c7869c64 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 76d2da3abf6..15bc021c757 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(&notices, &intrinsics, cpp_compiler, a32) {
+    if !build_c(&notices, &intrinsics, &cpp_compiler, a32) {
         std::process::exit(2);
     }