Skip to content

Commit

Permalink
[llvm-ml] Add support for the .S extension
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alanzhao1 committed May 26, 2022
1 parent 8aa6b05 commit 65fd1e9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
8 changes: 8 additions & 0 deletions 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:
2 changes: 2 additions & 0 deletions llvm/test/tools/llvm-ml/lit.local.cfg
Expand Up @@ -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')
5 changes: 5 additions & 0 deletions 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:
4 changes: 2 additions & 2 deletions llvm/tools/llvm-ml/Opts.td
Expand Up @@ -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]>,
Expand Down Expand Up @@ -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"]>;
Expand Down
6 changes: 4 additions & 2 deletions llvm/tools/llvm-ml/llvm-ml.cpp
Expand Up @@ -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; "
Expand All @@ -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)) {
Expand Down

0 comments on commit 65fd1e9

Please sign in to comment.