forked from OSchip/llvm-project
[RISCV][NFC] Factor out matchRegisterNameHelper in RISCVAsmParser.cpp
Contains common logic to match a string to a register name. llvm-svn: 356330
This commit is contained in:
parent
b18e314a7c
commit
997947961a
|
@ -908,6 +908,16 @@ bool RISCVAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
|
|||
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(unsigned &RegNo, SMLoc &StartLoc,
|
|||
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::parseRegister(OperandVector &Operands,
|
|||
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()));
|
||||
|
|
Loading…
Reference in New Issue