[PATCH] D14255: [AsmParser] Provide direct access to mnemonic token. Allow assignment parsing to be hooked by target. Allow target to specify if identifier is a label.

Colin LeMahieu via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 2 12:09:07 PST 2015


colinl created this revision.
colinl added reviewers: sidneym, mcrosier.
colinl added a subscriber: llvm-commits.
colinl set the repository for this revision to rL LLVM.

This allows AsmParsers to directly access the first token of a statement.  This was creating an issue for statements that aren't lead by a token other than an identifier.

This also creates target hooks for checking if an identifier is a label and if AsmParser itself should parse assignment expressions.

"r31:30 = r21:20" is a register assignment.  This trips up the parser because "r31:" looks like a label and an equals sign tells it to parse this as an assignment expression instead of an instruction. 

Repository:
  rL LLVM

http://reviews.llvm.org/D14255

Files:
  include/llvm/MC/MCTargetAsmParser.h
  lib/MC/MCParser/AsmParser.cpp

Index: lib/MC/MCParser/AsmParser.cpp
===================================================================
--- lib/MC/MCParser/AsmParser.cpp
+++ lib/MC/MCParser/AsmParser.cpp
@@ -1396,6 +1396,8 @@
   // See what kind of statement we have.
   switch (Lexer.getKind()) {
   case AsmToken::Colon: {
+    if (!getTargetParser().isLabel(ID))
+      break;
     checkForValidSection();
 
     // identifier ':'   -> Label.
@@ -1454,6 +1456,8 @@
   }
 
   case AsmToken::Equal:
+    if (!getTargetParser().equalIsAsmAssignment())
+      break;
     // identifier '=' ... -> assignment statement
     Lex();
 
@@ -1701,7 +1705,7 @@
   // 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;
 
Index: include/llvm/MC/MCTargetAsmParser.h
===================================================================
--- include/llvm/MC/MCTargetAsmParser.h
+++ include/llvm/MC/MCTargetAsmParser.h
@@ -143,6 +143,10 @@
   /// \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
   ///
@@ -192,6 +196,11 @@
   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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14255.38961.patch
Type: text/x-patch
Size: 2348 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151102/25ff2305/attachment.bin>


More information about the llvm-commits mailing list