summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2015-08-17 14:35:25 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2015-08-17 14:35:25 +0000
commit1ee99a8b46839073361f72e4179f1bb9b7aad74d (patch)
tree8f7c267c75ff5caa9850ef1efcee4025f216864b
parentaa3d810b5f95bf8966d8c82535329a499be0528c (diff)
downloadbcm5719-llvm-1ee99a8b46839073361f72e4179f1bb9b7aad74d.tar.gz
bcm5719-llvm-1ee99a8b46839073361f72e4179f1bb9b7aad74d.zip
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! llvm-svn: 245221
-rw-r--r--llvm/include/llvm/MC/MCParser/AsmLexer.h3
-rw-r--r--llvm/include/llvm/MC/MCParser/MCAsmLexer.h16
-rw-r--r--llvm/lib/MC/MCParser/AsmLexer.cpp16
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) {
OpenPOWER on IntegriCloud