[llvm] 65fd1e9 - [llvm-ml] Add support for the .S extension

Alan Zhao via llvm-commits llvm-commits at lists.llvm.org
Wed May 25 19:10:09 PDT 2022


Author: Alan Zhao
Date: 2022-05-25T22:10:05-04:00
New Revision: 65fd1e91b0f864f6f97742f2ed5d0243a9dc8f55

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

LOG: [llvm-ml] Add support for the .S extension

Even though MASM files typically have the .asm extension, there are some
use cases [0] where they have the .S extension. MSVC ml assembles such
files with no problems, so llvm-ml should as well.

Additionally, fix the implementation of the /Ta flag and add a test for
it.

[0]: https://crrev.com/c/3668287

Reviewed By: epastor

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

Added: 
    llvm/test/tools/llvm-ml/invalid_file_extension.blah
    llvm/test/tools/llvm-ml/valid_file_extension.S

Modified: 
    llvm/test/tools/llvm-ml/lit.local.cfg
    llvm/tools/llvm-ml/Opts.td
    llvm/tools/llvm-ml/llvm-ml.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-ml/invalid_file_extension.blah b/llvm/test/tools/llvm-ml/invalid_file_extension.blah
new file mode 100644
index 0000000000000..7b916910a1270
--- /dev/null
+++ b/llvm/test/tools/llvm-ml/invalid_file_extension.blah
@@ -0,0 +1,8 @@
+; RUN: not llvm-ml %s /Fo /dev/null 2>&1 | FileCheck %s --check-prefixes=CHECK-INVALID
+; RUN: llvm-ml /Ta %s -m64 -filetype=s /Fo - | FileCheck %s --check-prefixes=CHECK-TA
+
+; CHECK-INVALID: error: invalid option '{{.*}}invalid_file_extension.blah'
+
+.code
+foo:
+; CHECK-TA: foo:

diff  --git a/llvm/test/tools/llvm-ml/lit.local.cfg b/llvm/test/tools/llvm-ml/lit.local.cfg
index 5729c25cfd5be..ffc3d7a1e0ab1 100644
--- a/llvm/test/tools/llvm-ml/lit.local.cfg
+++ b/llvm/test/tools/llvm-ml/lit.local.cfg
@@ -3,3 +3,5 @@ if not ('X86' in config.root.targets):
     config.unsupported = True
 
 config.suffixes.add('.asm')
+config.suffixes.add('.S')
+config.suffixes.add('.blah')

diff  --git a/llvm/test/tools/llvm-ml/valid_file_extension.S b/llvm/test/tools/llvm-ml/valid_file_extension.S
new file mode 100644
index 0000000000000..8c7e9435fed6c
--- /dev/null
+++ b/llvm/test/tools/llvm-ml/valid_file_extension.S
@@ -0,0 +1,5 @@
+; RUN: llvm-ml -m64 -filetype=s %s /Fo - | FileCheck %s
+
+.code
+foo:
+; CHECK: foo:

diff  --git a/llvm/tools/llvm-ml/Opts.td b/llvm/tools/llvm-ml/Opts.td
index 9cd1e91ecbb55..88897a7aa7c8f 100644
--- a/llvm/tools/llvm-ml/Opts.td
+++ b/llvm/tools/llvm-ml/Opts.td
@@ -31,7 +31,7 @@ class UnsupportedSeparate<string name> : Separate<["/", "-"], name>,
 def bitness : LLVMJoined<"m">, Values<"32,64">,
               HelpText<"Target platform (x86 or x86-64)">;
 def as_lex : LLVMFlag<"as-lex">,
-             HelpText<"Lex tokens from a .asm file without assembling">;
+             HelpText<"Lex tokens from an .asm or .S file without assembling">;
 def debug : LLVMFlag<"debug">, Flags<[HelpHidden]>,
             HelpText<"Enable debug output">;
 def debug_only : LLVMCommaJoined<"debug-only=">, Flags<[HelpHidden]>,
@@ -82,7 +82,7 @@ def safeseh : MLFlag<"safeseh">,
                        "32-bit.">;
 def assembly_file : MLJoinedOrSeparate<"Ta">,
                     HelpText<"Assemble source file with name not ending with "
-                             "the .asm extension">;
+                             "the .asm or the .S extension">;
 def error_on_warning : MLFlag<"WX">, Alias<fatal_warnings>;
 def parse_only : MLFlag<"Zs">, HelpText<"Run a syntax-check only">,
                  Alias<filetype>, AliasArgs<["null"]>;

diff  --git a/llvm/tools/llvm-ml/llvm-ml.cpp b/llvm/tools/llvm-ml/llvm-ml.cpp
index 2fd218a0c907b..2651132f23ccc 100644
--- a/llvm/tools/llvm-ml/llvm-ml.cpp
+++ b/llvm/tools/llvm-ml/llvm-ml.cpp
@@ -208,7 +208,9 @@ int main(int Argc, char **Argv) {
   std::string InputFilename;
   for (auto *Arg : InputArgs.filtered(OPT_INPUT)) {
     std::string ArgString = Arg->getAsString(InputArgs);
-    if (ArgString == "-" || StringRef(ArgString).endswith(".asm")) {
+    StringRef ArgStringRef(ArgString);
+    if (ArgString == "-" || ArgStringRef.endswith(".asm") ||
+        ArgStringRef.endswith(".S")) {
       if (!InputFilename.empty()) {
         WithColor::warning(errs(), ProgName)
             << "does not support multiple assembly files in one command; "
@@ -234,7 +236,7 @@ int main(int Argc, char **Argv) {
           << "does not support multiple assembly files in one command; "
           << "ignoring '" << InputFilename << "'\n";
     }
-    InputFilename = Arg->getAsString(InputArgs);
+    InputFilename = Arg->getValue();
   }
 
   for (auto *Arg : InputArgs.filtered(OPT_unsupported_Group)) {


        


More information about the llvm-commits mailing list