Give better verifier errors for missing instruction encodings.
When possible, provide the ISA's default encoding as a suggesting for the missing instruction encoding.
This commit is contained in:
@@ -920,28 +920,40 @@ impl<'a> Verifier<'a> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if this opcode must be encoded.
|
||||||
|
let mut needs_enc = None;
|
||||||
if opcode.is_branch() {
|
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() {
|
if let Some(text) = needs_enc {
|
||||||
return err!(inst, "Call must have an encoding");
|
// This instruction needs an encoding, so generate an error.
|
||||||
}
|
// Provide the ISA default encoding as a hint.
|
||||||
|
match isa.encode(
|
||||||
if opcode.is_return() {
|
&self.func.dfg,
|
||||||
return err!(inst, "Return must have an encoding");
|
&self.func.dfg[inst],
|
||||||
}
|
self.func.dfg.ctrl_typevar(inst),
|
||||||
|
) {
|
||||||
if opcode.can_store() {
|
Ok(enc) => {
|
||||||
return err!(inst, "Store must have an encoding");
|
return err!(
|
||||||
}
|
inst,
|
||||||
|
"{} must have an encoding (e.g., {})",
|
||||||
if opcode.can_trap() {
|
text,
|
||||||
return err!(inst, "Trapping instruction must have an encoding");
|
isa.encoding_info().display(enc)
|
||||||
}
|
)
|
||||||
|
}
|
||||||
if opcode.other_side_effects() {
|
Err(_) => return err!(inst, "{} must have an encoding", text),
|
||||||
return err!(inst, "Instruction with side effects must have an encoding");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user