Skip to content

Commit 1754ded

Browse files
jacobbramleyAmanieu
authored andcommitted
Add --generate-only to intrinsic-test.
This is useful for debugging.
1 parent 3a132d5 commit 1754ded

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

stdarch/crates/intrinsic-test/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ USAGE:
77
intrinsic-test [FLAGS] [OPTIONS] <INPUT>
88
99
FLAGS:
10-
--a32 Run tests for A32 instrinsics instead of A64
11-
-h, --help Prints help information
12-
-V, --version Prints version information
10+
--a32 Run tests for A32 instrinsics instead of A64
11+
--generate-only Regenerate test programs, but don't build or run them
12+
-h, --help Prints help information
13+
-V, --version Prints version information
1314
1415
OPTIONS:
1516
--cppcompiler <CPPCOMPILER> The C++ compiler to use for compiling the c++ code [default: clang++]

stdarch/crates/intrinsic-test/src/main.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ fn build_notices(line_prefix: &str) -> String {
232232
)
233233
}
234234

235-
fn build_c(notices: &str, intrinsics: &Vec<Intrinsic>, compiler: &str, a32: bool) -> bool {
235+
fn build_c(notices: &str, intrinsics: &Vec<Intrinsic>, compiler: Option<&str>, a32: bool) -> bool {
236236
let _ = std::fs::create_dir("c_programs");
237237
intrinsics
238238
.par_iter()
@@ -242,13 +242,16 @@ fn build_c(notices: &str, intrinsics: &Vec<Intrinsic>, compiler: &str, a32: bool
242242

243243
let c_code = generate_c_program(notices, &["arm_neon.h", "arm_acle.h"], &i, a32);
244244
file.write_all(c_code.into_bytes().as_slice()).unwrap();
245-
compile_c(&c_filename, &i, compiler, a32)
245+
match compiler {
246+
None => true,
247+
Some(compiler) => compile_c(&c_filename, &i, compiler, a32),
248+
}
246249
})
247250
.find_any(|x| !x)
248251
.is_none()
249252
}
250253

251-
fn build_rust(notices: &str, intrinsics: &[Intrinsic], toolchain: &str, a32: bool) -> bool {
254+
fn build_rust(notices: &str, intrinsics: &[Intrinsic], toolchain: Option<&str>, a32: bool) -> bool {
252255
intrinsics.iter().for_each(|i| {
253256
let rust_dir = format!(r#"rust_programs/{}"#, i.name);
254257
let _ = std::fs::create_dir_all(&rust_dir);
@@ -296,6 +299,11 @@ path = "{intrinsic}/main.rs""#,
296299
)
297300
.unwrap();
298301

302+
let toolchain = match toolchain {
303+
None => return true,
304+
Some(t) => t,
305+
};
306+
299307
let output = Command::new("sh")
300308
.current_dir("rust_programs")
301309
.arg("-c")
@@ -356,6 +364,10 @@ struct Cli {
356364
/// Run tests for A32 instrinsics instead of A64
357365
#[arg(long)]
358366
a32: bool,
367+
368+
/// Regenerate test programs, but don't build or run them
369+
#[arg(long)]
370+
generate_only: bool,
359371
}
360372

361373
fn main() {
@@ -364,8 +376,6 @@ fn main() {
364376
let args: Cli = clap::Parser::parse();
365377

366378
let filename = args.input;
367-
let toolchain = args.toolchain.map_or_else(String::new, |t| format!("+{t}"));
368-
let cpp_compiler = args.cppcompiler;
369379
let c_runner = args.runner.unwrap_or_else(String::new);
370380
let skip = if let Some(filename) = args.skip {
371381
let data = std::fs::read_to_string(&filename).expect("Failed to open file");
@@ -403,18 +413,29 @@ fn main() {
403413
.collect::<Vec<_>>();
404414
intrinsics.dedup();
405415

416+
let (toolchain, cpp_compiler) = if args.generate_only {
417+
(None, None)
418+
} else {
419+
(
420+
Some(args.toolchain.map_or_else(String::new, |t| format!("+{t}"))),
421+
Some(args.cppcompiler),
422+
)
423+
};
424+
406425
let notices = build_notices("// ");
407426

408-
if !build_c(&notices, &intrinsics, &cpp_compiler, a32) {
427+
if !build_c(&notices, &intrinsics, cpp_compiler.as_deref(), a32) {
409428
std::process::exit(2);
410429
}
411430

412-
if !build_rust(&notices, &intrinsics, &toolchain, a32) {
431+
if !build_rust(&notices, &intrinsics, toolchain.as_deref(), a32) {
413432
std::process::exit(3);
414433
}
415434

416-
if !compare_outputs(&intrinsics, &toolchain, &c_runner, a32) {
417-
std::process::exit(1)
435+
if let Some(ref toolchain) = toolchain {
436+
if !compare_outputs(&intrinsics, toolchain, &c_runner, a32) {
437+
std::process::exit(1)
438+
}
418439
}
419440
}
420441

0 commit comments

Comments
 (0)