Skip to content

Commit 101b3ff

Browse files
authored
[RISCV][NFC] Adopt DiagnosticString interface (#126290)
1 parent a07928c commit 101b3ff

File tree

6 files changed

+19
-58
lines changed

6 files changed

+19
-58
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class RISCVAsmParser : public MCTargetAsmParser {
280280
std::unique_ptr<RISCVOperand> defaultFRMArgLegacyOp() const;
281281

282282
public:
283-
enum RISCVMatchResultTy {
283+
enum RISCVMatchResultTy : unsigned {
284284
Match_Dummy = FIRST_TARGET_MATCH_RESULT_TY,
285285
#define GET_OPERAND_DIAGNOSTIC_TYPES
286286
#include "RISCVGenAsmMatcher.inc"
@@ -1527,10 +1527,6 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
15271527
std::numeric_limits<uint32_t>::max(),
15281528
"operand either must be a bare symbol name or an immediate integer in "
15291529
"the range");
1530-
case Match_InvalidImmZero: {
1531-
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
1532-
return Error(ErrorLoc, "immediate must be zero");
1533-
}
15341530
case Match_InvalidUImmLog2XLen:
15351531
if (isRV64())
15361532
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 6) - 1);
@@ -1657,47 +1653,10 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
16571653
"operand must be a valid system register "
16581654
"name or an integer in the range");
16591655
}
1660-
case Match_InvalidLoadFPImm: {
1661-
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
1662-
return Error(ErrorLoc, "operand must be a valid floating-point constant");
1663-
}
1664-
case Match_InvalidBareSymbol: {
1665-
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
1666-
return Error(ErrorLoc, "operand must be a bare symbol name");
1667-
}
1668-
case Match_InvalidPseudoJumpSymbol: {
1669-
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
1670-
return Error(ErrorLoc, "operand must be a valid jump target");
1671-
}
1672-
case Match_InvalidCallSymbol: {
1673-
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
1674-
return Error(ErrorLoc, "operand must be a bare symbol name");
1675-
}
1676-
case Match_InvalidTPRelAddSymbol: {
1677-
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
1678-
return Error(ErrorLoc, "operand must be a symbol with %tprel_add modifier");
1679-
}
1680-
case Match_InvalidTLSDESCCallSymbol: {
1681-
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
1682-
return Error(ErrorLoc,
1683-
"operand must be a symbol with %tlsdesc_call modifier");
1684-
}
1685-
case Match_InvalidRTZArg: {
1686-
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
1687-
return Error(ErrorLoc, "operand must be 'rtz' floating-point rounding mode");
1688-
}
16891656
case Match_InvalidVTypeI: {
16901657
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
16911658
return generateVTypeError(ErrorLoc);
16921659
}
1693-
case Match_InvalidVMaskRegister: {
1694-
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
1695-
return Error(ErrorLoc, "operand must be v0.t");
1696-
}
1697-
case Match_InvalidVMaskCarryInRegister: {
1698-
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
1699-
return Error(ErrorLoc, "operand must be v0");
1700-
}
17011660
case Match_InvalidSImm5Plus1: {
17021661
return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 4) + 1,
17031662
(1 << 4),
@@ -1706,26 +1665,14 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
17061665
case Match_InvalidSImm26:
17071666
return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 25),
17081667
(1 << 25) - 1);
1709-
case Match_InvalidRlist: {
1710-
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
1711-
return Error(
1712-
ErrorLoc,
1713-
"operand must be {ra [, s0[-sN]]} or {x1 [, x8[-x9][, x18[-xN]]]}");
1714-
}
1715-
case Match_InvalidStackAdj: {
1716-
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
1717-
return Error(
1718-
ErrorLoc,
1719-
"stack adjustment is invalid for this instruction and register list; "
1720-
"refer to Zc spec for a detailed range of stack adjustment");
1721-
}
17221668
case Match_InvalidRnumArg: {
17231669
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, 10);
17241670
}
1725-
case Match_InvalidRegReg: {
1726-
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
1727-
return Error(ErrorLoc, "operands must be register and register");
17281671
}
1672+
1673+
if (const char *MatchDiag = getMatchKindDiag((RISCVMatchResultTy)Result)) {
1674+
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
1675+
return Error(ErrorLoc, MatchDiag);
17291676
}
17301677

17311678
llvm_unreachable("Unknown match type detected!");

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def ImmZeroAsmOperand : AsmOperandClass {
125125
let Name = "ImmZero";
126126
let RenderMethod = "addImmOperands";
127127
let DiagnosticType = !strconcat("Invalid", Name);
128+
let DiagnosticString = "immediate must be zero";
128129
}
129130

130131
// A parse method for (${gpr}) or 0(${gpr}), where the 0 is be silently ignored.
@@ -323,6 +324,7 @@ def BareSymbol : AsmOperandClass {
323324
let Name = "BareSymbol";
324325
let RenderMethod = "addImmOperands";
325326
let DiagnosticType = "InvalidBareSymbol";
327+
let DiagnosticString = "operand must be a bare symbol name";
326328
let ParserMethod = "parseBareSymbol";
327329
}
328330

@@ -335,6 +337,7 @@ def CallSymbol : AsmOperandClass {
335337
let Name = "CallSymbol";
336338
let RenderMethod = "addImmOperands";
337339
let DiagnosticType = "InvalidCallSymbol";
340+
let DiagnosticString = "operand must be a bare symbol name";
338341
let ParserMethod = "parseCallSymbol";
339342
}
340343

@@ -347,6 +350,7 @@ def PseudoJumpSymbol : AsmOperandClass {
347350
let Name = "PseudoJumpSymbol";
348351
let RenderMethod = "addImmOperands";
349352
let DiagnosticType = "InvalidPseudoJumpSymbol";
353+
let DiagnosticString = "operand must be a valid jump target";
350354
let ParserMethod = "parsePseudoJumpSymbol";
351355
}
352356

@@ -359,6 +363,7 @@ def TPRelAddSymbol : AsmOperandClass {
359363
let Name = "TPRelAddSymbol";
360364
let RenderMethod = "addImmOperands";
361365
let DiagnosticType = "InvalidTPRelAddSymbol";
366+
let DiagnosticString = "operand must be a symbol with %tprel_add modifier";
362367
let ParserMethod = "parseOperandWithModifier";
363368
}
364369

@@ -1779,6 +1784,7 @@ def TLSDESCCallSymbol : AsmOperandClass {
17791784
let Name = "TLSDESCCallSymbol";
17801785
let RenderMethod = "addImmOperands";
17811786
let DiagnosticType = "InvalidTLSDESCCallSymbol";
1787+
let DiagnosticString = "operand must be a symbol with %tlsdesc_call modifier";
17821788
let ParserMethod = "parseOperandWithModifier";
17831789
}
17841790

llvm/lib/Target/RISCV/RISCVInstrInfoV.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ def VMaskAsmOperand : AsmOperandClass {
4848
let IsOptional = 1;
4949
let DefaultMethod = "defaultMaskRegOp";
5050
let DiagnosticType = "InvalidVMaskRegister";
51+
let DiagnosticString = "operand must be v0.t";
5152
}
5253

5354
def VMaskCarryInAsmOperand : AsmOperandClass {
5455
let Name = "RVVMaskCarryInRegOpOperand";
5556
let RenderMethod = "addRegOperands";
5657
let PredicateMethod = "isV0Reg";
5758
let DiagnosticType = "InvalidVMaskCarryInRegister";
59+
let DiagnosticString = "operand must be v0";
5860
}
5961

6062
def VMaskOp : RegisterOperand<VMV0> {

llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ def CVrrAsmOperand : AsmOperandClass {
514514
let Name = "RegReg";
515515
let ParserMethod = "parseRegReg";
516516
let DiagnosticType = "InvalidRegReg";
517+
let DiagnosticString = "operands must be register and register";
517518
}
518519

519520
def CVrr : Operand<i32>,

llvm/lib/Target/RISCV/RISCVInstrInfoZc.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ def RlistAsmOperand : AsmOperandClass {
3939
let Name = "Rlist";
4040
let ParserMethod = "parseReglist";
4141
let DiagnosticType = "InvalidRlist";
42+
let DiagnosticString = "operand must be {ra [, s0[-sN]]} or {x1 [, x8[-x9][, x18[-xN]]]}";
4243
}
4344

4445
def StackAdjAsmOperand : AsmOperandClass {
4546
let Name = "StackAdj";
4647
let ParserMethod = "parseZcmpStackAdj";
4748
let DiagnosticType = "InvalidStackAdj";
49+
let DiagnosticString = "stack adjustment is invalid for this instruction and register list; "
50+
"refer to Zc spec for a detailed range of stack adjustment";
4851
let PredicateMethod = "isSpimm";
4952
let RenderMethod = "addSpimmOperands";
5053
}

llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def LoadFPImmOperand : AsmOperandClass {
3030
let ParserMethod = "parseFPImm";
3131
let RenderMethod = "addFPImmOperands";
3232
let DiagnosticType = "InvalidLoadFPImm";
33+
let DiagnosticString = "operand must be a valid floating-point constant";
3334
}
3435

3536
def loadfpimm : Operand<XLenVT> {
@@ -43,6 +44,7 @@ def RTZArg : AsmOperandClass {
4344
let Name = "RTZArg";
4445
let RenderMethod = "addFRMArgOperands";
4546
let DiagnosticType = "InvalidRTZArg";
47+
let DiagnosticString = "operand must be 'rtz' floating-point rounding mode";
4648
let ParserMethod = "parseFRMArg";
4749
}
4850

0 commit comments

Comments
 (0)