[AsmParser] Add DiagnosticString to register classes in tablegen
authorOliver Stannard <oliver.stannard@arm.com>
Tue, 10 Oct 2017 11:00:40 +0000 (11:00 +0000)
committerOliver Stannard <oliver.stannard@arm.com>
Tue, 10 Oct 2017 11:00:40 +0000 (11:00 +0000)
commit29ffd3f1d9dfe63b8f088ae1c7d4eefefec388f7
treedfaf0156bc435bbc0a409bc23f9b9877251aba13
parent7d2375df305b2a7a2e96daa24e3ee63e772edec0
[AsmParser] Add DiagnosticString to register classes in tablegen

This allows a DiagnosticType and/or DiagnosticString to be associated
with a RegisterClass in tablegen, so that we can emit diagnostics in the
assembler when a register operand is incorrect.

DiagnosticType creates a predictable enum value, which gets returned as
the error code when an operand does not match, and can be used by the
assembly parser to map to a user-facing diagnostic. DiagnosticString
creates an anonymous enum value (currently based on the tablegen class
name), and a function to map from enum values to strings will be
generated. Both of these work the same was as they do for AsmOperand.

This isn't used by any targets yet, but has one (positive) side-effect.
It improves the diagnostic codes returned by validateOperandClass - we
always want to emit the diagnostic that relates to the expected operand
class, but this wasn't always being done when the expected and actual
classes were completely different (token/register/custom). This causes a
few AArch64 diagnostics to be improved, as Match_InvalidOperand was
being returned instead of a specific diagnostic type.

Differential revision: https://reviews.llvm.org/D36691

llvm-svn: 315295
llvm/include/llvm/Target/Target.td
llvm/test/MC/AArch64/arm64-diags.s
llvm/test/MC/AArch64/basic-a64-diagnostics.s
llvm/utils/TableGen/AsmMatcherEmitter.cpp