[PATCH] D123173: [llvm-ml] Add support for the -o flag
Alan Zhao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 5 17:46:01 PDT 2022
ayzhao created this revision.
Herald added a project: All.
ayzhao requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Many LLVM tools, such as clang-cl, that accept the flag /Fo to specify
output files are also tolerant of the -o flag to do the same thing. To
maintain parity with these other tools, llvm-ml should also support -o.
As with clang-cl, if both /Fo and -o are specified, then /Fo takes
precedence[0].
[0]: https://github.com/llvm/llvm-project/blob/175b9af484f483c3423ab2f78db5de7e25b64c31/clang/lib/Driver/ToolChains/Clang.cpp#L987-L992
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D123173
Files:
llvm/test/tools/llvm-ml/output_flag.asm
llvm/tools/llvm-ml/Opts.td
llvm/tools/llvm-ml/llvm-ml.cpp
Index: llvm/tools/llvm-ml/llvm-ml.cpp
===================================================================
--- llvm/tools/llvm-ml/llvm-ml.cpp
+++ llvm/tools/llvm-ml/llvm-ml.cpp
@@ -342,8 +342,13 @@
DefaultOutputFilename = InputFilename;
sys::path::replace_extension(DefaultOutputFilename, FileType);
}
- const StringRef OutputFilename =
- InputArgs.getLastArgValue(OPT_output_file, DefaultOutputFilename);
+ StringRef OutputFilename;
+ if (Arg *OutputFile = InputArgs.getLastArg(OPT_output_file))
+ OutputFilename = OutputFile->getValue();
+ else if (Arg *OutputFile = InputArgs.getLastArg(OPT_output_file_llvm))
+ OutputFilename = OutputFile->getValue();
+ else
+ OutputFilename = DefaultOutputFilename;
std::unique_ptr<ToolOutputFile> Out = GetOutputStream(OutputFilename);
if (!Out)
return 1;
Index: llvm/tools/llvm-ml/Opts.td
===================================================================
--- llvm/tools/llvm-ml/Opts.td
+++ llvm/tools/llvm-ml/Opts.td
@@ -37,6 +37,8 @@
HelpText<"Emit a file with the given type">;
def output_att_asm : LLVMFlag<"output-att-asm">,
HelpText<"Use ATT syntax for output assembly">;
+def output_file_llvm : LLVMJoinedOrSeparate<"o">,
+ HelpText<"Names the output file">;
def show_encoding : LLVMFlag<"show-encoding">,
HelpText<"Show instruction encodings in output assembly">;
def show_inst : LLVMFlag<"show-inst">,
Index: llvm/test/tools/llvm-ml/output_flag.asm
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-ml/output_flag.asm
@@ -0,0 +1,13 @@
+; RUN: llvm-ml --filetype=s %s /Fo - | FileCheck %s --check-prefix=LLVM_FLAG
+; RUN: llvm-ml --filetype=s %s -o - | FileCheck %s --check-prefix=LLVM_FLAG
+; RUN: llvm-ml --filetype=s %s -o /dev/null /Fo - | FileCheck %s --check-prefix=BOTH_FLAGS
+
+.code
+
+t1:
+; LLVM_FLAG: t1:
+; MS_FLAG: t1:
+; /Fo takes precedence over -o, so we should still expect to see output
+; BOTH_FLAGS: t1:
+
+END
\ No newline at end of file
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123173.420677.patch
Type: text/x-patch
Size: 2093 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220406/eef1dc49/attachment.bin>
More information about the llvm-commits
mailing list