diff --git a/lib/codegen/src/print_errors.rs b/lib/codegen/src/print_errors.rs index 5944e407ff..8e764065a7 100644 --- a/lib/codegen/src/print_errors.rs +++ b/lib/codegen/src/print_errors.rs @@ -84,11 +84,7 @@ fn pretty_instruction_error( printed_instr = true; } - write!(w, "{1:0$}^", indent, "")?; - for _c in cur_inst.to_string().chars() { - write!(w, "~")?; - } - writeln!(w, " verifier {}", err.to_string())?; + print_error(w, indent, cur_inst.to_string(), err)?; } ir::entities::AnyEntity::Inst(_) => i += 1, _ => unreachable!(), @@ -133,11 +129,7 @@ fn pretty_preamble_error( printed_entity = true; } - write!(w, "{1:0$}^", indent, "")?; - for _c in entity.to_string().chars() { - write!(w, "~")?; - } - writeln!(w, " verifier {}", err.to_string())?; + print_error(w, indent, entity.to_string(), err)?; } else { i += 1 } @@ -152,6 +144,18 @@ fn pretty_preamble_error( Ok(()) } +/// Prints ; ^~~~~~ verifier [ERROR BODY] +fn print_error(w: &mut Write, indent: usize, s: String, err: VerifierError) -> fmt::Result { + let indent = if indent < 1 { 0 } else { indent - 1 }; + + write!(w, ";{1:0$}^", indent, "")?; + for _c in s.chars() { + write!(w, "~")?; + } + writeln!(w, " verifier {}", err.to_string())?; + Ok(()) +} + /// Pretty-print a Cranelift error. pub fn pretty_error(func: &ir::Function, isa: Option<&TargetIsa>, err: CodegenError) -> String { if let CodegenError::Verifier(e) = err {