From cba7a032751b3ed21d2b5aac3e215256bbdeb20e Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 15 Sep 2017 09:32:56 -0700 Subject: [PATCH] Give better verifier errors for missing instruction encodings. When possible, provide the ISA's default encoding as a suggesting for the missing instruction encoding. --- lib/cretonne/src/verifier/mod.rs | 50 ++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/lib/cretonne/src/verifier/mod.rs b/lib/cretonne/src/verifier/mod.rs index f7170bbd24..bfc45b7d0d 100644 --- a/lib/cretonne/src/verifier/mod.rs +++ b/lib/cretonne/src/verifier/mod.rs @@ -920,28 +920,40 @@ impl<'a> Verifier<'a> { return Ok(()); } + // Check if this opcode must be encoded. + let mut needs_enc = None; if opcode.is_branch() { - return err!(inst, "Branch must have an encoding"); + needs_enc = Some("Branch"); + } else if opcode.is_call() { + needs_enc = Some("Call"); + } else if opcode.is_return() { + needs_enc = Some("Return"); + } else if opcode.can_store() { + needs_enc = Some("Store"); + } else if opcode.can_trap() { + needs_enc = Some("Trapping instruction"); + } else if opcode.other_side_effects() { + needs_enc = Some("Instruction with side effects"); } - if opcode.is_call() { - return err!(inst, "Call must have an encoding"); - } - - if opcode.is_return() { - return err!(inst, "Return must have an encoding"); - } - - if opcode.can_store() { - return err!(inst, "Store must have an encoding"); - } - - if opcode.can_trap() { - return err!(inst, "Trapping instruction must have an encoding"); - } - - if opcode.other_side_effects() { - return err!(inst, "Instruction with side effects must have an encoding"); + if let Some(text) = needs_enc { + // This instruction needs an encoding, so generate an error. + // Provide the ISA default encoding as a hint. + match isa.encode( + &self.func.dfg, + &self.func.dfg[inst], + self.func.dfg.ctrl_typevar(inst), + ) { + Ok(enc) => { + return err!( + inst, + "{} must have an encoding (e.g., {})", + text, + isa.encoding_info().display(enc) + ) + } + Err(_) => return err!(inst, "{} must have an encoding", text), + } } Ok(())