Skip to content

Commit

Permalink
[MC] Lex CRLF as one token
Browse files Browse the repository at this point in the history
This will prevent doubling of line endings when parsing assembly and
emitting assembly.

Otherwise we'd parse the directive, consume the end of statement, hit
the next end of statement, and emit a fresh newline.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315943 91177308-0d34-0410-b5e6-96231b3b80d8
rnk committed Oct 16, 2017
1 parent 7b58f47 commit 983f9af
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/MC/MCParser/AsmLexer.cpp
Original file line number Diff line number Diff line change
@@ -606,8 +606,16 @@ AsmToken AsmLexer::LexToken() {
return LexToken(); // Ignore whitespace.
else
return AsmToken(AsmToken::Space, StringRef(TokStart, CurPtr - TokStart));
case '\r': {
IsAtStartOfLine = true;
IsAtStartOfStatement = true;
// If this is a CR followed by LF, treat that as one token.
if (CurPtr != CurBuf.end() && *CurPtr == '\n')
++CurPtr;
return AsmToken(AsmToken::EndOfStatement,
StringRef(TokStart, CurPtr - TokStart));
}
case '\n':
case '\r':
IsAtStartOfLine = true;
IsAtStartOfStatement = true;
return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1));
5 changes: 5 additions & 0 deletions test/MC/X86/crlf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RUN: printf '\r\n\r\n' | llvm-mc -as-lex | FileCheck %s
There should only be two end of statements.
CHECK: EndOfStatement
CHECK: EndOfStatement
CHECK-NOT: EndOfStatement

0 comments on commit 983f9af

Please sign in to comment.