diff options
| author | Madhav Madhusoodanan <f20200049@pilani.bits-pilani.ac.in> | 2025-04-23 19:25:53 +0530 |
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2025-05-27 23:27:38 +0000 |
| commit | 86f23a6c2ab327b88a050727f6e43278973599a9 (patch) | |
| tree | 60aa2359cb6c0d9c499e88dd94b3d5648b3845c3 /library/stdarch/crates/intrinsic-test/src/common/cli.rs | |
| parent | a416e3ea11d5c1e0518aa5635c1f2474d9942c38 (diff) | |
| download | rust-86f23a6c2ab327b88a050727f6e43278973599a9.tar.gz rust-86f23a6c2ab327b88a050727f6e43278973599a9.zip | |
chore: file renaming
Diffstat (limited to 'library/stdarch/crates/intrinsic-test/src/common/cli.rs')
| -rw-r--r-- | library/stdarch/crates/intrinsic-test/src/common/cli.rs | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/library/stdarch/crates/intrinsic-test/src/common/cli.rs b/library/stdarch/crates/intrinsic-test/src/common/cli.rs new file mode 100644 index 00000000000..9345761cf18 --- /dev/null +++ b/library/stdarch/crates/intrinsic-test/src/common/cli.rs @@ -0,0 +1,113 @@ +use itertools::Itertools; +use std::path::PathBuf; + +#[derive(Debug, PartialEq)] +pub enum Language { + Rust, + C, +} + +pub enum FailureReason { + RunC(String), + RunRust(String), + Difference(String, String, String), +} + +/// Intrinsic test tool +#[derive(clap::Parser)] +#[command( + name = "Intrinsic test tool", + about = "Generates Rust and C programs for intrinsics and compares the output" +)] +pub struct Cli { + /// The input file containing the intrinsics + pub input: PathBuf, + + /// The rust toolchain to use for building the rust code + #[arg(long)] + pub toolchain: Option<String>, + + /// The C++ compiler to use for compiling the c++ code + #[arg(long, default_value_t = String::from("clang++"))] + pub cppcompiler: String, + + /// Run the C programs under emulation with this command + #[arg(long)] + pub runner: Option<String>, + + /// Filename for a list of intrinsics to skip (one per line) + #[arg(long)] + pub skip: Option<PathBuf>, + + /// Regenerate test programs, but don't build or run them + #[arg(long)] + pub generate_only: bool, + + /// Pass a target the test suite + #[arg(long, default_value_t = String::from("armv7-unknown-linux-gnueabihf"))] + pub target: String, + + /// Set the linker + #[arg(long)] + pub linker: Option<String>, + + /// Set the sysroot for the C++ compiler + #[arg(long)] + pub cxx_toolchain_dir: Option<String>, +} + +pub struct ProcessedCli { + pub filename: PathBuf, + pub toolchain: Option<String>, + pub cpp_compiler: Option<String>, + pub c_runner: String, + pub target: String, + pub linker: Option<String>, + pub cxx_toolchain_dir: Option<String>, + pub skip: Vec<String>, +} + +impl ProcessedCli { + pub fn new(cli_options: Cli) -> Self { + let filename = cli_options.input; + let c_runner = cli_options.runner.unwrap_or_default(); + let target = cli_options.target; + let linker = cli_options.linker; + let cxx_toolchain_dir = cli_options.cxx_toolchain_dir; + + let skip = if let Some(filename) = cli_options.skip { + let data = std::fs::read_to_string(&filename).expect("Failed to open file"); + data.lines() + .map(str::trim) + .filter(|s| !s.contains('#')) + .map(String::from) + .collect_vec() + } else { + Default::default() + }; + + let (toolchain, cpp_compiler) = if cli_options.generate_only { + (None, None) + } else { + ( + Some( + cli_options + .toolchain + .map_or_else(String::new, |t| format!("+{t}")), + ), + Some(cli_options.cppcompiler), + ) + }; + + Self { + toolchain: toolchain, + cpp_compiler: cpp_compiler, + c_runner: c_runner, + target: target, + linker: linker, + cxx_toolchain_dir: cxx_toolchain_dir, + skip: skip, + filename: filename, + } + } +} |
