<div dir="ltr">I fixed everything you mentioned Benjamin - thanks for the review!<div><br></div><div>Attached is the new patch.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Aug 16, 2015 at 10:57 PM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@gmail.com" target="_blank">benny.kra@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> On 15.08.2015, at 16:23, Dylan McKay via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
><br>
> From b7094fa637ffd59b10776e0a4bbf7f8c04235306 Mon Sep 17 00:00:00 2001<br>
> From: Dylan McKay <<a href="mailto:dylanmckay34@gmail.com">dylanmckay34@gmail.com</a>><br>
> Date: Sun, 16 Aug 2015 02:09:05 +1200<br>
> Subject: [PATCH] Extend MCAsmLexer so that it can peek forward several tokens<br>
><br>
> This commit adds a virtual `peekTokens()` function to `MCAsmLexer`<br>
> which can peek forward an arbitrary number of tokens.<br>
><br>
> It also makes the `peekTok()` method call `peekTokens()` method, but<br>
> only requesting one token.<br>
><br>
> The idea is to better support targets which more more ambiguous<br>
> assembly syntaxes.<br>
> ---<br>
> include/llvm/MC/MCParser/AsmLexer.h | 3 ++-<br>
> include/llvm/MC/MCParser/MCAsmLexer.h | 13 ++++++++++++-<br>
> lib/MC/MCParser/AsmLexer.cpp | 16 +++++++++++++---<br>
> 3 files changed, 27 insertions(+), 5 deletions(-)<br>
><br>
> diff --git a/include/llvm/MC/MCParser/AsmLexer.h b/include/llvm/MC/MCParser/AsmLexer.h<br>
> index 62d39b2..77023e4 100644<br>
> --- a/include/llvm/MC/MCParser/AsmLexer.h<br>
> +++ b/include/llvm/MC/MCParser/AsmLexer.h<br>
> @@ -47,7 +47,8 @@ public:<br>
> StringRef LexUntilEndOfStatement() override;<br>
> StringRef LexUntilEndOfLine();<br>
><br>
> - const AsmToken peekTok(bool ShouldSkipSpace = true) override;<br>
> + size_t peekTokens(AsmToken *Buf, size_t Size,<br>
> + bool ShouldSkipSpace = true) override;<br>
<br>
This could be a MutableArrayRef<AsmToken> instead of a pointer+size pair.<br>
<br>
><br>
> bool isAtStartOfComment(const char *Ptr);<br>
> bool isAtStatementSeparator(const char *Ptr);<br>
> diff --git a/include/llvm/MC/MCParser/MCAsmLexer.h b/include/llvm/MC/MCParser/MCAsmLexer.h<br>
> index 71f15b3..fb9d32d 100644<br>
> --- a/include/llvm/MC/MCParser/MCAsmLexer.h<br>
> +++ b/include/llvm/MC/MCParser/MCAsmLexer.h<br>
> @@ -162,7 +162,18 @@ public:<br>
> }<br>
><br>
> /// Look ahead at the next token to be lexed.<br>
> - virtual const AsmToken peekTok(bool ShouldSkipSpace = true) = 0;<br>
> + const AsmToken peekTok(bool ShouldSkipSpace = true) {<br>
> + AsmToken Buf;<br>
> +<br>
> + size_t ReadCount = peekTokens(&Buf, 1, ShouldSkipSpace);<br>
> + assert(ReadCount == 1);<br>
<br>
Add (void)ReadCount; here to avoid unused variable warnings when assertions are disabled.<br>
<br>
> +<br>
> + return Buf;<br>
> + }<br>
> +<br>
> + /// Look ahead an arbitrary number of tokens.<br>
> + virtual size_t peekTokens(AsmToken *Buf, size_t Size,<br>
> + bool ShouldSkipSpace = true) = 0;<br>
><br>
> /// Get the current error location<br>
> const SMLoc &getErrLoc() {<br>
> diff --git a/lib/MC/MCParser/AsmLexer.cpp b/lib/MC/MCParser/AsmLexer.cpp<br>
> index b983d99..fcedb42 100644<br>
> --- a/lib/MC/MCParser/AsmLexer.cpp<br>
> +++ b/lib/MC/MCParser/AsmLexer.cpp<br>
> @@ -436,7 +436,8 @@ StringRef AsmLexer::LexUntilEndOfLine() {<br>
> return StringRef(TokStart, CurPtr-TokStart);<br>
> }<br>
><br>
> -const AsmToken AsmLexer::peekTok(bool ShouldSkipSpace) {<br>
> +size_t AsmLexer::peekTokens(AsmToken *Buf, size_t Size,<br>
> + bool ShouldSkipSpace) {<br>
> const char *SavedTokStart = TokStart;<br>
> const char *SavedCurPtr = CurPtr;<br>
> bool SavedAtStartOfLine = isAtStartOfLine;<br>
> @@ -446,8 +447,17 @@ const AsmToken AsmLexer::peekTok(bool ShouldSkipSpace) {<br>
> SMLoc SavedErrLoc = getErrLoc();<br>
><br>
> SkipSpace = ShouldSkipSpace;<br>
> - AsmToken Token = LexToken();<br>
><br>
> + size_t ReadCount;<br>
> + for(ReadCount = 0; ReadCount<Size; ++ReadCount) {<br>
> + AsmToken Token = LexToken();<br>
> +<br>
> + Buf[ReadCount] = Token;<br>
> +<br>
> + if(Token.is(AsmToken::Eof))<br>
> + break;<br>
> +<br>
> + }<br>
<br>
This hunk has funky identation. clang-format?<br>
<br>
Patch looks good when my comments are fixed.<br>
<br>
- Ben<br>
<br>
> SetError(SavedErrLoc, SavedErr);<br>
><br>
> SkipSpace = SavedSkipSpace;<br>
> @@ -455,7 +465,7 @@ const AsmToken AsmLexer::peekTok(bool ShouldSkipSpace) {<br>
> CurPtr = SavedCurPtr;<br>
> TokStart = SavedTokStart;<br>
><br>
> - return Token;<br>
> + return ReadCount;<br>
> }<br>
><br>
> bool AsmLexer::isAtStartOfComment(const char *Ptr) {<br>
<span class="HOEnZb"><font color="#888888">> --<br>
> 2.4.4<br>
><br>
<br>
</font></span></blockquote></div><br></div>