Skip to content

Commit

Permalink
[RISCV] Sink some repeated code into parseVTypeToken. NFC (#89694)
Browse files Browse the repository at this point in the history
Both calls to parseVTypeToken were proceeded by check for an Identifier
token and a call to getIdentifier. Sync those into the parseVTypeToken
to reduce repetition.
  • Loading branch information
topperc committed Apr 23, 2024
1 parent e5f9de8 commit 25a391c
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class RISCVAsmParser : public MCTargetAsmParser {

ParseStatus parseDirective(AsmToken DirectiveID) override;

bool parseVTypeToken(StringRef Identifier, VTypeState &State, unsigned &Sew,
bool parseVTypeToken(const AsmToken &Tok, VTypeState &State, unsigned &Sew,
unsigned &Lmul, bool &Fractional, bool &TailAgnostic,
bool &MaskAgnostic);
bool generateVTypeError(SMLoc ErrorLoc);
Expand Down Expand Up @@ -2125,10 +2125,15 @@ ParseStatus RISCVAsmParser::parseJALOffset(OperandVector &Operands) {
return parseImmediate(Operands);
}

bool RISCVAsmParser::parseVTypeToken(StringRef Identifier, VTypeState &State,
bool RISCVAsmParser::parseVTypeToken(const AsmToken &Tok, VTypeState &State,
unsigned &Sew, unsigned &Lmul,
bool &Fractional, bool &TailAgnostic,
bool &MaskAgnostic) {
if (Tok.isNot(AsmToken::Identifier))
return true;

StringRef Identifier = Tok.getIdentifier();

switch (State) {
case VTypeState_SEW:
if (!Identifier.consume_front("e"))
Expand Down Expand Up @@ -2187,24 +2192,14 @@ ParseStatus RISCVAsmParser::parseVTypeI(OperandVector &Operands) {

VTypeState State = VTypeState_SEW;

if (getLexer().isNot(AsmToken::Identifier))
return ParseStatus::NoMatch;

StringRef Identifier = getTok().getIdentifier();

if (parseVTypeToken(Identifier, State, Sew, Lmul, Fractional, TailAgnostic,
if (parseVTypeToken(getTok(), State, Sew, Lmul, Fractional, TailAgnostic,
MaskAgnostic))
return ParseStatus::NoMatch;

getLexer().Lex();

while (parseOptionalToken(AsmToken::Comma)) {
if (getLexer().isNot(AsmToken::Identifier))
break;

Identifier = getTok().getIdentifier();

if (parseVTypeToken(Identifier, State, Sew, Lmul, Fractional, TailAgnostic,
if (parseVTypeToken(getTok(), State, Sew, Lmul, Fractional, TailAgnostic,
MaskAgnostic))
break;

Expand Down

0 comments on commit 25a391c

Please sign in to comment.