From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1130) id 1683A3858421; Thu, 30 Mar 2023 10:13:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1683A3858421 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Richard Sandiford To: bfd-cvs@sourceware.org Subject: [binutils-gdb] aarch64: Add an error code for out-of-range registers X-Act-Checkin: binutils-gdb X-Git-Author: Richard Sandiford X-Git-Refname: refs/heads/master X-Git-Oldrev: 36043bcff490e6c588d5b52318fbba233f478fab X-Git-Newrev: 859f51df4d0e23c21adc2167d738cf1e6c0f2613 Message-Id: <20230330101301.1683A3858421@sourceware.org> Date: Thu, 30 Mar 2023 10:13:01 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Mar 2023 10:13:01 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D859f51df4d0e= 23c21adc2167d738cf1e6c0f2613 commit 859f51df4d0e23c21adc2167d738cf1e6c0f2613 Author: Richard Sandiford Date: Thu Mar 30 11:09:07 2023 +0100 aarch64: Add an error code for out-of-range registers =20 libopcodes currently reports out-of-range registers as a general AARCH64_OPDE_OTHER_ERROR. However, this means that each register range needs its own hard-coded string, which is a bit cumbersome if the range is determined programmatically. This patch therefore adds a dedicated error type for out-of-range errors. Diff: --- gas/config/tc-aarch64.c | 8 ++++++++ include/opcode/aarch64.h | 10 +++++++++- opcodes/aarch64-opc.c | 20 ++++++++++++++------ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c index 86d5ba992ff..145e241b13b 100644 --- a/gas/config/tc-aarch64.c +++ b/gas/config/tc-aarch64.c @@ -5057,6 +5057,7 @@ const char* operand_mismatch_kind_names[] =3D "AARCH64_OPDE_OUT_OF_RANGE", "AARCH64_OPDE_UNALIGNED", "AARCH64_OPDE_OTHER_ERROR", + "AARCH64_OPDE_INVALID_REGNO", }; #endif /* DEBUG_AARCH64 */ =20 @@ -5081,6 +5082,7 @@ operand_error_higher_severity_p (enum aarch64_operand= _error_kind lhs, gas_assert (AARCH64_OPDE_OUT_OF_RANGE > AARCH64_OPDE_REG_LIST); gas_assert (AARCH64_OPDE_UNALIGNED > AARCH64_OPDE_OUT_OF_RANGE); gas_assert (AARCH64_OPDE_OTHER_ERROR > AARCH64_OPDE_REG_LIST); + gas_assert (AARCH64_OPDE_INVALID_REGNO > AARCH64_OPDE_OTHER_ERROR); return lhs > rhs; } =20 @@ -5712,6 +5714,12 @@ output_operand_error_record (const operand_error_rec= ord *record, char *str) detail->index + 1, str); break; =20 + case AARCH64_OPDE_INVALID_REGNO: + handler (_("%s%d-%s%d expected at operand %d -- `%s'"), + detail->data[0].s, detail->data[1].i, + detail->data[0].s, detail->data[2].i, idx + 1, str); + break; + case AARCH64_OPDE_OUT_OF_RANGE: if (detail->data[0].i !=3D detail->data[1].i) handler (_("%s out of range %d to %d at operand %d -- `%s'"), diff --git a/include/opcode/aarch64.h b/include/opcode/aarch64.h index 10c7983aa2d..6615dec41a7 100644 --- a/include/opcode/aarch64.h +++ b/include/opcode/aarch64.h @@ -1311,6 +1311,13 @@ struct aarch64_inst Error of the highest severity and used for any severe issue that does= not fall into any of the above categories. =20 + AARCH64_OPDE_INVALID_REGNO + A register was syntactically valid and had the right type, but it was + outside the range supported by the associated operand field. This is + a high severity error because there are currently no instructions that + would accept the operands that precede the erroneous one (if any) and + yet still accept a wider range of registers. + AARCH64_OPDE_RECOVERABLE, AARCH64_OPDE_SYNTAX_ERROR and AARCH64_OPDE_FATAL_SYNTAX_ERROR are only deteced by GAS while the AARCH64_OPDE_INVALID_VARIANT error can only be spotted by libopcodes as @@ -1339,7 +1346,8 @@ enum aarch64_operand_error_kind AARCH64_OPDE_UNTIED_OPERAND, AARCH64_OPDE_OUT_OF_RANGE, AARCH64_OPDE_UNALIGNED, - AARCH64_OPDE_OTHER_ERROR + AARCH64_OPDE_OTHER_ERROR, + AARCH64_OPDE_INVALID_REGNO }; =20 /* N.B. GAS assumes that this structure work well with shallow copy. */ diff --git a/opcodes/aarch64-opc.c b/opcodes/aarch64-opc.c index 24cca9e8193..c36e4cc67f6 100644 --- a/opcodes/aarch64-opc.c +++ b/opcodes/aarch64-opc.c @@ -1335,6 +1335,18 @@ set_syntax_error (aarch64_operand_error *mismatch_de= tail, int idx, set_error (mismatch_detail, AARCH64_OPDE_SYNTAX_ERROR, idx, error); } =20 +static inline void +set_invalid_regno_error (aarch64_operand_error *mismatch_detail, int idx, + const char *prefix, int lower_bound, int upper_bound) +{ + if (mismatch_detail =3D=3D NULL) + return; + set_error (mismatch_detail, AARCH64_OPDE_INVALID_REGNO, idx, NULL); + mismatch_detail->data[0].s =3D prefix; + mismatch_detail->data[1].i =3D lower_bound; + mismatch_detail->data[2].i =3D upper_bound; +} + static inline void set_out_of_range_error (aarch64_operand_error *mismatch_detail, int idx, int lower_bound, int upper_bound, @@ -1569,11 +1581,7 @@ operand_general_constraint_met_p (const aarch64_opnd= _info *opnds, int idx, mask =3D (1 << shift) - 1; if (opnd->reg.regno > mask) { - assert (mask =3D=3D 7 || mask =3D=3D 15); - set_other_error (mismatch_detail, idx, - mask =3D=3D 15 - ? _("z0-z15 expected") - : _("z0-z7 expected")); + set_invalid_regno_error (mismatch_detail, idx, "z", 0, mask); return 0; } mask =3D (1u << (size - shift)) - 1; @@ -1642,7 +1650,7 @@ operand_general_constraint_met_p (const aarch64_opnd_= info *opnds, int idx, if (opnd->reg.regno >=3D 8 && get_operand_fields_width (get_operand_from_code (type)) =3D=3D 3) { - set_other_error (mismatch_detail, idx, _("p0-p7 expected")); + set_invalid_regno_error (mismatch_detail, idx, "p", 0, 7); return 0; } break;