compiletest/runtest/
assembly.rs

1use std::path::PathBuf;
2
3use super::{AllowUnused, Emit, LinkToAux, ProcRes, TargetLocation, TestCx};
4
5impl TestCx<'_> {
6    pub(super) fn run_assembly_test(&self) {
7        if self.config.llvm_filecheck.is_none() {
8            self.fatal("missing --llvm-filecheck");
9        }
10
11        let (proc_res, output_path) = self.compile_test_and_save_assembly();
12        if !proc_res.status.success() {
13            self.fatal_proc_rec("compilation failed!", &proc_res);
14        }
15
16        let proc_res = self.verify_with_filecheck(&output_path);
17        if !proc_res.status.success() {
18            self.fatal_proc_rec("verification with 'FileCheck' failed", &proc_res);
19        }
20    }
21
22    fn compile_test_and_save_assembly(&self) -> (ProcRes, PathBuf) {
23        // This works with both `--emit asm` (as default output name for the assembly)
24        // and `ptx-linker` because the latter can write output at requested location.
25        let output_path = self.output_base_name().with_extension("s");
26        let input_file = &self.testpaths.file;
27
28        // Use the `//@ assembly-output:` directive to determine how to emit assembly.
29        let emit = match self.props.assembly_output.as_deref() {
30            Some("emit-asm") => Emit::Asm,
31            Some("bpf-linker") => Emit::LinkArgsAsm,
32            Some("ptx-linker") => Emit::None, // No extra flags needed.
33            Some(other) => self.fatal(&format!("unknown 'assembly-output' directive: {other}")),
34            None => self.fatal("missing 'assembly-output' directive"),
35        };
36
37        let rustc = self.make_compile_args(
38            input_file,
39            TargetLocation::ThisFile(output_path.clone()),
40            emit,
41            AllowUnused::No,
42            LinkToAux::Yes,
43            Vec::new(),
44        );
45
46        let proc_res = self.compose_and_run_compiler(rustc, None, self.testpaths);
47        (proc_res, output_path)
48    }
49}