Add code to print clif ir on panics during define_function

This commit is contained in:
bjorn3 2022-07-02 19:38:23 +02:00
parent 45b6cd6a8a
commit 14b2f8f98d
2 changed files with 30 additions and 2 deletions

View File

@ -175,10 +175,37 @@ fn compile_fn<'tcx>(
);
});
#[cfg(any())] // This is never true
let _clif_guard = {
use std::fmt::Write;
let func_clone = context.func.clone();
let clif_comments_clone = clif_comments.clone();
let mut clif = String::new();
for flag in module.isa().flags().iter() {
writeln!(clif, "set {}", flag).unwrap();
}
write!(clif, "target {}", module.isa().triple().architecture.to_string()).unwrap();
for isa_flag in module.isa().isa_flags().iter() {
write!(clif, " {}", isa_flag).unwrap();
}
writeln!(clif, "\n").unwrap();
crate::PrintOnPanic(move || {
let mut clif = clif.clone();
::cranelift_codegen::write::decorate_function(
&mut &clif_comments_clone,
&mut clif,
&func_clone,
)
.unwrap();
clif
})
};
// Define function
tcx.sess.time("define function", || {
context.want_disasm = crate::pretty_clif::should_write_ir(tcx);
module.define_function(func_id, context).unwrap()
module.define_function(func_id, context).unwrap();
});
// Write optimized function to file for debugging

View File

@ -66,7 +66,7 @@
use crate::prelude::*;
#[derive(Debug)]
#[derive(Clone, Debug)]
pub(crate) struct CommentWriter {
enabled: bool,
global_comments: Vec<String>,
@ -237,6 +237,7 @@ pub(crate) fn write_clif_file<'tcx>(
func: &cranelift_codegen::ir::Function,
mut clif_comments: &CommentWriter,
) {
// FIXME work around filename too long errors
write_ir_file(
tcx,
|| format!("{}.{}.clif", tcx.symbol_name(instance).name, postfix),