Closed Nelson1225 closed 4 years ago
The match_func
have many uses,
match_opcode
The basic encoding check.
match_never
For INSN_MACRO without any checking here.
match_rs1_eq_rs2
with INSN_ALIAS
The match and mask macros are same as the non-alias one, but use the match_func
to decide which one to disassemble.
match_rd_nonzero
, match_c_add_with_hint
, match_c_lui_with_hint
, match_c_slli
, match_c_slli64
For instruction constraints, we should report "Error: illegal operand" for them.
match_c_add
, match_c_lui
, match_c_nop
, match_slli_as_c_slli
, match_srxi_as_c_srxi
For RVI to RVC, avoid converting the RVI instruction to the corresponding RVC hint instruction.
match_c_addi16sp
, match_c_addi4spn
For both instruction constraints and RVI to RVC. We should report "Error: illegal operand" for them.
match_widen_vd_neq_vs1_neq_vs2_neq_vm
, match_widen_vd_neq_vs1_neq_vm
, match_widen_vd_neq_vs2_neq_vm
, match_widen_vd_neq_vm
, match_quad_vd_neq_vs1_neq_vs2_neq_vm
, match_quad_vd_neq_vs2_neq_vm
, match_narrow_vd_neq_vs2
, match_vd_neq_vs1_neq_vs2_neq_vm
, match_vd_neq_vs2_neq_vm
, match_vd_neq_vm
, match_vmv_nf_rv
For vector instruction constraints, we should report "Error: illegal operand" for them.
As mentioned above, we only need to report the error message for which are used to check the instruction constraints.
I prefer to close this PR for now. I should try to upstream the parts of this PR, and then implement the remaining parts to rvv-0.9.x or newer version. This feature seems not so urgent or necessary, so I close this until we need it again. Thanks.
Do not merge these commits. I just record them here, and appreciate for any feedback :)
Currently, RISC-V assembler just report "Error: unrecognized opcode" or "Error: illegal operands" for lots of error cases when parsing the instructions (riscv_ip). It would be nice if we can give more error information to user. MIPS is doing this good, so the basic idea is come from them.
There are five commits to improve the current error report,
The first three commits are more suited to commit to upstream, and the last two commits are used to improve the error report for RVV. If everyone is fine for these commits, then I will send the first three commits to the upstream. Please see the details in the commits' comment, thanks :)
Basically, there are three stages for parsing one instruction. First, we find all candidates which have the same opcode name, but have different formats in the riscv_opcodes table. If the opcode name isn't defined in the table, then we should report "Error: unrecognized opcode". Second, we check the
insn_class
andxlen_requirement
of the opcode candidate to determine whether it is valid for the current -march setting and RV32/RV64. If it is invalid, then we should report "Error: invalid instruction ...". After that, we check if each operand is legal, otherwise, the "Error: illegal operand" should be reported. We compare theargs
, which describe the syntax of operands, in the opcode table. And then call thematch_func
to do the final checking. Thematch_func
have many uses, but we only need to report the error message for which are used to check the instruction constraints. As for theargs
comparing, it is more complicated, so I report at least which operand is invalid for them. Beside, the error information may be set multiple times during parsing. For now I just report the error for the last opcode candidate.All of the above mentioned are implemented in the first commit. Now user can get more information about their wrong assembly instruction,
The second and third commits are used to avoid redundant error messages. Consider the following case:
then the assembler reports the following errors:
There are lots of redundant messages reported since we use
as_bad
to report the error for each opcode candidate. Therefore, replaceas_bad
withset_insn_error
to avoid the redundant message and then only report the last useful one.But there are one issue that we may need to resolve in the future,
The exactly invalid operand is Funct7 field for the above code, but now the assembler will report the invalid one is Funct2. The reason is that we always report the last error message for the last candidate. I have no idea that how to improve this now.