[llvm] bc96178 - [ms] [llvm-ml] Handle OPTION PROLOGUE/EPILOGUE:NONE

Eric Astor via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 10 10:52:30 PDT 2022


Author: Eric Astor
Date: 2022-08-10T17:52:15Z
New Revision: bc9617899c6eb57f7c505bf0271ae6c8d4081aec

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

LOG: [ms] [llvm-ml] Handle OPTION PROLOGUE/EPILOGUE:NONE

Since we don't yet implement PROC's PROLOGUE and EPILOGUE support, we can safely ignore the option that disables them.

Reviewed By: thakis

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

Added: 
    llvm/test/tools/llvm-ml/option_prologue_epilogue_none.asm

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCParser/COFFMasmParser.cpp b/llvm/lib/MC/MCParser/COFFMasmParser.cpp
index 9109333cb4677..f2165b4864497 100644
--- a/llvm/lib/MC/MCParser/COFFMasmParser.cpp
+++ b/llvm/lib/MC/MCParser/COFFMasmParser.cpp
@@ -47,6 +47,7 @@ class COFFMasmParser : public MCAsmParserExtension {
   bool ParseDirectiveSegment(StringRef, SMLoc);
   bool ParseDirectiveSegmentEnd(StringRef, SMLoc);
   bool ParseDirectiveIncludelib(StringRef, SMLoc);
+  bool ParseDirectiveOption(StringRef, SMLoc);
 
   bool ParseDirectiveAlias(StringRef, SMLoc);
 
@@ -120,7 +121,7 @@ class COFFMasmParser : public MCAsmParserExtension {
     // .fpo
     addDirectiveHandler<&COFFMasmParser::ParseDirectiveIncludelib>(
         "includelib");
-    // option
+    addDirectiveHandler<&COFFMasmParser::ParseDirectiveOption>("option");
     // popcontext
     // pushcontext
     // .safeseh
@@ -403,6 +404,43 @@ bool COFFMasmParser::ParseDirectiveIncludelib(StringRef Directive, SMLoc Loc) {
   return false;
 }
 
+/// ParseDirectiveOption
+///  ::= "option" option-list
+bool COFFMasmParser::ParseDirectiveOption(StringRef Directive, SMLoc Loc) {
+  auto parseOption = [&]() -> bool {
+    StringRef Option;
+    if (getParser().parseIdentifier(Option))
+      return TokError("expected identifier for option name");
+    if (Option.equals_insensitive("prologue")) {
+      StringRef MacroId;
+      if (parseToken(AsmToken::Colon) || getParser().parseIdentifier(MacroId))
+        return TokError("expected :macroId after OPTION PROLOGUE");
+      if (MacroId.equals_insensitive("none")) {
+        // Since we currently don't implement prologues/epilogues, NONE is our
+        // default.
+        return false;
+      }
+      return TokError("OPTION PROLOGUE is currently unsupported");
+    }
+    if (Option.equals_insensitive("epilogue")) {
+      StringRef MacroId;
+      if (parseToken(AsmToken::Colon) || getParser().parseIdentifier(MacroId))
+        return TokError("expected :macroId after OPTION EPILOGUE");
+      if (MacroId.equals_insensitive("none")) {
+        // Since we currently don't implement prologues/epilogues, NONE is our
+        // default.
+        return false;
+      }
+      return TokError("OPTION EPILOGUE is currently unsupported");
+    }
+    return TokError("OPTION '" + Option + "' is currently unsupported");
+  };
+
+  if (parseMany(parseOption))
+    return addErrorSuffix(" in OPTION directive");
+  return false;
+}
+
 /// ParseDirectiveProc
 /// TODO(epastor): Implement parameters and other attributes.
 ///  ::= label "proc" [[distance]]

diff  --git a/llvm/test/tools/llvm-ml/option_prologue_epilogue_none.asm b/llvm/test/tools/llvm-ml/option_prologue_epilogue_none.asm
new file mode 100644
index 0000000000000..0aac244db57d9
--- /dev/null
+++ b/llvm/test/tools/llvm-ml/option_prologue_epilogue_none.asm
@@ -0,0 +1,17 @@
+; RUN: llvm-ml -filetype=s %s /Fo - | FileCheck %s
+
+OPTION pRoLoGuE:nOnE, EPILogue:None
+
+.code
+
+t1 PROC
+  ret
+t1 ENDP
+
+; CHECK-LABEL: t1:
+; CHECK-NOT: pop
+; CHECK-NOT: push
+; CHECK: {{^ *}}ret{{ *$}}
+
+end
+


        


More information about the llvm-commits mailing list