Pretty-print errors for extended basic blocks too;

This commit is contained in:
Benjamin Bouvier
2018-11-14 13:04:37 +01:00
committed by Dan Gohman
parent d45e8b5830
commit b41bc55007
2 changed files with 69 additions and 7 deletions

View File

@@ -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<FuncWriter + 'a>, &'a mut Vec<VerifierError>);
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<VerifierError>,
) -> 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,

View File

@@ -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<Value, Vec<Value>>,
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<FW: FuncWriter>(
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)?;
}