summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2014-02-09 23:29:24 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2014-02-09 23:29:24 +0000
commit537dca94b35e651248b57db03c9fece4c40bd5f9 (patch)
treec6559d7f5c823fa0e7a16091177455cb1735bfcd
parenta4122f4746f3d89530f59f84ce21e9eb3bbabb9e (diff)
downloadllvm-537dca94b35e651248b57db03c9fece4c40bd5f9.tar.gz
llvm-537dca94b35e651248b57db03c9fece4c40bd5f9.tar.bz2
llvm-537dca94b35e651248b57db03c9fece4c40bd5f9.tar.xz
MCParser: add a single token lookahead
Some of the more complex directive and macro handling for GAS compatibility requires lookahead. Add a single token lookahead in the MCAsmLexer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201058 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/MC/MCParser/AsmLexer.h2
-rw-r--r--include/llvm/MC/MCParser/MCAsmLexer.h3
-rw-r--r--lib/MC/MCParser/AsmLexer.cpp22
3 files changed, 27 insertions, 0 deletions
diff --git a/include/llvm/MC/MCParser/AsmLexer.h b/include/llvm/MC/MCParser/AsmLexer.h
index 1b3ab57751..89677a91cd 100644
--- a/include/llvm/MC/MCParser/AsmLexer.h
+++ b/include/llvm/MC/MCParser/AsmLexer.h
@@ -47,6 +47,8 @@ public:
virtual StringRef LexUntilEndOfStatement();
StringRef LexUntilEndOfLine();
+ virtual const AsmToken peekTok(bool ShouldSkipSpace = true);
+
bool isAtStartOfComment(char Char);
bool isAtStatementSeparator(const char *Ptr);
diff --git a/include/llvm/MC/MCParser/MCAsmLexer.h b/include/llvm/MC/MCParser/MCAsmLexer.h
index ceba3f05e1..e3d4181e08 100644
--- a/include/llvm/MC/MCParser/MCAsmLexer.h
+++ b/include/llvm/MC/MCParser/MCAsmLexer.h
@@ -160,6 +160,9 @@ public:
return CurTok;
}
+ /// peekTok - Look ahead at the next token to be lexed.
+ virtual const AsmToken peekTok(bool ShouldSkipSpace = true) = 0;
+
/// getErrLoc - Get the current error location
const SMLoc &getErrLoc() {
return ErrLoc;
diff --git a/lib/MC/MCParser/AsmLexer.cpp b/lib/MC/MCParser/AsmLexer.cpp
index 88f1761789..a3b68d8380 100644
--- a/lib/MC/MCParser/AsmLexer.cpp
+++ b/lib/MC/MCParser/AsmLexer.cpp
@@ -439,6 +439,28 @@ StringRef AsmLexer::LexUntilEndOfLine() {
return StringRef(TokStart, CurPtr-TokStart);
}
+const AsmToken AsmLexer::peekTok(bool ShouldSkipSpace) {
+ const char *SavedTokStart = TokStart;
+ const char *SavedCurPtr = CurPtr;
+ bool SavedAtStartOfLine = isAtStartOfLine;
+ bool SavedSkipSpace = SkipSpace;
+
+ std::string SavedErr = getErr();
+ SMLoc SavedErrLoc = getErrLoc();
+
+ SkipSpace = ShouldSkipSpace;
+ AsmToken Token = LexToken();
+
+ SetError(SavedErrLoc, SavedErr);
+
+ SkipSpace = SavedSkipSpace;
+ isAtStartOfLine = SavedAtStartOfLine;
+ CurPtr = SavedCurPtr;
+ TokStart = SavedTokStart;
+
+ return Token;
+}
+
bool AsmLexer::isAtStartOfComment(char Char) {
// FIXME: This won't work for multi-character comment indicators like "//".
return Char == *MAI.getCommentString();