[PATCH 17/28] aarch64: Add report_error helper to aarch64-gen
Alice Carlotti
alice.carlotti@arm.com
Wed Nov 4 18:46:05 GMT 2026
Move the repetitive parts of error reporting out of validate_table,
to reduce code duplication and make validate_table more readable.
diff --git a/opcodes/aarch64-gen.c b/opcodes/aarch64-gen.c
index 0779618dcc95b2b6a91cff99f8edd34086e0f24e..fe33f5fa17d3efb1027b6250b41008d12c5673e2 100644
--- a/opcodes/aarch64-gen.c
+++ b/opcodes/aarch64-gen.c
@@ -90,13 +90,27 @@ get_aarch64_opcode (const opcode_node *opcode_node)
return &aarch64_opcode_table[opcode_node->index];
}
+static unsigned int table_error_count = 0;
+
+static void __attribute__ ((format (printf, 2, 3)))
+report_error (const struct aarch64_opcode *ent, const char *format, ...)
+{
+ va_list ap;
+ va_start (ap, format);
+ fprintf (stderr, "%s (%08x,%08x): ",
+ ent->name, ent->opcode, ent->mask);
+ vfprintf (stderr, format, ap);
+ fprintf (stderr, "\n");
+ va_end (ap);
+ table_error_count++;
+}
+
/* 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;
- unsigned int errors = 0;
bool iclass_has_subclasses_p[last_iclass + 1] = { false };
@@ -125,22 +139,14 @@ validate_table (void)
match = true;
if (i != ent->tied_operand)
- {
- fprintf (stderr,
- "%s (%08x,%08x): operands 1 and %u match, but tied=%u\n",
- ent->name, ent->opcode, ent->mask, i + 1,
- ent->tied_operand);
- ++errors;
- }
+ report_error (ent, "operands 1 and %u match, but tied=%u",
+ i + 1, ent->tied_operand);
}
if (!match && ent->tied_operand
/* SME LDR/STR (array vector) tie together inner immediates only. */
&& ent->iclass != sme_ldr && ent->iclass != sme_str)
- {
- fprintf (stderr, "%s: no operands match, but tied=%u\n",
- ent->name, ent->tied_operand);
- ++errors;
- }
+ report_error (ent, "no operands match, but tied=%u",
+ ent->tied_operand);
/* Check that the qualifier sequence lengths match the number of
operands. */
@@ -152,12 +158,8 @@ validate_table (void)
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;
- }
+ report_error (ent, "Qualifier %u for sequence %u should be UNUSED.",
+ j, i);
}
else if (ent->qualifiers_list[i][j] == AARCH64_OPND_QLF_UNUSED)
{
@@ -165,20 +167,11 @@ validate_table (void)
{
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;
- }
+ report_error (ent, "no qualifiers specified.");
}
else
- {
- fprintf (stderr,
- "%s (%08x,%08x): Qualifier %u for sequence %u is missing.\n",
- ent->name, ent->opcode, ent->mask, j, i);
- ++errors;
- }
+ report_error (ent, "Qualifier %u for sequence %u is missing.",
+ j, i);
}
}
}
@@ -194,15 +187,12 @@ validate_table (void)
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;
- }
+ report_error (ent, "unexpected subclass");
}
- if (errors)
+ if (table_error_count)
{
- fprintf (stderr, "%u errors, exiting\n", errors);
+ fprintf (stderr, "%u errors, exiting\n", table_error_count);
xexit (3);
}
}
More information about the Binutils
mailing list