From b41bc55007e13d03770624006f2b34ce9f18c089 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 14 Nov 2018 13:04:37 +0100 Subject: [PATCH] Pretty-print errors for extended basic blocks too; --- lib/codegen/src/print_errors.rs | 51 +++++++++++++++++++++++++++++---- lib/codegen/src/write.rs | 25 ++++++++++++++-- 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/lib/codegen/src/print_errors.rs b/lib/codegen/src/print_errors.rs index 8e764065a7..43bbc2cea4 100644 --- a/lib/codegen/src/print_errors.rs +++ b/lib/codegen/src/print_errors.rs @@ -2,7 +2,7 @@ use entity::SecondaryMap; use ir; -use ir::entities::{AnyEntity, Inst, Value}; +use ir::entities::{AnyEntity, Ebb, Inst, Value}; use ir::function::Function; use isa::TargetIsa; use result::CodegenError; @@ -36,6 +36,17 @@ pub fn pretty_verifier_error<'a>( struct PrettyVerifierError<'a>(Box, &'a mut Vec); impl<'a> FuncWriter for PrettyVerifierError<'a> { + fn write_ebb_header( + &mut self, + w: &mut Write, + func: &Function, + isa: Option<&TargetIsa>, + ebb: Ebb, + indent: usize, + ) -> fmt::Result { + pretty_ebb_header_error(w, func, isa, ebb, indent, &mut *self.0, self.1) + } + fn write_instruction( &mut self, w: &mut Write, @@ -59,7 +70,39 @@ impl<'a> FuncWriter for PrettyVerifierError<'a> { } } -/// Pretty-print a function verifier error. +/// Pretty-print a function verifier error for a given EBB. +fn pretty_ebb_header_error( + w: &mut Write, + func: &Function, + isa: Option<&TargetIsa>, + cur_ebb: Ebb, + indent: usize, + func_w: &mut FuncWriter, + errors: &mut Vec, +) -> fmt::Result { + let mut i = 0; + let mut printed_ebb = false; + + while i < errors.len() { + match errors[i].location { + ir::entities::AnyEntity::Ebb(ebb) if ebb == cur_ebb => { + if !printed_ebb { + func_w.write_ebb_header(w, func, isa, cur_ebb, indent)?; + printed_ebb = true; + } + let err = errors.remove(i); + print_error(w, indent, cur_ebb.to_string(), err)?; + } + _ => { + i += 1; + } + } + } + + Ok(()) +} + +/// Pretty-print a function verifier error for a given instruction. fn pretty_instruction_error( w: &mut Write, func: &Function, @@ -77,13 +120,11 @@ fn pretty_instruction_error( while i != errors.len() { match errors[i].location { ir::entities::AnyEntity::Inst(inst) if inst == cur_inst => { - let err = errors.remove(i); - if !printed_instr { func_w.write_instruction(w, func, aliases, isa, cur_inst, indent)?; printed_instr = true; } - + let err = errors.remove(i); print_error(w, indent, cur_inst.to_string(), err)?; } ir::entities::AnyEntity::Inst(_) => i += 1, diff --git a/lib/codegen/src/write.rs b/lib/codegen/src/write.rs index d790efa920..b4f9b1c76d 100644 --- a/lib/codegen/src/write.rs +++ b/lib/codegen/src/write.rs @@ -14,6 +14,16 @@ use std::vec::Vec; /// A `FuncWriter` used to decorate functions during printing. pub trait FuncWriter { + /// Write the extended basic block header for the current function. + fn write_ebb_header( + &mut self, + w: &mut Write, + func: &Function, + isa: Option<&TargetIsa>, + ebb: Ebb, + indent: usize, + ) -> fmt::Result; + /// Write the given `inst` to `w`. fn write_instruction( &mut self, @@ -22,7 +32,7 @@ pub trait FuncWriter { aliases: &SecondaryMap>, isa: Option<&TargetIsa>, inst: Inst, - ident: usize, + indent: usize, ) -> fmt::Result; /// Write the preamble to `w`. By default, this uses `write_entity_definition`. @@ -108,6 +118,17 @@ impl FuncWriter for PlainWriter { ) -> fmt::Result { write_instruction(w, func, aliases, isa, inst, indent) } + + fn write_ebb_header( + &mut self, + w: &mut Write, + func: &Function, + isa: Option<&TargetIsa>, + ebb: Ebb, + indent: usize, + ) -> fmt::Result { + write_ebb_header(w, func, isa, ebb, indent) + } } /// Write `func` to `w` as equivalent text. @@ -227,7 +248,7 @@ fn decorate_ebb( 36 }; - write_ebb_header(w, func, isa, ebb, indent)?; + func_w.write_ebb_header(w, func, isa, ebb, indent)?; for a in func.dfg.ebb_params(ebb).iter().cloned() { write_value_aliases(w, aliases, a, indent)?; }