cranelift_filetests/
test_safepoint.rs

1use crate::subtest::{run_filecheck, Context, SubTest};
2use cranelift_codegen::ir::Function;
3use cranelift_reader::TestCommand;
4use std::borrow::Cow;
5
6struct TestSafepoint;
7
8pub fn subtest(parsed: &TestCommand) -> anyhow::Result<Box<dyn SubTest>> {
9    assert_eq!(parsed.command, "safepoint");
10    if !parsed.options.is_empty() {
11        anyhow::bail!("No options allowed on {}", parsed);
12    }
13    Ok(Box::new(TestSafepoint))
14}
15
16impl SubTest for TestSafepoint {
17    fn name(&self) -> &'static str {
18        "safepoint"
19    }
20
21    fn run(&self, func: Cow<Function>, context: &Context) -> anyhow::Result<()> {
22        let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned());
23
24        let isa = context.isa.expect("register allocator needs an ISA");
25        comp_ctx.compute_cfg();
26        comp_ctx
27            .legalize(isa)
28            .map_err(|e| crate::pretty_anyhow_error(&comp_ctx.func, e))?;
29        comp_ctx.compute_domtree();
30
31        let text = comp_ctx.func.display().to_string();
32        run_filecheck(&text, context)
33    }
34}