diff options
-rw-r--r-- | llvm/include/llvm/MC/MCParser/AsmLexer.h | 3 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCParser/MCAsmLexer.h | 16 | ||||
-rw-r--r-- | llvm/lib/MC/MCParser/AsmLexer.cpp | 16 |
3 files changed, 30 insertions, 5 deletions
diff --git a/llvm/include/llvm/MC/MCParser/AsmLexer.h b/llvm/include/llvm/MC/MCParser/AsmLexer.h index 62d39b26c86..1bb6d212784 100644 --- a/llvm/include/llvm/MC/MCParser/AsmLexer.h +++ b/llvm/include/llvm/MC/MCParser/AsmLexer.h @@ -47,7 +47,8 @@ public: StringRef LexUntilEndOfStatement() override; StringRef LexUntilEndOfLine(); - const AsmToken peekTok(bool ShouldSkipSpace = true) override; + size_t peekTokens(MutableArrayRef<AsmToken> Buf, + bool ShouldSkipSpace = true) override; bool isAtStartOfComment(const char *Ptr); bool isAtStatementSeparator(const char *Ptr); diff --git a/llvm/include/llvm/MC/MCParser/MCAsmLexer.h b/llvm/include/llvm/MC/MCParser/MCAsmLexer.h index 71f15b37c33..644dbd90997 100644 --- a/llvm/include/llvm/MC/MCParser/MCAsmLexer.h +++ b/llvm/include/llvm/MC/MCParser/MCAsmLexer.h @@ -162,7 +162,21 @@ public: } /// Look ahead at the next token to be lexed. - virtual const AsmToken peekTok(bool ShouldSkipSpace = true) = 0; + const AsmToken peekTok(bool ShouldSkipSpace = true) { + AsmToken Tok; + + MutableArrayRef<AsmToken> Buf(Tok); + size_t ReadCount = peekTokens(Buf, ShouldSkipSpace); + + assert(ReadCount == 1); + (void)ReadCount; + + return Tok; + } + + /// Look ahead an arbitrary number of tokens. + virtual size_t peekTokens(MutableArrayRef<AsmToken> Buf, + bool ShouldSkipSpace = true) = 0; /// Get the current error location const SMLoc &getErrLoc() { diff --git a/llvm/lib/MC/MCParser/AsmLexer.cpp b/llvm/lib/MC/MCParser/AsmLexer.cpp index b983d9995f4..36c19202685 100644 --- a/llvm/lib/MC/MCParser/AsmLexer.cpp +++ b/llvm/lib/MC/MCParser/AsmLexer.cpp @@ -436,7 +436,8 @@ StringRef AsmLexer::LexUntilEndOfLine() { return StringRef(TokStart, CurPtr-TokStart); } -const AsmToken AsmLexer::peekTok(bool ShouldSkipSpace) { +size_t AsmLexer::peekTokens(MutableArrayRef<AsmToken> Buf, + bool ShouldSkipSpace) { const char *SavedTokStart = TokStart; const char *SavedCurPtr = CurPtr; bool SavedAtStartOfLine = isAtStartOfLine; @@ -446,7 +447,16 @@ const AsmToken AsmLexer::peekTok(bool ShouldSkipSpace) { SMLoc SavedErrLoc = getErrLoc(); SkipSpace = ShouldSkipSpace; - AsmToken Token = LexToken(); + + size_t ReadCount; + for (ReadCount = 0; ReadCount < Buf.size(); ++ReadCount) { + AsmToken Token = LexToken(); + + Buf[ReadCount] = Token; + + if (Token.is(AsmToken::Eof)) + break; + } SetError(SavedErrLoc, SavedErr); @@ -455,7 +465,7 @@ const AsmToken AsmLexer::peekTok(bool ShouldSkipSpace) { CurPtr = SavedCurPtr; TokStart = SavedTokStart; - return Token; + return ReadCount; } bool AsmLexer::isAtStartOfComment(const char *Ptr) { |