llvm.org GIT mirror llvm / 6c8de7f
[RISCV][NFC] Factor out matchRegisterNameHelper in RISCVAsmParser.cpp Contains common logic to match a string to a register name. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356330 91177308-0d34-0410-b5e6-96231b3b80d8 Alex Bradbury 1 year, 8 months ago
1 changed file(s) with 17 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
907907 llvm_unreachable("Unknown match type detected!");
908908 }
909909
910 // Attempts to match Name as a register (either using the default name or
911 // alternative ABI names), setting RegNo to the matching register. Upon
912 // failure, returns true and sets RegNo to 0.
913 static bool matchRegisterNameHelper(unsigned &RegNo, StringRef Name) {
914 RegNo = MatchRegisterName(Name);
915 if (RegNo == 0)
916 RegNo = MatchRegisterAltName(Name);
917 return RegNo == 0;
918 }
919
910920 bool RISCVAsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
911921 SMLoc &EndLoc) {
912922 const AsmToken &Tok = getParser().getTok();
915925 RegNo = 0;
916926 StringRef Name = getLexer().getTok().getIdentifier();
917927
918 RegNo = MatchRegisterName(Name);
919 if (RegNo == 0)
920 RegNo = MatchRegisterAltName(Name);
921 if (RegNo == 0)
928 if (matchRegisterNameHelper(RegNo, Name))
922929 return Error(StartLoc, "invalid register name");
923930
924931 getParser().Lex(); // Eat identifier token.
945952 return MatchOperand_NoMatch;
946953 case AsmToken::Identifier:
947954 StringRef Name = getLexer().getTok().getIdentifier();
948 unsigned RegNo = MatchRegisterName(Name);
955 unsigned RegNo;
956 matchRegisterNameHelper(RegNo, Name);
957
949958 if (RegNo == 0) {
950 RegNo = MatchRegisterAltName(Name);
951 if (RegNo == 0) {
952 if (HadParens)
953 getLexer().UnLex(Buf[0]);
954 return MatchOperand_NoMatch;
955 }
959 if (HadParens)
960 getLexer().UnLex(Buf[0]);
961 return MatchOperand_NoMatch;
956962 }
957963 if (HadParens)
958964 Operands.push_back(RISCVOperand::createToken("(", FirstS, isRV64()));