[llvm] r245221 - Extend MCAsmLexer so that it can peek forward several tokens
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 17 07:35:25 PDT 2015
Author: d0k
Date: Mon Aug 17 09:35:25 2015
New Revision: 245221
URL: http://llvm.org/viewvc/llvm-project?rev=245221&view=rev
Log:
Extend MCAsmLexer so that it can peek forward several tokens
This commit adds a virtual `peekTokens()` function to `MCAsmLexer`
which can peek forward an arbitrary number of tokens.
It also makes the `peekTok()` method call `peekTokens()` method, but
only requesting one token.
The idea is to better support targets which more more ambiguous
assembly syntaxes.
Patch by Dylan McKay!
Modified:
llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h
llvm/trunk/include/llvm/MC/MCParser/MCAsmLexer.h
llvm/trunk/lib/MC/MCParser/AsmLexer.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=245221&r1=245220&r2=245221&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h Mon Aug 17 09:35:25 2015
@@ -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);
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=245221&r1=245220&r2=245221&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/MCAsmLexer.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/MCAsmLexer.h Mon Aug 17 09:35:25 2015
@@ -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() {
Modified: llvm/trunk/lib/MC/MCParser/AsmLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmLexer.cpp?rev=245221&r1=245220&r2=245221&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmLexer.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmLexer.cpp Mon Aug 17 09:35:25 2015
@@ -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 Sh
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 Sh
CurPtr = SavedCurPtr;
TokStart = SavedTokStart;
- return Token;
+ return ReadCount;
}
bool AsmLexer::isAtStartOfComment(const char *Ptr) {
More information about the llvm-commits
mailing list