(&self, func: Cow<ir::Function>, context: &Context)
| 49 | } |
| 50 | |
| 51 | fn run(&self, func: Cow<ir::Function>, context: &Context) -> Result<()> { |
| 52 | let isa = context.isa.expect("compile needs an ISA"); |
| 53 | let params = func.params.clone(); |
| 54 | let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned()); |
| 55 | |
| 56 | // With `MachBackend`s, we need to explicitly request disassembly results. |
| 57 | comp_ctx.set_disasm(true); |
| 58 | |
| 59 | let compiled_code = comp_ctx.compile(isa, &mut Default::default()); |
| 60 | |
| 61 | let compiled_code = if self.expect_fail { |
| 62 | if compiled_code.is_ok() { |
| 63 | anyhow::bail!("Expected compilation failure but compilation succeeded"); |
| 64 | } |
| 65 | return Ok(()); |
| 66 | } else { |
| 67 | compiled_code.map_err(|e| crate::pretty_anyhow_error(&e.func, e.inner))? |
| 68 | }; |
| 69 | let total_size = compiled_code.code_info().total_size; |
| 70 | |
| 71 | let vcode = compiled_code.vcode.as_ref().unwrap(); |
| 72 | |
| 73 | info!("Generated {total_size} bytes of code:\n{vcode}"); |
| 74 | |
| 75 | if self.precise_output { |
| 76 | let dis = match isa.triple().architecture { |
| 77 | target_lexicon::Architecture::Pulley32 | target_lexicon::Architecture::Pulley64 => { |
| 78 | // Disable hexdumps/offsets to reduce the churn in these |
| 79 | // tests as instructions are encoded differently and/or |
| 80 | // their immediates change. |
| 81 | let mut disas = |
| 82 | pulley_interpreter::disas::Disassembler::new(compiled_code.buffer.data()); |
| 83 | disas.hexdump(false).offsets(false); |
| 84 | pulley_interpreter::decode::Decoder::decode_all(&mut disas)?; |
| 85 | disas.disas().to_string() |
| 86 | } |
| 87 | _ => { |
| 88 | let cs = isa.to_capstone().map_err(|e| anyhow::format_err!("{e}"))?; |
| 89 | compiled_code.disassemble(Some(¶ms), &cs)? |
| 90 | } |
| 91 | }; |
| 92 | |
| 93 | let actual = Vec::from_iter( |
| 94 | std::iter::once("VCode:") |
| 95 | .chain(compiled_code.vcode.as_ref().unwrap().lines()) |
| 96 | .chain(["", "Disassembled:"]) |
| 97 | .chain(dis.lines()), |
| 98 | ); |
| 99 | |
| 100 | check_precise_output(&actual, context) |
| 101 | } else { |
| 102 | run_filecheck(&vcode, context) |
| 103 | } |
| 104 | } |
| 105 | } |
nothing calls this directly
no test coverage detected