[PATCH 14/28] aarch64: Split up read_table() in aarch64-gen.c

Alice Carlotti alice.carlotti@arm.com
Wed Nov 4 18:45:01 GMT 2026


Split out all of the validation in read_table() into a new function
validate_table(), and don't skip validation for aliases.

The other results of initialize_decoder_tree() are only used when
emitting aarch64-dis-2.c, so move the call (and inline it) into the
corresponding if block.


diff --git a/opcodes/aarch64-gen.c b/opcodes/aarch64-gen.c
index b41fc5c5e5598ed3266a50561a4d4c1e65e5cba1..13cbe0c426ce29bc897a7d7f683dd78a1c15bc2f 100644
--- a/opcodes/aarch64-gen.c
+++ b/opcodes/aarch64-gen.c
@@ -95,22 +95,17 @@ get_aarch64_opcode (const opcode_node *opcode_node)
 
 static bool iclass_has_subclasses_p[last_iclass + 1];
 
+/* Verify various properties of the opcode table.  This allows some errors to
+   be detected at build time.  */
 static void
-read_table (void)
+validate_table (void)
 {
   const struct aarch64_opcode *ent = aarch64_opcode_table;
-  opcode_node **new_ent;
-  unsigned int index = 0;
   unsigned int errors = 0;
 
   if (!ent->name)
     return;
 
-  new_ent = &opcode_nodes_head.next;
-
-  while (*new_ent)
-    new_ent = &(*new_ent)->next;
-
   do
     {
       bool match = false;
@@ -124,12 +119,6 @@ read_table (void)
 	 opcode is a programmer friendly pseudo instruction available only in
 	 the assembly code (thus will not show up in the disassembly).  */
       assert (!pseudo_opcode_p (ent) || alias_opcode_p (ent));
-      /* Skip alias (inc. pseudo) opcode.  */
-      if (alias_opcode_p (ent))
-	{
-	  index++;
-	  continue;
-	}
 
       /* Check tied_operand against operands[].  */
       for (unsigned int i = 1; i < ARRAY_SIZE (ent->operands); ++i)
@@ -202,12 +191,6 @@ read_table (void)
 
       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;
-      (*new_ent)->index = index++;
-      new_ent = &((*new_ent)->next);
     } while ((++ent)->name);
 
   ent = aarch64_opcode_table;
@@ -232,6 +215,39 @@ read_table (void)
     }
 }
 
+/* Create a linked list of opcode table entries.  */
+static void
+read_table (void)
+{
+  const struct aarch64_opcode *ent = aarch64_opcode_table;
+  opcode_node **new_ent;
+  unsigned int index = 0;
+
+  if (!ent->name)
+    return;
+
+  new_ent = &opcode_nodes_head.next;
+
+  while (*new_ent)
+    new_ent = &(*new_ent)->next;
+
+  do
+    {
+      /* Skip alias (inc. pseudo) opcode.  */
+      if (alias_opcode_p (ent))
+	{
+	  index++;
+	  continue;
+	}
+
+      *new_ent = new_opcode_node ();
+      (*new_ent)->opcode = ent->opcode;
+      (*new_ent)->mask = ent->mask;
+      (*new_ent)->index = index++;
+      new_ent = &((*new_ent)->next);
+    } while ((++ent)->name);
+}
+
 static inline void
 print_one_opcode_node (opcode_node* ent)
 {
@@ -434,17 +450,6 @@ divide_table (void)
   return bittree;
 }
 
-/* Read in all of the tables, create the decoding decision tree and return
-   the tree root.  */
-static struct bittree *
-initialize_decoder_tree (void)
-{
-  read_table ();
-  if (debug)
-    print_opcode_nodes ();
-  return divide_table ();
-}
-
 static void __attribute__ ((format (printf, 2, 3)))
 indented_print (unsigned int indent, const char *format, ...)
 {
@@ -1377,11 +1382,7 @@ main (int argc, char **argv)
       xexit (2);
     }
 
-  struct bittree *decoder_tree;
-
-  decoder_tree = initialize_decoder_tree ();
-  if (debug)
-    print_divide_result (decoder_tree);
+  validate_table ();
 
   label_opcode_nodes ();
 
@@ -1423,6 +1424,13 @@ main (int argc, char **argv)
   /* Generate opcode entry lookup for the disassembler.  */
   if (gen_disassembler_p)
     {
+      read_table ();
+      if (debug)
+	print_opcode_nodes ();
+      struct bittree *decoder_tree = divide_table ();
+      if (debug)
+	print_divide_result (decoder_tree);
+
       print_decision_tree (decoder_tree);
       print_find_next_opcode (decoder_tree);
       release_resource_decoder_tree (decoder_tree);


More information about the Binutils mailing list