[PATCH 15/28] aarch64: Refactor read_table and validate_table

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


Use for loops, and make iclass_has_subclasses_p a local variable.


diff --git a/opcodes/aarch64-gen.c b/opcodes/aarch64-gen.c
index 13cbe0c426ce29bc897a7d7f683dd78a1c15bc2f..f0604c2ecbdfec10261642d207447434dc6d82c0 100644
--- a/opcodes/aarch64-gen.c
+++ b/opcodes/aarch64-gen.c
@@ -93,20 +93,17 @@ get_aarch64_opcode (const opcode_node *opcode_node)
   return &aarch64_opcode_table[opcode_node->index];
 }
 
-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
 validate_table (void)
 {
-  const struct aarch64_opcode *ent = aarch64_opcode_table;
+  const struct aarch64_opcode *ent;
   unsigned int errors = 0;
 
-  if (!ent->name)
-    return;
+  bool iclass_has_subclasses_p[last_iclass + 1] = { false };
 
-  do
+  for (ent = aarch64_opcode_table; ent->name; ent++)
     {
       bool match = false;
 
@@ -191,10 +188,9 @@ validate_table (void)
 
       if (ent->flags & F_SUBCLASS)
 	iclass_has_subclasses_p[ent->iclass] = true;
-    } while ((++ent)->name);
+    }
 
-  ent = aarch64_opcode_table;
-  do
+  for (ent = aarch64_opcode_table; ent->name; ent++)
     {
       /* If a subclass is set for one insn of an iclass, every insn of that
 	 iclass must have non-zero subclass field.  */
@@ -205,8 +201,7 @@ validate_table (void)
 	  fprintf (stderr, "%s: unexpected subclass\n", ent->name);
 	  ++errors;
 	}
-      ent++;
-    } while (ent->name);
+    }
 
   if (errors)
     {
@@ -219,33 +214,24 @@ validate_table (void)
 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
+  opcode_node **tail = &opcode_nodes_head.next;
+  for (unsigned int index = 0; ; index++)
     {
+      const struct aarch64_opcode *ent = &aarch64_opcode_table[index];
+      if (!ent->name)
+	break;
+
       /* 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);
+      opcode_node *node = new_opcode_node ();
+      node->opcode = ent->opcode;
+      node->mask = ent->mask;
+      node->index = index;
+      *tail = node;
+      tail = &node->next;
+    }
 }
 
 static inline void


More information about the Binutils mailing list