[llvm] r356330 - [RISCV][NFC] Factor out matchRegisterNameHelper in RISCVAsmParser.cpp
Alex Bradbury via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 17 05:02:33 PDT 2019
Author: asb
Date: Sun Mar 17 05:02:32 2019
New Revision: 356330
URL: http://llvm.org/viewvc/llvm-project?rev=356330&view=rev
Log:
[RISCV][NFC] Factor out matchRegisterNameHelper in RISCVAsmParser.cpp
Contains common logic to match a string to a register name.
Modified:
llvm/trunk/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Modified: llvm/trunk/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp?rev=356330&r1=356329&r2=356330&view=diff
==============================================================================
--- llvm/trunk/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp Sun Mar 17 05:02:32 2019
@@ -908,6 +908,16 @@ bool RISCVAsmParser::MatchAndEmitInstruc
llvm_unreachable("Unknown match type detected!");
}
+// Attempts to match Name as a register (either using the default name or
+// alternative ABI names), setting RegNo to the matching register. Upon
+// failure, returns true and sets RegNo to 0.
+static bool matchRegisterNameHelper(unsigned &RegNo, StringRef Name) {
+ RegNo = MatchRegisterName(Name);
+ if (RegNo == 0)
+ RegNo = MatchRegisterAltName(Name);
+ return RegNo == 0;
+}
+
bool RISCVAsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
SMLoc &EndLoc) {
const AsmToken &Tok = getParser().getTok();
@@ -916,10 +926,7 @@ bool RISCVAsmParser::ParseRegister(unsig
RegNo = 0;
StringRef Name = getLexer().getTok().getIdentifier();
- RegNo = MatchRegisterName(Name);
- if (RegNo == 0)
- RegNo = MatchRegisterAltName(Name);
- if (RegNo == 0)
+ if (matchRegisterNameHelper(RegNo, Name))
return Error(StartLoc, "invalid register name");
getParser().Lex(); // Eat identifier token.
@@ -946,14 +953,13 @@ OperandMatchResultTy RISCVAsmParser::par
return MatchOperand_NoMatch;
case AsmToken::Identifier:
StringRef Name = getLexer().getTok().getIdentifier();
- unsigned RegNo = MatchRegisterName(Name);
+ unsigned RegNo;
+ matchRegisterNameHelper(RegNo, Name);
+
if (RegNo == 0) {
- RegNo = MatchRegisterAltName(Name);
- if (RegNo == 0) {
- if (HadParens)
- getLexer().UnLex(Buf[0]);
- return MatchOperand_NoMatch;
- }
+ if (HadParens)
+ getLexer().UnLex(Buf[0]);
+ return MatchOperand_NoMatch;
}
if (HadParens)
Operands.push_back(RISCVOperand::createToken("(", FirstS, isRV64()));
More information about the llvm-commits
mailing list