Path: blob/main/cranelift/filetests/src/test_legalizer.rs
1693 views
//! Test command for checking the IR legalizer.1//!2//! The `test legalizer` test command runs each function through `legalize_function()` and sends3//! the result to filecheck.45use crate::subtest::{Context, SubTest, run_filecheck};6use cranelift_codegen::ir::Function;7use cranelift_reader::TestCommand;8use std::borrow::Cow;910struct TestLegalizer;1112pub fn subtest(parsed: &TestCommand) -> anyhow::Result<Box<dyn SubTest>> {13assert_eq!(parsed.command, "legalizer");14if !parsed.options.is_empty() {15anyhow::bail!("No options allowed on {}", parsed);16}17Ok(Box::new(TestLegalizer))18}1920impl SubTest for TestLegalizer {21fn name(&self) -> &'static str {22"legalizer"23}2425fn is_mutating(&self) -> bool {26true27}2829fn needs_isa(&self) -> bool {30true31}3233fn run(&self, func: Cow<Function>, context: &Context) -> anyhow::Result<()> {34let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned());35let isa = context.isa.expect("legalizer needs an ISA");3637comp_ctx.compute_cfg();38comp_ctx39.legalize(isa)40.map_err(|e| crate::pretty_anyhow_error(&comp_ctx.func, e))?;4142let text = comp_ctx.func.display().to_string();43run_filecheck(&text, context)44}45}464748