[binutils-gdb] aarch64: Add qualifier checks to aarch64-gen

Alice Carlotti via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4355b37ca0864f3670a52ef68a64bf13e1c0cd4f

commit 4355b37ca0864f3670a52ef68a64bf13e1c0cd4f
Author: Alice Carlotti <[email protected]>
Date:   Mon Mar 10 15:32:11 2025 +0000

    aarch64: Add qualifier checks to aarch64-gen
    
    Add checks to verify that all qualifier sequences have the correct
    length.

Diff:
---
 opcodes/aarch64-gen.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/opcodes/aarch64-gen.c b/opcodes/aarch64-gen.c
index 1988879da81..d989c557523 100644
--- a/opcodes/aarch64-gen.c
+++ b/opcodes/aarch64-gen.c
@@ -150,6 +150,11 @@ read_table (const struct aarch64_opcode* table)
     {
       bool match = false;
 
+      unsigned int operand_count = 0;
+      while (operand_count < ARRAY_SIZE (ent->operands)
+	     && ent->operands[operand_count] != AARCH64_OPND_NIL)
+	operand_count++;
+
       /* F_PSEUDO needs to be used together with F_ALIAS to indicate an alias
 	 opcode is a programmer friendly pseudo instruction available only in
 	 the assembly code (thus will not show up in the disassembly).  */
@@ -189,6 +194,47 @@ read_table (const struct aarch64_opcode* table)
 	  ++errors;
 	}
 
+      /* Check that the qualifier sequence lengths match the number of
+	 operands.  */
+      bool qlf_end = false;
+      for (unsigned int i = 0; i < ARRAY_SIZE (ent->qualifiers_list); i++)
+	{
+	  for (unsigned int j = 0; j < ARRAY_SIZE (ent->qualifiers_list[0]); j++)
+	    {
+	      if (j >= operand_count || qlf_end)
+		{
+		  if (ent->qualifiers_list[i][j] != AARCH64_OPND_QLF_UNUSED)
+		    {
+		      fprintf (stderr,
+			       "%s (%08x,%08x): Qualifier %u for sequence %u should be UNUSED.\n",
+			       ent->name, ent->opcode, ent->mask, j, i);
+		      ++errors;
+		    }
+		}
+	      else if (ent->qualifiers_list[i][j] == AARCH64_OPND_QLF_UNUSED)
+		{
+		  if (j == 0)
+		    {
+		      qlf_end = true;
+		      if (i == 0 && operand_count > 0)
+			{
+			  fprintf (stderr,
+				   "%s (%08x,%08x): No qualifiers specified.\n",
+				   ent->name, ent->opcode, ent->mask);
+			  ++errors;
+			}
+		    }
+		  else
+		    {
+		      fprintf (stderr,
+			       "%s (%08x,%08x): Qualifier %u for sequence %u is missing.\n",
+			       ent->name, ent->opcode, ent->mask, j, i);
+		      ++errors;
+		    }
+		}
+	    }
+	}
+
       if (ent->flags & F_SUBCLASS)
 	iclass_has_subclasses_p[ent->iclass] = true;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.