[PATCH 3/6] aarch64: use an enumeration for operand indices.

Richard Earnshaw rearnsha@arm.com
Fri Jul 18 10:03:58 GMT 2025


The generated aarch64 operand tables use index values into an array.  But if
the table of operands is modified by inserting a new operand into the middle
of the table, *all* the index values can change, leading to a lot of
churn in the generated output.

include/opcode/aarch64.h already provides an enumeration for the operands,
so make use of that instead of printing out the raw index values.
---
 opcodes/aarch64-gen.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/opcodes/aarch64-gen.c b/opcodes/aarch64-gen.c
index ba48f06024e..17fca2fe4d5 100644
--- a/opcodes/aarch64-gen.c
+++ b/opcodes/aarch64-gen.c
@@ -1027,8 +1027,9 @@ print_operand_table (void)
   printf ("};\n");
 }
 
-/* Generate aarch64_insert_operand in C to the standard output.  */
+#define OPN_PFX_ENUM "AARCH64_OPND_"
 
+/* Generate aarch64_insert_operand in C to the standard output.  */
 static void
 print_operand_inserter (void)
 {
@@ -1047,7 +1048,7 @@ print_operand_inserter (void)
 			   aarch64_operand_error *errors)\n");
   printf ("{\n");
   printf ("  /* Use the index as the key.  */\n");
-  printf ("  int key = self - aarch64_operands;\n");
+  printf ("  enum aarch64_opnd key = self - aarch64_operands;\n");
   printf ("  switch (key)\n");
   printf ("    {\n");
 
@@ -1061,7 +1062,7 @@ print_operand_inserter (void)
 	  int j = i + 1;
 	  const int len = strlen (opnd->inserter);
 	  operand *opnd2 = opnd + 1;
-	  printf ("    case %u:\n", (unsigned int)(opnd - operands));
+	  printf ("    case " OPN_PFX_ENUM "%s:\n", opnd->str);
 	  opnd->processed = 1;
 	  for (; j < num; ++j, ++opnd2)
 	    {
@@ -1070,7 +1071,8 @@ print_operand_inserter (void)
 		  && len == strlen (opnd2->inserter)
 		  && strncmp (opnd->inserter, opnd2->inserter, len) == 0)
 		{
-		  printf ("    case %u:\n", (unsigned int)(opnd2 - operands));
+		  printf ("    case " OPN_PFX_ENUM "%s:\n", opnd2->str);
+
 		  opnd2->processed = 1;
 		}
 	    }
@@ -1104,7 +1106,7 @@ print_operand_extractor (void)
 			   aarch64_operand_error *errors)\n");
   printf ("{\n");
   printf ("  /* Use the index as the key.  */\n");
-  printf ("  int key = self - aarch64_operands;\n");
+  printf ("  enum aarch64_opnd key = self - aarch64_operands;\n");
   printf ("  switch (key)\n");
   printf ("    {\n");
 
@@ -1118,7 +1120,7 @@ print_operand_extractor (void)
 	  int j = i + 1;
 	  const int len = strlen (opnd->extractor);
 	  operand *opnd2 = opnd + 1;
-	  printf ("    case %u:\n", (unsigned int)(opnd - operands));
+	  printf ("    case " OPN_PFX_ENUM "%s:\n", opnd->str);
 	  opnd->processed = 1;
 	  for (; j < num; ++j, ++opnd2)
 	    {
@@ -1127,7 +1129,7 @@ print_operand_extractor (void)
 		  && len == strlen (opnd2->extractor)
 		  && strncmp (opnd->extractor, opnd2->extractor, len) == 0)
 		{
-		  printf ("    case %u:\n", (unsigned int)(opnd2 - operands));
+		  printf ("    case " OPN_PFX_ENUM "%s:\n", opnd2->str);
 		  opnd2->processed = 1;
 		}
 	    }
-- 
2.43.0



More information about the Binutils mailing list