Skip to content

Commit

Permalink
opcodes: aarch64: enforce checks on subclass flags in aarch64-gen.c
Browse files Browse the repository at this point in the history
[No changes in V5]

[New in V4]

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.
  • Loading branch information
ibhagatgnu committed Jul 13, 2024
1 parent a84e9df commit ffd91fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/opcode/aarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,8 @@ enum aarch64_insn_class
sve2_urqvs,
sve_index1,
rcpc3,
lut
lut,
last_iclass = lut
};

/* Opcode enumerators. */
Expand Down
19 changes: 19 additions & 0 deletions opcodes/aarch64-gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -181,13 +183,30 @@ 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;
(*new_ent)->index = index++;
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);
Expand Down

0 comments on commit ffd91fa

Please sign in to comment.