[llvm-branch-commits] [llvm] 1e41e22 - [ms] [llvm-ml] Support purging macro definitions

Eric Astor via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Nov 23 12:07:50 PST 2020


Author: Eric Astor
Date: 2020-11-23T15:03:13-05:00
New Revision: 1e41e22323a33d7b7977e48ff6ec243e46860257

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

LOG: [ms] [llvm-ml] Support purging macro definitions

Support MASM's PURGE directive.

Reviewed By: thakis

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

Added: 
    

Modified: 
    llvm/lib/MC/MCParser/COFFMasmParser.cpp
    llvm/lib/MC/MCParser/MasmParser.cpp
    llvm/test/tools/llvm-ml/macro.test

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCParser/COFFMasmParser.cpp b/llvm/lib/MC/MCParser/COFFMasmParser.cpp
index 61d69ee4e7e8..aacce928c141 100644
--- a/llvm/lib/MC/MCParser/COFFMasmParser.cpp
+++ b/llvm/lib/MC/MCParser/COFFMasmParser.cpp
@@ -118,9 +118,7 @@ class COFFMasmParser : public MCAsmParserExtension {
     addDirectiveHandler<&COFFMasmParser::IgnoreDirective>("title");
 
     // Macro directives
-    // exitm
     // goto
-    // purge
 
     // Miscellaneous directives
     addDirectiveHandler<&COFFMasmParser::ParseDirectiveAlias>("alias");
@@ -153,9 +151,6 @@ class COFFMasmParser : public MCAsmParserExtension {
     addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(".mmx");
     addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(".xmm");
 
-    // Repeat blocks directives
-    // goto
-
     // Scope directives
     // comm
     // externdef

diff  --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp
index d717cadf4e4a..9b63148c6860 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -734,7 +734,7 @@ class MasmParser : public MCAsmParser {
     DK_MACRO,
     DK_EXITM,
     DK_ENDM,
-    DK_PURGEM,
+    DK_PURGE,
     DK_ERR,
     DK_ERRB,
     DK_ERRNB,
@@ -2311,7 +2311,7 @@ bool MasmParser::parseStatement(ParseStatementInfo &Info,
     case DK_ENDM:
       Info.ExitValue = "";
       return parseDirectiveEndMacro(IDVal);
-    case DK_PURGEM:
+    case DK_PURGE:
       return parseDirectivePurgeMacro(IDLoc);
     case DK_END:
       return parseDirectiveEnd(IDLoc);
@@ -5544,23 +5544,27 @@ bool MasmParser::parseDirectiveEndMacro(StringRef Directive) {
 }
 
 /// parseDirectivePurgeMacro
-/// ::= .purgem
+/// ::= purge identifier ( , identifier )*
 bool MasmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
   StringRef Name;
-  SMLoc Loc;
-  if (parseTokenLoc(Loc) ||
-      check(parseIdentifier(Name), Loc,
-            "expected identifier in '.purgem' directive") ||
-      parseToken(AsmToken::EndOfStatement,
-                 "unexpected token in '.purgem' directive"))
-    return true;
+  while (true) {
+    SMLoc NameLoc;
+    if (parseTokenLoc(NameLoc) ||
+        check(parseIdentifier(Name), NameLoc,
+              "expected identifier in 'purge' directive"))
+      return true;
 
-  if (!getContext().lookupMacro(Name))
-    return Error(DirectiveLoc, "macro '" + Name + "' is not defined");
+    DEBUG_WITH_TYPE("asm-macros", dbgs()
+                                      << "Un-defining macro: " << Name << "\n");
+    if (!getContext().lookupMacro(Name))
+      return Error(NameLoc, "macro '" + Name + "' is not defined");
+    getContext().undefineMacro(Name);
+
+    if (!parseOptionalToken(AsmToken::Comma))
+      break;
+    parseOptionalToken(AsmToken::EndOfStatement);
+  }
 
-  getContext().undefineMacro(Name);
-  DEBUG_WITH_TYPE("asm-macros", dbgs()
-                                    << "Un-defining macro: " << Name << "\n");
   return false;
 }
 
@@ -6322,7 +6326,7 @@ void MasmParser::initializeDirectiveKindMap() {
   DirectiveKindMap["macro"] = DK_MACRO;
   DirectiveKindMap["exitm"] = DK_EXITM;
   DirectiveKindMap["endm"] = DK_ENDM;
-  // DirectiveKindMap[".purgem"] = DK_PURGEM;
+  DirectiveKindMap["purge"] = DK_PURGE;
   DirectiveKindMap[".err"] = DK_ERR;
   DirectiveKindMap[".errb"] = DK_ERRB;
   DirectiveKindMap[".errnb"] = DK_ERRNB;

diff  --git a/llvm/test/tools/llvm-ml/macro.test b/llvm/test/tools/llvm-ml/macro.test
index 255cd485e36b..3a356c0abe3e 100644
--- a/llvm/test/tools/llvm-ml/macro.test
+++ b/llvm/test/tools/llvm-ml/macro.test
@@ -134,4 +134,23 @@ local_symbol_test PROC
 ; CHECK-NEXT: jmp "??0001"
 local_symbol_test ENDP
 
+PURGE ambiguous_substitution_macro, local_symbol_macro,
+      optional_parameter_macro
+
+; Redefinition
+local_symbol_macro MACRO
+  LOCAL b
+b: xor eax, eax
+   jmp b
+ENDM
+
+purge_test PROC
+; CHECK-LABEL: purge_test:
+
+  local_symbol_macro
+; CHECK: "??0002":
+; CHECK-NEXT: xor eax, eax
+; CHECK-NEXT: jmp "??0002"
+purge_test ENDP
+
 END


        


More information about the llvm-branch-commits mailing list