[llvm] r272957 - Revert "Refactor and cleanup Assembly Parsing / Lexing"

Nirav Dave via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 16 14:19:23 PDT 2016


Author: niravd
Date: Thu Jun 16 16:19:23 2016
New Revision: 272957

URL: http://llvm.org/viewvc/llvm-project?rev=272957&view=rev
Log:
Revert "Refactor and cleanup Assembly Parsing / Lexing"

Reverting for unexpected crashes on various platforms.

This reverts commit r272953.

Removed:
    llvm/trunk/test/MC/AsmParser/hash-directive.s
Modified:
    llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h
    llvm/trunk/include/llvm/MC/MCParser/MCAsmLexer.h
    llvm/trunk/lib/MC/MCParser/AsmLexer.cpp
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp
    llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
    llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp
    llvm/trunk/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp
    llvm/trunk/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp

Modified: llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h?rev=272957&r1=272956&r2=272957&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h Thu Jun 16 16:19:23 2016
@@ -29,8 +29,7 @@ class AsmLexer : public MCAsmLexer {
 
   const char *CurPtr;
   StringRef CurBuf;
-  bool IsAtStartOfLine;
-  bool IsAtStartOfStatement;
+  bool isAtStartOfLine;
 
   void operator=(const AsmLexer&) = delete;
   AsmLexer(const AsmLexer&) = delete;
@@ -46,15 +45,17 @@ public:
   void setBuffer(StringRef Buf, const char *ptr = nullptr);
 
   StringRef LexUntilEndOfStatement() override;
+  StringRef LexUntilEndOfLine();
 
   size_t peekTokens(MutableArrayRef<AsmToken> Buf,
                     bool ShouldSkipSpace = true) override;
 
+  bool isAtStartOfComment(const char *Ptr);
+  bool isAtStatementSeparator(const char *Ptr);
+
   const MCAsmInfo &getMAI() const { return MAI; }
 
 private:
-  bool isAtStartOfComment(const char *Ptr);
-  bool isAtStatementSeparator(const char *Ptr);
   int getNextChar();
   AsmToken ReturnError(const char *Loc, const std::string &Msg);
 
@@ -66,8 +67,6 @@ private:
   AsmToken LexQuote();
   AsmToken LexFloatLiteral();
   AsmToken LexHexFloatLiteral(bool NoIntDigits);
-
-  StringRef LexUntilEndOfLine();
 };
 
 } // end namespace llvm

Modified: llvm/trunk/include/llvm/MC/MCParser/MCAsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCParser/MCAsmLexer.h?rev=272957&r1=272956&r2=272957&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/MCAsmLexer.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/MCAsmLexer.h Thu Jun 16 16:19:23 2016
@@ -39,15 +39,12 @@ public:
     // Real values.
     Real,
 
-    // Comments
-    Comment,
-    HashDirective,
     // No-value.
     EndOfStatement,
     Colon,
     Space,
     Plus, Minus, Tilde,
-    Slash,     // '/'
+    Slash,    // '/'
     BackSlash, // '\'
     LParen, RParen, LBrac, RBrac, LCurly, RCurly,
     Star, Dot, Comma, Dollar, Equal, EqualEqual,
@@ -156,9 +153,8 @@ public:
   const AsmToken &Lex() {
     assert(!CurTok.empty());
     CurTok.erase(CurTok.begin());
-    // Always place in front as LexToken may generate multiple tokens via UnLex.
     if (CurTok.empty())
-      CurTok.insert(CurTok.begin(), LexToken());
+      CurTok.emplace_back(LexToken());
     return CurTok.front();
   }
 

Modified: llvm/trunk/lib/MC/MCParser/AsmLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmLexer.cpp?rev=272957&r1=272956&r2=272957&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmLexer.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmLexer.cpp Thu Jun 16 16:19:23 2016
@@ -23,8 +23,7 @@ using namespace llvm;
 
 AsmLexer::AsmLexer(const MCAsmInfo &MAI) : MAI(MAI) {
   CurPtr = nullptr;
-  IsAtStartOfLine = true;
-  IsAtStartOfStatement = true;
+  isAtStartOfLine = true;
   AllowAtInIdentifier = !StringRef(MAI.getCommentString()).startswith("@");
 }
 
@@ -51,9 +50,20 @@ AsmToken AsmLexer::ReturnError(const cha
 }
 
 int AsmLexer::getNextChar() {
-  if (CurPtr == CurBuf.end())
+  char CurChar = *CurPtr++;
+  switch (CurChar) {
+  default:
+    return (unsigned char)CurChar;
+  case 0:
+    // A nul character in the stream is either the end of the current buffer or
+    // a random nul in the file.  Disambiguate that here.
+    if (CurPtr - 1 != CurBuf.end())
+      return 0;  // Just whitespace.
+
+    // Otherwise, return end of file.
+    --CurPtr;  // Another call to lex will return EOF again.
     return EOF;
-  return (unsigned char)*CurPtr++;
+  }
 }
 
 /// LexFloatLiteral: [0-9]*[.][0-9]*([eE][+-]?[0-9]*)?
@@ -159,52 +169,43 @@ AsmToken AsmLexer::LexIdentifier() {
 AsmToken AsmLexer::LexSlash() {
   switch (*CurPtr) {
   case '*':
-    IsAtStartOfStatement = false;
     break; // C style comment.
   case '/':
     ++CurPtr;
     return LexLineComment();
   default:
-    IsAtStartOfStatement = false;
-    return AsmToken(AsmToken::Slash, StringRef(TokStart, 1));
+    return AsmToken(AsmToken::Slash, StringRef(CurPtr - 1, 1));
   }
 
   // C Style comment.
   ++CurPtr;  // skip the star.
-  while (CurPtr != CurBuf.end()) {
-    switch (*CurPtr++) {
+  while (1) {
+    int CurChar = getNextChar();
+    switch (CurChar) {
+    case EOF:
+      return ReturnError(TokStart, "unterminated comment");
     case '*':
       // End of the comment?
-      if (*CurPtr != '/')
-        break;
+      if (CurPtr[0] != '/') break;
+
       ++CurPtr;   // End the */.
-      return AsmToken(AsmToken::Comment,
-                      StringRef(TokStart, CurPtr - TokStart));
+      return LexToken();
     }
   }
-  return ReturnError(TokStart, "unterminated comment");
 }
 
 /// LexLineComment: Comment: #[^\n]*
 ///                        : //[^\n]*
 AsmToken AsmLexer::LexLineComment() {
-  // Mark This as an end of statement with a body of the
-  // comment. While it would be nicer to leave this two tokens,
-  // backwards compatability with TargetParsers makes keeping this in this form
-  // better.
+  // FIXME: This is broken if we happen to a comment at the end of a file, which
+  // was .included, and which doesn't end with a newline.
   int CurChar = getNextChar();
   while (CurChar != '\n' && CurChar != '\r' && CurChar != EOF)
     CurChar = getNextChar();
 
-  IsAtStartOfLine = true;
-  // Whis is a whole line comment. leave newline
-  if (IsAtStartOfStatement)
-    return AsmToken(AsmToken::EndOfStatement,
-                    StringRef(TokStart, CurPtr - TokStart));
-  IsAtStartOfStatement = true;
-
-  return AsmToken(AsmToken::EndOfStatement,
-                  StringRef(TokStart, CurPtr - 1 - TokStart));
+  if (CurChar == EOF)
+    return AsmToken(AsmToken::Eof, StringRef(TokStart, 0));
+  return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 0));
 }
 
 static void SkipIgnoredIntegerSuffix(const char *&CurPtr) {
@@ -422,7 +423,8 @@ StringRef AsmLexer::LexUntilEndOfStateme
 
   while (!isAtStartOfComment(CurPtr) &&     // Start of line comment.
          !isAtStatementSeparator(CurPtr) && // End of statement marker.
-         *CurPtr != '\n' && *CurPtr != '\r' && CurPtr != CurBuf.end()) {
+         *CurPtr != '\n' && *CurPtr != '\r' &&
+         (*CurPtr != 0 || CurPtr != CurBuf.end())) {
     ++CurPtr;
   }
   return StringRef(TokStart, CurPtr-TokStart);
@@ -431,7 +433,8 @@ StringRef AsmLexer::LexUntilEndOfStateme
 StringRef AsmLexer::LexUntilEndOfLine() {
   TokStart = CurPtr;
 
-  while (*CurPtr != '\n' && *CurPtr != '\r' && CurPtr != CurBuf.end()) {
+  while (*CurPtr != '\n' && *CurPtr != '\r' &&
+         (*CurPtr != 0 || CurPtr != CurBuf.end())) {
     ++CurPtr;
   }
   return StringRef(TokStart, CurPtr-TokStart);
@@ -441,8 +444,7 @@ size_t AsmLexer::peekTokens(MutableArray
                             bool ShouldSkipSpace) {
   const char *SavedTokStart = TokStart;
   const char *SavedCurPtr = CurPtr;
-  bool SavedAtStartOfLine = IsAtStartOfLine;
-  bool SavedAtStartOfStatement = IsAtStartOfStatement;
+  bool SavedAtStartOfLine = isAtStartOfLine;
   bool SavedSkipSpace = SkipSpace;
 
   std::string SavedErr = getErr();
@@ -463,8 +465,7 @@ size_t AsmLexer::peekTokens(MutableArray
   SetError(SavedErrLoc, SavedErr);
 
   SkipSpace = SavedSkipSpace;
-  IsAtStartOfLine = SavedAtStartOfLine;
-  IsAtStartOfStatement = SavedAtStartOfStatement;
+  isAtStartOfLine = SavedAtStartOfLine;
   CurPtr = SavedCurPtr;
   TokStart = SavedTokStart;
 
@@ -494,45 +495,29 @@ AsmToken AsmLexer::LexToken() {
   // This always consumes at least one character.
   int CurChar = getNextChar();
 
-  if (CurChar == '#' && IsAtStartOfStatement) {
-    // If this starts with a '#', this may be a cpp
-    // hash directive and otherwise a line comment.
-    AsmToken TokenBuf[2];
-    MutableArrayRef<AsmToken> Buf(TokenBuf, 2);
-    size_t num = peekTokens(Buf, true);
-    // There cannot be a space preceeding this
-    if (IsAtStartOfLine && num == 2 && TokenBuf[0].is(AsmToken::Integer) &&
-        TokenBuf[1].is(AsmToken::String)) {
-      CurPtr = TokStart; // reset curPtr;
-      StringRef s = LexUntilEndOfLine();
-      UnLex(TokenBuf[1]);
-      UnLex(TokenBuf[0]);
-      return AsmToken(AsmToken::HashDirective, s);
-    }
+  if (isAtStartOfComment(TokStart)) {
+    // If this comment starts with a '#', then return the Hash token and let
+    // the assembler parser see if it can be parsed as a cpp line filename
+    // comment. We do this only if we are at the start of a line.
+    if (CurChar == '#' && isAtStartOfLine)
+      return AsmToken(AsmToken::Hash, StringRef(TokStart, 1));
+    isAtStartOfLine = true;
     return LexLineComment();
   }
-
-  if (isAtStartOfComment(TokStart))
-    return LexLineComment();
-
   if (isAtStatementSeparator(TokStart)) {
     CurPtr += strlen(MAI.getSeparatorString()) - 1;
-    IsAtStartOfLine = true;
-    IsAtStartOfStatement = true;
     return AsmToken(AsmToken::EndOfStatement,
                     StringRef(TokStart, strlen(MAI.getSeparatorString())));
   }
 
   // If we're missing a newline at EOF, make sure we still get an
   // EndOfStatement token before the Eof token.
-  if (CurChar == EOF && !IsAtStartOfStatement) {
-    IsAtStartOfLine = true;
-    IsAtStartOfStatement = true;
+  if (CurChar == EOF && !isAtStartOfLine) {
+    isAtStartOfLine = true;
     return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1));
   }
-  IsAtStartOfLine = false;
-  bool OldIsAtStartOfStatement = IsAtStartOfStatement;
-  IsAtStartOfStatement = false;
+
+  isAtStartOfLine = false;
   switch (CurChar) {
   default:
     // Handle identifier: [a-zA-Z_.][a-zA-Z0-9_$.@]*
@@ -541,24 +526,24 @@ AsmToken AsmLexer::LexToken() {
 
     // Unknown character, emit an error.
     return ReturnError(TokStart, "invalid character in input");
-  case EOF:
-    IsAtStartOfLine = true;
-    IsAtStartOfStatement = true;
-    return AsmToken(AsmToken::Eof, StringRef(TokStart, 0));
+  case EOF: return AsmToken(AsmToken::Eof, StringRef(TokStart, 0));
   case 0:
   case ' ':
   case '\t':
-    IsAtStartOfStatement = OldIsAtStartOfStatement;
-    while (*CurPtr == ' ' || *CurPtr == '\t')
-      CurPtr++;
-    if (SkipSpace)
-      return LexToken(); // Ignore whitespace.
-    else
-      return AsmToken(AsmToken::Space, StringRef(TokStart, CurPtr - TokStart));
-  case '\n':
+    if (SkipSpace) {
+      // Ignore whitespace.
+      return LexToken();
+    } else {
+      int len = 1;
+      while (*CurPtr==' ' || *CurPtr=='\t') {
+        CurPtr++;
+        len++;
+      }
+      return AsmToken(AsmToken::Space, StringRef(TokStart, len));
+    }
+  case '\n': // FALL THROUGH.
   case '\r':
-    IsAtStartOfLine = true;
-    IsAtStartOfStatement = true;
+    isAtStartOfLine = true;
     return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1));
   case ':': return AsmToken(AsmToken::Colon, StringRef(TokStart, 1));
   case '+': return AsmToken(AsmToken::Plus, StringRef(TokStart, 1));
@@ -601,9 +586,7 @@ AsmToken AsmLexer::LexToken() {
     }
     return AsmToken(AsmToken::Exclaim, StringRef(TokStart, 1));
   case '%': return AsmToken(AsmToken::Percent, StringRef(TokStart, 1));
-  case '/':
-    IsAtStartOfStatement = OldIsAtStartOfStatement;
-    return LexSlash();
+  case '/': return LexSlash();
   case '#': return AsmToken(AsmToken::Hash, StringRef(TokStart, 1));
   case '\'': return LexSingleQuote();
   case '"': return LexQuote();

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=272957&r1=272956&r2=272957&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Thu Jun 16 16:19:23 2016
@@ -257,6 +257,7 @@ private:
   bool parseStatement(ParseStatementInfo &Info,
                       MCAsmParserSemaCallback *SI);
   bool parseCurlyBlockScope(SmallVectorImpl<AsmRewrite>& AsmStrRewrites);
+  void eatToEndOfLine();
   bool parseCppHashLineFilenameComment(SMLoc L);
 
   void checkForBadMacro(SMLoc DirectiveLoc, StringRef Name, StringRef Body,
@@ -627,10 +628,6 @@ const AsmToken &AsmParser::Lex() {
     Error(Lexer.getErrLoc(), Lexer.getErr());
 
   const AsmToken *tok = &Lexer.Lex();
-  // Drop comments here.
-  while (tok->is(AsmToken::Comment)) {
-    tok = &Lexer.Lex();
-  }
 
   if (tok->is(AsmToken::Eof)) {
     // If this is the end of an included file, pop the parent file off the
@@ -638,7 +635,7 @@ const AsmToken &AsmParser::Lex() {
     SMLoc ParentIncludeLoc = SrcMgr.getParentIncludeLoc(CurBuffer);
     if (ParentIncludeLoc != SMLoc()) {
       jumpToLoc(ParentIncludeLoc);
-      return Lex();
+      tok = &Lexer.Lex();
     }
   }
 
@@ -723,8 +720,8 @@ bool AsmParser::Run(bool NoInitialTextSe
           // first referenced for a source location. We need to add something
           // to track that. Currently, we just point to the end of the file.
           HadError |=
-              Error(getTok().getLoc(), "assembler local symbol '" +
-                                           Sym->getName() + "' not defined");
+              Error(getLexer().getLoc(), "assembler local symbol '" +
+                                             Sym->getName() + "' not defined");
       }
     }
 
@@ -769,7 +766,7 @@ StringRef AsmParser::parseStringToEndOfS
   const char *Start = getTok().getLoc().getPointer();
 
   while (Lexer.isNot(AsmToken::EndOfStatement) && Lexer.isNot(AsmToken::Eof))
-    Lexer.Lex();
+    Lex();
 
   const char *End = getTok().getLoc().getPointer();
   return StringRef(Start, End - Start);
@@ -780,7 +777,7 @@ StringRef AsmParser::parseStringToComma(
 
   while (Lexer.isNot(AsmToken::EndOfStatement) &&
          Lexer.isNot(AsmToken::Comma) && Lexer.isNot(AsmToken::Eof))
-    Lexer.Lex();
+    Lex();
 
   const char *End = getTok().getLoc().getPointer();
   return StringRef(Start, End - Start);
@@ -862,7 +859,7 @@ bool AsmParser::parsePrimaryExpr(const M
     if (!MAI.useParensForSymbolVariant()) {
       if (FirstTokenKind == AsmToken::String) {
         if (Lexer.is(AsmToken::At)) {
-          Lex(); // eat @
+          Lexer.Lex(); // eat @
           SMLoc AtLoc = getLexer().getLoc();
           StringRef VName;
           if (parseIdentifier(VName))
@@ -874,14 +871,14 @@ bool AsmParser::parsePrimaryExpr(const M
         Split = Identifier.split('@');
       }
     } else if (Lexer.is(AsmToken::LParen)) {
-      Lex(); // eat '('.
+      Lexer.Lex(); // eat (
       StringRef VName;
       parseIdentifier(VName);
       if (Lexer.isNot(AsmToken::RParen)) {
           return Error(Lexer.getTok().getLoc(),
                        "unexpected token in variant, expected ')'");
       }
-      Lex(); // eat ')'.
+      Lexer.Lex(); // eat )
       Split = std::make_pair(Identifier, VName);
     }
 
@@ -1346,24 +1343,21 @@ bool AsmParser::parseBinOpRHS(unsigned P
 ///   ::= Label* Identifier OperandList* EndOfStatement
 bool AsmParser::parseStatement(ParseStatementInfo &Info,
                                MCAsmParserSemaCallback *SI) {
-  // Eat initial spaces and comments
-  while (Lexer.is(AsmToken::Space))
-    Lex();
   if (Lexer.is(AsmToken::EndOfStatement)) {
-    // if this is a line comment we can drop it safely
-    if (getTok().getString().front() == '\r' ||
-        getTok().getString().front() == '\n')
-      Out.AddBlankLine();
+    Out.AddBlankLine();
     Lex();
     return false;
   }
-  // Statements always start with an identifier.
+
+  // Statements always start with an identifier or are a full line comment.
   AsmToken ID = getTok();
   SMLoc IDLoc = ID.getLoc();
   StringRef IDVal;
   int64_t LocalLabelVal = -1;
-  if (Lexer.is(AsmToken::HashDirective))
+  // A full line comment is a '#' as the first token.
+  if (Lexer.is(AsmToken::Hash))
     return parseCppHashLineFilenameComment(IDLoc);
+
   // Allow an integer followed by a ':' as a directional local label.
   if (Lexer.is(AsmToken::Integer)) {
     LocalLabelVal = getTok().getIntVal();
@@ -1654,8 +1648,7 @@ bool AsmParser::parseStatement(ParseStat
       return parseDirectiveIncbin();
     case DK_CODE16:
     case DK_CODE16GCC:
-      return TokError(Twine(IDVal) +
-                      " not currently supported for this target");
+      return TokError(Twine(IDVal) + " not supported yet");
     case DK_REPT:
       return parseDirectiveRept(IDLoc, IDVal);
     case DK_IRP:
@@ -1875,20 +1868,37 @@ AsmParser::parseCurlyBlockScope(SmallVec
   return true;
 }
 
+/// eatToEndOfLine uses the Lexer to eat the characters to the end of the line
+/// since they may not be able to be tokenized to get to the end of line token.
+void AsmParser::eatToEndOfLine() {
+  if (!Lexer.is(AsmToken::EndOfStatement))
+    Lexer.LexUntilEndOfLine();
+  // Eat EOL.
+  Lex();
+}
+
 /// parseCppHashLineFilenameComment as this:
 ///   ::= # number "filename"
+/// or just as a full line comment if it doesn't have a number and a string.
 bool AsmParser::parseCppHashLineFilenameComment(SMLoc L) {
   Lex(); // Eat the hash token.
-  // Lexer only ever emits HashDirective if it fully formed if it's
-  // done the checking already so this is an internal error.
-  assert(getTok().is(AsmToken::Integer) &&
-         "Lexing Cpp line comment: Expected Integer");
+
+  if (getLexer().isNot(AsmToken::Integer)) {
+    // Consume the line since in cases it is not a well-formed line directive,
+    // as if were simply a full line comment.
+    eatToEndOfLine();
+    return false;
+  }
+
   int64_t LineNumber = getTok().getIntVal();
   Lex();
-  assert(getTok().is(AsmToken::String) &&
-         "Lexing Cpp line comment: Expected String");
+
+  if (getLexer().isNot(AsmToken::String)) {
+    eatToEndOfLine();
+    return false;
+  }
+
   StringRef Filename = getTok().getString();
-  Lex();
   // Get rid of the enclosing quotes.
   Filename = Filename.substr(1, Filename.size() - 2);
 
@@ -1897,6 +1907,9 @@ bool AsmParser::parseCppHashLineFilename
   CppHashInfo.Filename = Filename;
   CppHashInfo.LineNumber = LineNumber;
   CppHashInfo.Buf = CurBuffer;
+
+  // Ignore any trailing characters, they're just comment.
+  eatToEndOfLine();
   return false;
 }
 
@@ -2255,7 +2268,7 @@ bool AsmParser::parseMacroArguments(cons
           break;
 
       if (FAI >= NParameters) {
-        assert(M && "expected macro to be defined");
+    assert(M && "expected macro to be defined");
         Error(IDLoc,
               "parameter named '" + FA.Name + "' does not exist for macro '" +
               M->Name + "'");
@@ -2413,7 +2426,7 @@ bool AsmParser::parseIdentifier(StringRe
     // Construct the joined identifier and consume the token.
     Res =
         StringRef(PrefixLoc.getPointer(), getTok().getIdentifier().size() + 1);
-    Lex(); // Parser Lex to maintain invariants.
+    Lexer.Lex(); // Lexer's Lex guarantees consecutive token
     return false;
   }
 
@@ -2555,16 +2568,16 @@ bool AsmParser::parseDirectiveReloc(SMLo
 
   if (Lexer.isNot(AsmToken::Comma))
     return TokError("expected comma");
-  Lex();
+  Lexer.Lex();
 
   if (Lexer.isNot(AsmToken::Identifier))
     return TokError("expected relocation name");
   SMLoc NameLoc = Lexer.getTok().getLoc();
   StringRef Name = Lexer.getTok().getIdentifier();
-  Lex();
+  Lexer.Lex();
 
   if (Lexer.is(AsmToken::Comma)) {
-    Lex();
+    Lexer.Lex();
     SMLoc ExprLoc = Lexer.getLoc();
     if (parseExpression(Expr))
       return true;
@@ -5237,9 +5250,10 @@ static bool isSymbolUsedInExpression(con
 bool parseAssignmentExpression(StringRef Name, bool allow_redef,
                                MCAsmParser &Parser, MCSymbol *&Sym,
                                const MCExpr *&Value) {
+  MCAsmLexer &Lexer = Parser.getLexer();
 
   // FIXME: Use better location, we should use proper tokens.
-  SMLoc EqualLoc = Parser.getTok().getLoc();
+  SMLoc EqualLoc = Lexer.getLoc();
 
   if (Parser.parseExpression(Value)) {
     Parser.TokError("missing expression");
@@ -5251,7 +5265,7 @@ bool parseAssignmentExpression(StringRef
   // a = b
   // b = c
 
-  if (Parser.getTok().isNot(AsmToken::EndOfStatement))
+  if (Lexer.isNot(AsmToken::EndOfStatement))
     return Parser.TokError("unexpected token in assignment");
 
   // Eat the end of statement marker.

Modified: llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=272957&r1=272956&r2=272957&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp Thu Jun 16 16:19:23 2016
@@ -10072,7 +10072,7 @@ bool ARMAsmParser::parseDirectiveObjectA
 
   StringRef Arch = Parser.getTok().getString();
   SMLoc ArchLoc = Parser.getTok().getLoc();
-  Lex();
+  getLexer().Lex();
 
   unsigned ID = ARM::parseArch(Arch);
 
@@ -10195,7 +10195,7 @@ bool ARMAsmParser::parseDirectiveArchExt
 
   StringRef Name = Parser.getTok().getString();
   SMLoc ExtLoc = Parser.getTok().getLoc();
-  Lex();
+  getLexer().Lex();
 
   bool EnableFeature = true;
   if (Name.startswith_lower("no")) {

Modified: llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp?rev=272957&r1=272956&r2=272957&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp Thu Jun 16 16:19:23 2016
@@ -729,10 +729,11 @@ bool HexagonAsmParser::finishBundle(SMLo
 
 bool HexagonAsmParser::matchBundleOptions() {
   MCAsmParser &Parser = getParser();
+  MCAsmLexer &Lexer = getLexer();
   while (true) {
     if (!Parser.getTok().is(AsmToken::Colon))
       return false;
-    Lex();
+    Lexer.Lex();
     StringRef Option = Parser.getTok().getString();
     if (Option.compare_lower("endloop0") == 0)
       HexagonMCInstrInfo::setInnerLoop(MCB);
@@ -744,7 +745,7 @@ bool HexagonAsmParser::matchBundleOption
       HexagonMCInstrInfo::setMemStoreReorderEnabled(MCB);
     else
       return true;
-    Lex();
+    Lexer.Lex();
   }
 }
 
@@ -1104,7 +1105,7 @@ bool HexagonAsmParser::splitIdentifier(O
   AsmToken const &Token = getParser().getTok();
   StringRef String = Token.getString();
   SMLoc Loc = Token.getLoc();
-  Lex();
+  getLexer().Lex();
   do {
     std::pair<StringRef, StringRef> HeadTail = String.split('.');
     if (!HeadTail.first.empty())
@@ -1296,7 +1297,7 @@ bool HexagonAsmParser::parseExpression(M
   static char const * Comma = ",";
   do {
     Tokens.emplace_back (Lexer.getTok());
-    Lex();
+    Lexer.Lex();
     switch (Tokens.back().getKind())
     {
     case AsmToken::TokenKind::Hash:
@@ -1345,7 +1346,7 @@ bool HexagonAsmParser::parseInstruction(
     AsmToken const &Token = Parser.getTok();
     switch (Token.getKind()) {
     case AsmToken::EndOfStatement: {
-      Lex();
+      Lexer.Lex();
       return false;
     }
     case AsmToken::LCurly: {
@@ -1353,19 +1354,19 @@ bool HexagonAsmParser::parseInstruction(
         return true;
       Operands.push_back(
           HexagonOperand::CreateToken(Token.getString(), Token.getLoc()));
-      Lex();
+      Lexer.Lex();
       return false;
     }
     case AsmToken::RCurly: {
       if (Operands.empty()) {
         Operands.push_back(
             HexagonOperand::CreateToken(Token.getString(), Token.getLoc()));
-        Lex();
+        Lexer.Lex();
       }
       return false;
     }
     case AsmToken::Comma: {
-      Lex();
+      Lexer.Lex();
       continue;
     }
     case AsmToken::EqualEqual:
@@ -1378,7 +1379,7 @@ bool HexagonAsmParser::parseInstruction(
           Token.getString().substr(0, 1), Token.getLoc()));
       Operands.push_back(HexagonOperand::CreateToken(
           Token.getString().substr(1, 1), Token.getLoc()));
-      Lex();
+      Lexer.Lex();
       continue;
     }
     case AsmToken::Hash: {
@@ -1388,12 +1389,12 @@ bool HexagonAsmParser::parseInstruction(
       if (!ImplicitExpression)
         Operands.push_back(
           HexagonOperand::CreateToken(Token.getString(), Token.getLoc()));
-      Lex();
+      Lexer.Lex();
       bool MustExtend = false;
       bool HiOnly = false;
       bool LoOnly = false;
       if (Lexer.is(AsmToken::Hash)) {
-        Lex();
+        Lexer.Lex();
         MustExtend = true;
       } else if (ImplicitExpression)
         MustNotExtend = true;
@@ -1411,7 +1412,7 @@ bool HexagonAsmParser::parseInstruction(
             HiOnly = false;
             LoOnly = false;
           } else {
-            Lex();
+            Lexer.Lex();
           }
         }
       }

Modified: llvm/trunk/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp?rev=272957&r1=272956&r2=272957&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp Thu Jun 16 16:19:23 2016
@@ -1122,7 +1122,7 @@ bool LanaiAsmParser::ParseInstruction(Pa
   // Parse until end of statement, consuming commas between operands
   while (Lexer.isNot(AsmToken::EndOfStatement) && Lexer.is(AsmToken::Comma)) {
     // Consume comma token
-    Lex();
+    Lexer.Lex();
 
     // Parse next operand
     if (parseOperand(&Operands, Mnemonic) != MatchOperand_Success)

Modified: llvm/trunk/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp?rev=272957&r1=272956&r2=272957&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp Thu Jun 16 16:19:23 2016
@@ -1710,7 +1710,7 @@ bool PPCAsmParser::ParseInstruction(Pars
   while (getLexer().isNot(AsmToken::EndOfStatement) &&
          getLexer().is(AsmToken::Comma)) {
     // Consume the comma token
-    Lex();
+    getLexer().Lex();
 
     // Parse the next operand
     if (ParseOperand(Operands))

Removed: llvm/trunk/test/MC/AsmParser/hash-directive.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/hash-directive.s?rev=272956&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/hash-directive.s (original)
+++ llvm/trunk/test/MC/AsmParser/hash-directive.s (removed)
@@ -1,23 +0,0 @@
-# RUN: not llvm-mc -triple i386-unknown-unknown %s 2>&1 | FileCheck %s
-error
-# CHECK: hash-directive.s:[[@LINE-1]]:1: error
-# 3 "FILE1" 1 #<- This is a CPP Hash w/ comment
-error
-# CHECK: FILE1:3:1: error
-# 0 "" 2 #<- This is too
-error
-# CHECK: hash-directive.s:[[@LINE-1]]:1: error
- # 1 "FILE2" 2 #<- This is a comment
-error
-# CHECK: hash-directive.s:[[@LINE-1]]:1: error
-nop; # 6 "FILE3" 2 #<- This is a still comment
-error
-# CHECK: hash-directive.s:[[@LINE-1]]:1: error
-nop;# 6 "FILE4" 2
-  nop;
-error
-# CHECK: FILE4:7:1: error
-# 0 "" 2
-/*comment*/# 6 "FILE5" 2 #<- This is a comment
-error
-# CHECK: hash-directive.s:[[@LINE-1]]:1: error




More information about the llvm-commits mailing list