diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2023-07-26 19:03:47 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2023-07-26 19:04:23 +0000 |
| commit | 7fa27ce4a07f19b07799a767fc29416f3b625afb (patch) | |
| tree | 27825c83636c4de341eb09a74f49f5d38a15d165 /llvm/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp | |
| parent | e3b557809604d036af6e00c60f012c2025b59a5e (diff) | |
Diffstat (limited to 'llvm/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp')
| -rw-r--r-- | llvm/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp | 58 |
1 files changed, 25 insertions, 33 deletions
diff --git a/llvm/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp b/llvm/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp index 1560f14976dd..f2c90f565863 100644 --- a/llvm/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp +++ b/llvm/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp @@ -53,7 +53,7 @@ class MSP430AsmParser : public MCTargetAsmParser { bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc, OperandVector &Operands) override; - bool ParseDirective(AsmToken DirectiveID) override; + ParseStatus parseDirective(AsmToken DirectiveID) override; bool ParseDirectiveRefSym(AsmToken DirectiveID); unsigned validateTargetOperandClass(MCParsedAsmOperand &Op, @@ -330,7 +330,7 @@ OperandMatchResultTy MSP430AsmParser::tryParseRegister(MCRegister &RegNo, bool MSP430AsmParser::parseJccInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc, OperandVector &Operands) { - if (!Name.startswith_insensitive("j")) + if (!Name.starts_with_insensitive("j")) return true; auto CC = Name.drop_front().lower(); @@ -363,8 +363,7 @@ bool MSP430AsmParser::parseJccInstruction(ParseInstructionInfo &Info, } // Skip optional '$' sign. - if (getLexer().getKind() == AsmToken::Dollar) - getLexer().Lex(); // Eat '$' + (void)parseOptionalToken(AsmToken::Dollar); const MCExpr *Val; SMLoc ExprLoc = getLexer().getLoc(); @@ -393,7 +392,7 @@ bool MSP430AsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc, OperandVector &Operands) { // Drop .w suffix - if (Name.endswith_insensitive(".w")) + if (Name.ends_with_insensitive(".w")) Name = Name.drop_back(2); if (!parseJccInstruction(Info, Name, NameLoc, Operands)) @@ -411,11 +410,8 @@ bool MSP430AsmParser::ParseInstruction(ParseInstructionInfo &Info, return true; // Parse second operand if any - if (getLexer().is(AsmToken::Comma)) { - getLexer().Lex(); // Eat ',' - if (ParseOperand(Operands)) - return true; - } + if (parseOptionalToken(AsmToken::Comma) && ParseOperand(Operands)) + return true; if (getLexer().isNot(AsmToken::EndOfStatement)) { SMLoc Loc = getLexer().getLoc(); @@ -428,27 +424,26 @@ bool MSP430AsmParser::ParseInstruction(ParseInstructionInfo &Info, } bool MSP430AsmParser::ParseDirectiveRefSym(AsmToken DirectiveID) { - StringRef Name; - if (getParser().parseIdentifier(Name)) - return TokError("expected identifier in directive"); + StringRef Name; + if (getParser().parseIdentifier(Name)) + return TokError("expected identifier in directive"); - MCSymbol *Sym = getContext().getOrCreateSymbol(Name); - getStreamer().emitSymbolAttribute(Sym, MCSA_Global); - return false; + MCSymbol *Sym = getContext().getOrCreateSymbol(Name); + getStreamer().emitSymbolAttribute(Sym, MCSA_Global); + return parseEOL(); } -bool MSP430AsmParser::ParseDirective(AsmToken DirectiveID) { +ParseStatus MSP430AsmParser::parseDirective(AsmToken DirectiveID) { StringRef IDVal = DirectiveID.getIdentifier(); - if (IDVal.lower() == ".long") { - ParseLiteralValues(4, DirectiveID.getLoc()); - } else if (IDVal.lower() == ".word" || IDVal.lower() == ".short") { - ParseLiteralValues(2, DirectiveID.getLoc()); - } else if (IDVal.lower() == ".byte") { - ParseLiteralValues(1, DirectiveID.getLoc()); - } else if (IDVal.lower() == ".refsym") { + if (IDVal.lower() == ".long") + return ParseLiteralValues(4, DirectiveID.getLoc()); + if (IDVal.lower() == ".word" || IDVal.lower() == ".short") + return ParseLiteralValues(2, DirectiveID.getLoc()); + if (IDVal.lower() == ".byte") + return ParseLiteralValues(1, DirectiveID.getLoc()); + if (IDVal.lower() == ".refsym") return ParseDirectiveRefSym(DirectiveID); - } - return true; + return ParseStatus::NoMatch; } bool MSP430AsmParser::ParseOperand(OperandVector &Operands) { @@ -474,15 +469,13 @@ bool MSP430AsmParser::ParseOperand(OperandVector &Operands) { MCRegister RegNo = MSP430::PC; SMLoc EndLoc = getParser().getTok().getLoc(); // Try (rN) - if (getLexer().getKind() == AsmToken::LParen) { - getLexer().Lex(); // Eat '(' + if (parseOptionalToken(AsmToken::LParen)) { SMLoc RegStartLoc; if (parseRegister(RegNo, RegStartLoc, EndLoc)) return true; - if (getLexer().getKind() != AsmToken::RParen) - return true; EndLoc = getParser().getTok().getEndLoc(); - getLexer().Lex(); // Eat ')' + if (!parseOptionalToken(AsmToken::RParen)) + return true; } Operands.push_back(MSP430Operand::CreateMem(RegNo, Val, StartLoc, EndLoc)); @@ -511,9 +504,8 @@ bool MSP430AsmParser::ParseOperand(OperandVector &Operands) { SMLoc RegStartLoc, EndLoc; if (parseRegister(RegNo, RegStartLoc, EndLoc)) return true; - if (getLexer().getKind() == AsmToken::Plus) { + if (parseOptionalToken(AsmToken::Plus)) { Operands.push_back(MSP430Operand::CreatePostIndReg(RegNo, StartLoc, EndLoc)); - getLexer().Lex(); // Eat '+' return false; } if (Operands.size() > 1) // Emulate @rd in destination position as 0(rd) |
