Skip to main content

compiletest/runtest/
assembly.rs

1use camino::Utf8PathBuf;
2
3use crate::runtest::{AllowUnused, CompilerKind, 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        if !self.props.skip_filecheck {
17            let proc_res = self.verify_with_filecheck(&output_path);
18            if !proc_res.status.success() {
19                self.fatal_proc_rec("verification with 'FileCheck' failed", &proc_res);
20            }
21        }
22    }
23
24    fn compile_test_and_save_assembly(&self) -> (ProcRes, Utf8PathBuf) {
25        // This works with both `--emit asm` (as default output name for the assembly)
26        // and `ptx-linker` because the latter can write output at requested location.
27        let output_path = self.output_base_name().with_extension("s");
28        let input_file = &self.testpaths.file;
29
30        // Use the `//@ assembly-output:` directive to determine how to emit assembly.
31        let emit = match self.props.assembly_output.as_deref() {
32            Some("emit-asm") => Emit::Asm,
33            Some("bpf-linker") => Emit::LinkArgsAsm,
34            Some("ptx-linker") => Emit::None, // No extra flags needed.
35            Some(other) => self.fatal(&format!("unknown 'assembly-output' directive: {other}")),
36            None => self.fatal("missing 'assembly-output' directive"),
37        };
38
39        let rustc = self.make_compile_args(
40            CompilerKind::Rustc,
41            input_file,
42            TargetLocation::ThisFile(output_path.clone()),
43            emit,
44            AllowUnused::No,
45            LinkToAux::Yes,
46            Vec::new(),
47        );
48
49        let proc_res = self.compose_and_run_compiler(rustc, None);
50        (proc_res, output_path)
51    }
52}