Skip to content

Commit

Permalink
[AsmParser] Provide target direct access to mnemonic token. Allow ass…
Browse files Browse the repository at this point in the history
…ignment parsing to be hooked by target. Allow target to specify if identifier is a label.

Differential Revision:  http://reviews.llvm.org/D14255

llvm-svn: 252435
  • Loading branch information
Colin LeMahieu committed Nov 9, 2015
1 parent 2d7ec5a commit 7820dff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions llvm/include/llvm/MC/MCTargetAsmParser.h
Expand Up @@ -143,6 +143,10 @@ class MCTargetAsmParser : public MCAsmParserExtension {
/// \return True on failure.
virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
SMLoc NameLoc, OperandVector &Operands) = 0;
virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
AsmToken Token, OperandVector &Operands) {
return ParseInstruction(Info, Name, Token.getLoc(), Operands);
}

/// ParseDirective - Parse a target specific assembler directive
///
Expand Down Expand Up @@ -192,6 +196,11 @@ class MCTargetAsmParser : public MCAsmParserExtension {
virtual void convertToMapAndConstraints(unsigned Kind,
const OperandVector &Operands) = 0;

// Return whether this parser uses assignment statements with equals tokens
virtual bool equalIsAsmAssignment() { return true; };
// Return whether this start of statement identifier is a label
virtual bool isLabel(AsmToken &Token) { return true; };

virtual const MCExpr *applyModifierToExpr(const MCExpr *E,
MCSymbolRefExpr::VariantKind,
MCContext &Ctx) {
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/MC/MCParser/AsmParser.cpp
Expand Up @@ -1396,6 +1396,8 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
// See what kind of statement we have.
switch (Lexer.getKind()) {
case AsmToken::Colon: {
if (!getTargetParser().isLabel(ID))
break;
checkForValidSection();

// identifier ':' -> Label.
Expand Down Expand Up @@ -1454,6 +1456,8 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
}

case AsmToken::Equal:
if (!getTargetParser().equalIsAsmAssignment())
break;
// identifier '=' ... -> assignment statement
Lex();

Expand Down Expand Up @@ -1701,7 +1705,7 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
// Canonicalize the opcode to lower case.
std::string OpcodeStr = IDVal.lower();
ParseInstructionInfo IInfo(Info.AsmRewrites);
bool HadError = getTargetParser().ParseInstruction(IInfo, OpcodeStr, IDLoc,
bool HadError = getTargetParser().ParseInstruction(IInfo, OpcodeStr, ID,
Info.ParsedOperands);
Info.ParseError = HadError;

Expand Down

0 comments on commit 7820dff

Please sign in to comment.