]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
opcodes: aarch64: enforce checks on subclass flags in aarch64-gen.c
authorIndu Bhagat <indu.bhagat@oracle.com>
Fri, 19 Jul 2024 03:24:35 +0000 (20:24 -0700)
committerIndu Bhagat <indu.bhagat@oracle.com>
Fri, 19 Jul 2024 03:54:14 +0000 (20:54 -0700)
Enforce some checks on the newly added subclass flags:
  - If a subclass is set of one insn of an iclass, every insn of that
    iclass must have non-zero subclass field.
  - For all other iclasses, the subclass bits are zero for all insns.

include/
        * opcode/aarch64.h (enum aarch64_insn_class): Identify the
maximum iclass enum value.

opcodes/
        * aarch64-gen.c (iclass_has_subclasses_p): New array of bool.
        (read_table): Enforce checks on subclass flags.

include/opcode/aarch64.h
opcodes/aarch64-gen.c

index df07d3b1bbab1bb92397a0ffb78ef6cf24d22deb..bc779c973d6f2e237b190f7418f200af6e186b35 100644 (file)
@@ -1110,7 +1110,8 @@ enum aarch64_insn_class
   sve2_urqvs,
   sve_index1,
   rcpc3,
-  lut
+  lut,
+  last_iclass = lut
 };
 
 /* Opcode enumerators.  */
index 02dcde1f676f9d4a4cc62fb9eae392eb9a556801..6ca0932aa6ee955e7711bffef92a750c0e9a430a 100644 (file)
@@ -123,6 +123,8 @@ get_aarch64_opcode (const opcode_node *opcode_node)
   return &index2table (opcode_node->index)[real_index (opcode_node->index)];
 }
 
+static bool iclass_has_subclasses_p[last_iclass];
+
 static void
 read_table (const struct aarch64_opcode* table)
 {
@@ -181,6 +183,9 @@ read_table (const struct aarch64_opcode* table)
          ++errors;
        }
 
+      if (ent->flags & F_SUBCLASS)
+       iclass_has_subclasses_p[ent->iclass] = true;
+
       *new_ent = new_opcode_node ();
       (*new_ent)->opcode = ent->opcode;
       (*new_ent)->mask = ent->mask;
@@ -188,6 +193,20 @@ read_table (const struct aarch64_opcode* table)
       new_ent = &((*new_ent)->next);
     } while ((++ent)->name);
 
+  ent = table;
+  do
+    {
+      /* If a subclass is set for one insn of an iclass, every insn of that
+        iclass must have non-zero subclass field.  */
+      if ((iclass_has_subclasses_p[ent->iclass] && !(ent->flags & F_SUBCLASS))
+         || (!iclass_has_subclasses_p[ent->iclass] && (ent->flags & F_SUBCLASS)))
+       {
+         fprintf (stderr, "%s: unexpected subclass\n", ent->name);
+         ++errors;
+       }
+      ent++;
+    } while (ent->name);
+
   if (errors)
     {
       fprintf (stderr, "%u errors, exiting\n", errors);