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!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245221 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2015-08-17 14:35:25 +00:00
parent df09c6b4bf
commit ac67f04f79
3 changed files with 30 additions and 5 deletions

View File

@ -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);

View File

@ -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() {

View File

@ -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) {