[llvm] ddd48cd - [ms] [llvm-ml] Add support for line continuations in MASM

Eric Astor via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 2 09:12:21 PDT 2020


Author: Eric Astor
Date: 2020-09-02T12:12:04-04:00
New Revision: ddd48cdba690fdeefc6ad02a912b63bdb66401b4

URL: https://github.com/llvm/llvm-project/commit/ddd48cdba690fdeefc6ad02a912b63bdb66401b4
DIFF: https://github.com/llvm/llvm-project/commit/ddd48cdba690fdeefc6ad02a912b63bdb66401b4.diff

LOG: [ms] [llvm-ml] Add support for line continuations in MASM

Add support for line continuations (the "backslash operator") in MASM by modifying the Parser's Lex method.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D83347

Added: 
    llvm/test/tools/llvm-ml/line_continuations.test

Modified: 
    llvm/lib/MC/MCParser/MasmParser.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp
index fb7aaae295df..45165ffe3cac 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -1094,6 +1094,14 @@ const AsmToken &MasmParser::Lex() {
     tok = &Lexer.Lex();
   }
 
+  // Recognize and bypass line continuations.
+  while (tok->is(AsmToken::BackSlash) &&
+         Lexer.peekTok().is(AsmToken::EndOfStatement)) {
+    // Eat both the backslash and the end of statement.
+    Lexer.Lex();
+    tok = &Lexer.Lex();
+  }
+
   if (tok->is(AsmToken::Eof)) {
     // If this is the end of an included file, pop the parent file off the
     // include stack.

diff  --git a/llvm/test/tools/llvm-ml/line_continuations.test b/llvm/test/tools/llvm-ml/line_continuations.test
new file mode 100644
index 000000000000..604bbe91b32a
--- /dev/null
+++ b/llvm/test/tools/llvm-ml/line_continuations.test
@@ -0,0 +1,17 @@
+# RUN: llvm-ml -filetype=asm %s | FileCheck %s
+
+.code
+
+t1:
+mov eax, \
+    ebx
+# CHECK: t1:
+# CHECK-NEXT: mov eax, ebx
+
+t2:
+mov eax, [ebx + \
+          1]
+# CHECK: t2:
+# CHECK-NEXT: mov eax, dword ptr [ebx + 1]
+
+END


        


More information about the llvm-commits mailing list