aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Astor <epastor@google.com>2020-11-30 15:15:18 -0500
committerEric Astor <epastor@google.com>2020-12-01 17:43:44 -0500
commit8fee2ee9a689276eaea61d4c3f124aa80a81b6f7 (patch)
treeeffef26f82c92d838cd9b7f3233ef99245195cf8
parentAvoid redundant inline with LLVM_ATTRIBUTE_ALWAYS_INLINE (diff)
downloadllvm-project-8fee2ee9a689276eaea61d4c3f124aa80a81b6f7.tar.gz
llvm-project-8fee2ee9a689276eaea61d4c3f124aa80a81b6f7.tar.bz2
llvm-project-8fee2ee9a689276eaea61d4c3f124aa80a81b6f7.zip
[ms] [llvm-ml] Introduce command-line compatibility for ml.exe and ml64.exe
Switch to OptParser for command-line handling Reviewed By: thakis Differential Revision: https://reviews.llvm.org/D90058
-rw-r--r--llvm/test/tools/llvm-ml/alias.asm (renamed from llvm/test/tools/llvm-ml/alias.test)2
-rw-r--r--llvm/test/tools/llvm-ml/alias_errors.asm (renamed from llvm/test/tools/llvm-ml/alias_errors.test)2
-rw-r--r--llvm/test/tools/llvm-ml/basic.test4
-rw-r--r--llvm/test/tools/llvm-ml/basic_data.asm (renamed from llvm/test/tools/llvm-ml/basic_data.test)2
-rw-r--r--llvm/test/tools/llvm-ml/builtin_types.asm (renamed from llvm/test/tools/llvm-ml/builtin_types.test)2
-rw-r--r--llvm/test/tools/llvm-ml/dot_operator.asm (renamed from llvm/test/tools/llvm-ml/dot_operator.test)2
-rw-r--r--llvm/test/tools/llvm-ml/expansion.asm (renamed from llvm/test/tools/llvm-ml/expansion.test)2
-rw-r--r--llvm/test/tools/llvm-ml/feat00.asm (renamed from llvm/test/tools/llvm-ml/feat00.test)8
-rw-r--r--llvm/test/tools/llvm-ml/feat00_override.asm (renamed from llvm/test/tools/llvm-ml/feat00_override.test)6
-rw-r--r--llvm/test/tools/llvm-ml/line_continuations.asm (renamed from llvm/test/tools/llvm-ml/line_continuations.test)2
-rw-r--r--llvm/test/tools/llvm-ml/lit.local.cfg2
-rw-r--r--llvm/test/tools/llvm-ml/macro.asm (renamed from llvm/test/tools/llvm-ml/macro.test)2
-rw-r--r--llvm/test/tools/llvm-ml/macro_errors.asm (renamed from llvm/test/tools/llvm-ml/macro_errors.test)2
-rw-r--r--llvm/test/tools/llvm-ml/macro_function.asm (renamed from llvm/test/tools/llvm-ml/macro_function.test)2
-rw-r--r--llvm/test/tools/llvm-ml/named_operators.asm (renamed from llvm/test/tools/llvm-ml/named_operators.test)2
-rw-r--r--llvm/test/tools/llvm-ml/proc.asm13
-rw-r--r--llvm/test/tools/llvm-ml/proc.test13
-rw-r--r--llvm/test/tools/llvm-ml/proc_frame.asm (renamed from llvm/test/tools/llvm-ml/proc_frame.test)2
-rw-r--r--llvm/test/tools/llvm-ml/radix.asm (renamed from llvm/test/tools/llvm-ml/radix.test)2
-rw-r--r--llvm/test/tools/llvm-ml/radix_errors.asm (renamed from llvm/test/tools/llvm-ml/radix_errors.test)2
-rw-r--r--llvm/test/tools/llvm-ml/repeat_directives.asm (renamed from llvm/test/tools/llvm-ml/repeat_directives.test)2
-rw-r--r--llvm/test/tools/llvm-ml/rip-relative-addressing.asm8
-rw-r--r--llvm/test/tools/llvm-ml/rip-relative-addressing.test8
-rw-r--r--llvm/test/tools/llvm-ml/run.asm (renamed from llvm/test/tools/llvm-ml/run.test)0
-rw-r--r--llvm/test/tools/llvm-ml/size_inference.asm (renamed from llvm/test/tools/llvm-ml/size_inference.test)2
-rw-r--r--llvm/test/tools/llvm-ml/strings.asm (renamed from llvm/test/tools/llvm-ml/strings.test)2
-rw-r--r--llvm/test/tools/llvm-ml/strings_errors.asm (renamed from llvm/test/tools/llvm-ml/strings_errors.test)2
-rw-r--r--llvm/test/tools/llvm-ml/struct.asm (renamed from llvm/test/tools/llvm-ml/struct.test)2
-rw-r--r--llvm/test/tools/llvm-ml/struct_alignment.asm (renamed from llvm/test/tools/llvm-ml/struct_alignment.test)2
-rw-r--r--llvm/test/tools/llvm-ml/struct_errors.asm (renamed from llvm/test/tools/llvm-ml/struct_errors.test)2
-rw-r--r--llvm/test/tools/llvm-ml/type_operators.asm (renamed from llvm/test/tools/llvm-ml/type_operators.test)2
-rw-r--r--llvm/test/tools/llvm-ml/variable.asm (renamed from llvm/test/tools/llvm-ml/variable.test)2
-rw-r--r--llvm/tools/llvm-ml/CMakeLists.txt6
-rw-r--r--llvm/tools/llvm-ml/Opts.td108
-rw-r--r--llvm/tools/llvm-ml/llvm-ml.cpp338
35 files changed, 323 insertions, 237 deletions
diff --git a/llvm/test/tools/llvm-ml/alias.test b/llvm/test/tools/llvm-ml/alias.asm
index 2daaecdbbcc0..bd21f2b01c01 100644
--- a/llvm/test/tools/llvm-ml/alias.test
+++ b/llvm/test/tools/llvm-ml/alias.asm
@@ -1,4 +1,4 @@
-; RUN: llvm-ml -filetype=obj %s | llvm-readobj --syms - | FileCheck %s
+; RUN: llvm-ml %s /Fo - | llvm-readobj --syms - | FileCheck %s
.code
diff --git a/llvm/test/tools/llvm-ml/alias_errors.test b/llvm/test/tools/llvm-ml/alias_errors.asm
index 9d51b2a993ac..7c30b8e261a2 100644
--- a/llvm/test/tools/llvm-ml/alias_errors.test
+++ b/llvm/test/tools/llvm-ml/alias_errors.asm
@@ -1,4 +1,4 @@
-; RUN: not llvm-ml -filetype=asm %s 2>&1 | FileCheck %s
+; RUN: not llvm-ml -filetype=s %s /Fo /dev/null 2>&1 | FileCheck %s
.code
diff --git a/llvm/test/tools/llvm-ml/basic.test b/llvm/test/tools/llvm-ml/basic.test
index 30aa860f2b90..960eb47f6cc5 100644
--- a/llvm/test/tools/llvm-ml/basic.test
+++ b/llvm/test/tools/llvm-ml/basic.test
@@ -1,3 +1,3 @@
-# RUN: not llvm-ml %t.blah -o /dev/null 2>&1 | FileCheck --check-prefix=ENOENT %s
+# RUN: not llvm-ml %t.blah.asm /Fo /dev/null 2>&1 | FileCheck --check-prefix=ENOENT %s
-# ENOENT: {{.*}}.blah: {{[Nn]}}o such file or directory
+# ENOENT: {{.*}}.blah.asm: {{[Nn]}}o such file or directory
diff --git a/llvm/test/tools/llvm-ml/basic_data.test b/llvm/test/tools/llvm-ml/basic_data.asm
index d39775fb6646..4f659c1c225a 100644
--- a/llvm/test/tools/llvm-ml/basic_data.test
+++ b/llvm/test/tools/llvm-ml/basic_data.asm
@@ -1,4 +1,4 @@
-# RUN: llvm-ml -filetype=asm %s | FileCheck %s
+# RUN: llvm-ml -filetype=s %s /Fo - | FileCheck %s
.data
BYTE 2, 4, 6, 8
diff --git a/llvm/test/tools/llvm-ml/builtin_types.test b/llvm/test/tools/llvm-ml/builtin_types.asm
index 89ec1cfd0d71..e46c4c8a34e1 100644
--- a/llvm/test/tools/llvm-ml/builtin_types.test
+++ b/llvm/test/tools/llvm-ml/builtin_types.asm
@@ -1,4 +1,4 @@
-# RUN: llvm-ml -filetype=asm %s | FileCheck %s
+# RUN: llvm-ml -filetype=s %s /Fo - | FileCheck %s
.data
diff --git a/llvm/test/tools/llvm-ml/dot_operator.test b/llvm/test/tools/llvm-ml/dot_operator.asm
index bbea6152e8db..0e7a1db953f9 100644
--- a/llvm/test/tools/llvm-ml/dot_operator.test
+++ b/llvm/test/tools/llvm-ml/dot_operator.asm
@@ -1,4 +1,4 @@
-# RUN: llvm-ml -filetype=asm %s | FileCheck %s
+# RUN: llvm-ml -m64 -filetype=s %s /Fo - | FileCheck %s
.data
diff --git a/llvm/test/tools/llvm-ml/expansion.test b/llvm/test/tools/llvm-ml/expansion.asm
index 010d50c088d8..344184965f39 100644
--- a/llvm/test/tools/llvm-ml/expansion.test
+++ b/llvm/test/tools/llvm-ml/expansion.asm
@@ -1,4 +1,4 @@
-; RUN: llvm-ml -filetype=asm %s 2>&1 | FileCheck %s
+; RUN: llvm-ml -filetype=s %s /Fo - 2>&1 | FileCheck %s
.code
diff --git a/llvm/test/tools/llvm-ml/feat00.test b/llvm/test/tools/llvm-ml/feat00.asm
index 1b5070e8c86a..ff8df9d151aa 100644
--- a/llvm/test/tools/llvm-ml/feat00.test
+++ b/llvm/test/tools/llvm-ml/feat00.asm
@@ -1,8 +1,8 @@
-; RUN: llvm-ml -m32 -filetype=obj %s | llvm-readobj --syms - | FileCheck %s --check-prefix=CHECK-OBJ --check-prefix=CHECK-OBJ-NOSAFESEH
-; RUN: llvm-ml -m64 -filetype=obj %s | llvm-readobj --syms - | FileCheck %s --check-prefix=CHECK-OBJ --check-prefix=CHECK-OBJ-NOSAFESEH
+; RUN: llvm-ml -m32 %s /Fo - | llvm-readobj --syms - | FileCheck %s --check-prefix=CHECK-OBJ --check-prefix=CHECK-OBJ-NOSAFESEH
+; RUN: llvm-ml -m64 %s /Fo - | llvm-readobj --syms - | FileCheck %s --check-prefix=CHECK-OBJ --check-prefix=CHECK-OBJ-NOSAFESEH
-; RUN: llvm-ml -m32 -safeseh -filetype=obj %s | llvm-readobj --syms - | FileCheck %s --check-prefix=CHECK-OBJ --check-prefix=CHECK-OBJ-SAFESEH
-; RUN: llvm-ml -m64 -safeseh -filetype=obj %s -o %t.obj 2>&1 | FileCheck %s --check-prefix=CHECK-SAFESEH64
+; RUN: llvm-ml -m32 -safeseh %s /Fo - | llvm-readobj --syms - | FileCheck %s --check-prefix=CHECK-OBJ --check-prefix=CHECK-OBJ-SAFESEH
+; RUN: llvm-ml -m64 -safeseh %s /Fo %t.obj 2>&1 | FileCheck %s --check-prefix=CHECK-SAFESEH64
; RUN: llvm-readobj --syms %t.obj | FileCheck %s --check-prefix=CHECK-OBJ --check-prefix=CHECK-OBJ-NOSAFESEH
; CHECK-SAFESEH64: warning: /safeseh applies only to 32-bit X86 platforms; ignoring.
diff --git a/llvm/test/tools/llvm-ml/feat00_override.test b/llvm/test/tools/llvm-ml/feat00_override.asm
index 358fc8566081..fc5035874b32 100644
--- a/llvm/test/tools/llvm-ml/feat00_override.test
+++ b/llvm/test/tools/llvm-ml/feat00_override.asm
@@ -1,6 +1,6 @@
-; RUN: llvm-ml -m32 -filetype=obj %s | llvm-readobj --syms - | FileCheck %s
-; RUN: llvm-ml -m64 -filetype=obj %s | llvm-readobj --syms - | FileCheck %s
-; RUN: llvm-ml -m32 -safeseh -filetype=obj %s | llvm-readobj --syms - | FileCheck %s
+; RUN: llvm-ml -m32 %s /Fo - | llvm-readobj --syms - | FileCheck %s
+; RUN: llvm-ml -m64 %s /Fo - | llvm-readobj --syms - | FileCheck %s
+; RUN: llvm-ml -m32 -safeseh %s /Fo - | llvm-readobj --syms - | FileCheck %s
.code
diff --git a/llvm/test/tools/llvm-ml/line_continuations.test b/llvm/test/tools/llvm-ml/line_continuations.asm
index 604bbe91b32a..afeb69adf366 100644
--- a/llvm/test/tools/llvm-ml/line_continuations.test
+++ b/llvm/test/tools/llvm-ml/line_continuations.asm
@@ -1,4 +1,4 @@
-# RUN: llvm-ml -filetype=asm %s | FileCheck %s
+# RUN: llvm-ml -filetype=s %s /Fo - | FileCheck %s
.code
diff --git a/llvm/test/tools/llvm-ml/lit.local.cfg b/llvm/test/tools/llvm-ml/lit.local.cfg
index 7230f35fdb83..5729c25cfd5b 100644
--- a/llvm/test/tools/llvm-ml/lit.local.cfg
+++ b/llvm/test/tools/llvm-ml/lit.local.cfg
@@ -1,3 +1,5 @@
if not ('X86' in config.root.targets):
# We need support for X86.
config.unsupported = True
+
+config.suffixes.add('.asm')
diff --git a/llvm/test/tools/llvm-ml/macro.test b/llvm/test/tools/llvm-ml/macro.asm
index 3a356c0abe3e..93543aaf3d9d 100644
--- a/llvm/test/tools/llvm-ml/macro.test
+++ b/llvm/test/tools/llvm-ml/macro.asm
@@ -1,4 +1,4 @@
-; RUN: llvm-ml -m64 -filetype=asm %s | FileCheck %s
+; RUN: llvm-ml -m64 -filetype=s %s /Fo - | FileCheck %s
.data
diff --git a/llvm/test/tools/llvm-ml/macro_errors.test b/llvm/test/tools/llvm-ml/macro_errors.asm
index d5ef5c903b00..943ff41866b6 100644
--- a/llvm/test/tools/llvm-ml/macro_errors.test
+++ b/llvm/test/tools/llvm-ml/macro_errors.asm
@@ -1,4 +1,4 @@
-; RUN: not llvm-ml -filetype=asm %s 2>&1 | FileCheck %s --implicit-check-not=error:
+; RUN: not llvm-ml -filetype=s %s /Fo - 2>&1 | FileCheck %s --implicit-check-not=error:
.code
diff --git a/llvm/test/tools/llvm-ml/macro_function.test b/llvm/test/tools/llvm-ml/macro_function.asm
index 94164b5c60a3..c28d7c8c6222 100644
--- a/llvm/test/tools/llvm-ml/macro_function.test
+++ b/llvm/test/tools/llvm-ml/macro_function.asm
@@ -1,4 +1,4 @@
-; RUN: llvm-ml -filetype=asm %s | FileCheck %s
+; RUN: llvm-ml -filetype=s %s /Fo - | FileCheck %s
.code
diff --git a/llvm/test/tools/llvm-ml/named_operators.test b/llvm/test/tools/llvm-ml/named_operators.asm
index 1eb945326fe1..49ae8b093350 100644
--- a/llvm/test/tools/llvm-ml/named_operators.test
+++ b/llvm/test/tools/llvm-ml/named_operators.asm
@@ -1,4 +1,4 @@
-; RUN: llvm-ml -filetype=asm %s | FileCheck %s
+; RUN: llvm-ml -filetype=s %s /Fo - | FileCheck %s
.data
diff --git a/llvm/test/tools/llvm-ml/proc.asm b/llvm/test/tools/llvm-ml/proc.asm
new file mode 100644
index 000000000000..2e574dc89c05
--- /dev/null
+++ b/llvm/test/tools/llvm-ml/proc.asm
@@ -0,0 +1,13 @@
+# RUN: llvm-ml -m32 -filetype=s %s /Fo - | FileCheck %s
+# RUN: llvm-ml -m64 -filetype=s %s /Fo - | FileCheck %s
+
+.code
+
+t1 PROC
+ ret
+t1 ENDP
+
+; CHECK: t1:
+; CHECK: ret
+
+END
diff --git a/llvm/test/tools/llvm-ml/proc.test b/llvm/test/tools/llvm-ml/proc.test
deleted file mode 100644
index 15e253a31083..000000000000
--- a/llvm/test/tools/llvm-ml/proc.test
+++ /dev/null
@@ -1,13 +0,0 @@
-# RUN: llvm-ml -m32 -filetype=asm %s | FileCheck %s
-# RUN: llvm-ml -m64 -filetype=asm %s | FileCheck %s
-
-.code
-
-t1 PROC
- ret
-t1 ENDP
-
-; CHECK: t1:
-; CHECK: ret
-
-END
diff --git a/llvm/test/tools/llvm-ml/proc_frame.test b/llvm/test/tools/llvm-ml/proc_frame.asm
index f98721467474..e3a4c96e865b 100644
--- a/llvm/test/tools/llvm-ml/proc_frame.test
+++ b/llvm/test/tools/llvm-ml/proc_frame.asm
@@ -1,4 +1,4 @@
-# RUN: llvm-ml -m64 -filetype=asm %s | FileCheck %s
+# RUN: llvm-ml -m64 -filetype=s %s /Fo - | FileCheck %s
.code
diff --git a/llvm/test/tools/llvm-ml/radix.test b/llvm/test/tools/llvm-ml/radix.asm
index 64333706b07d..401abc7122d9 100644
--- a/llvm/test/tools/llvm-ml/radix.test
+++ b/llvm/test/tools/llvm-ml/radix.asm
@@ -1,4 +1,4 @@
-# RUN: llvm-ml -filetype=asm %s | FileCheck %s
+# RUN: llvm-ml -filetype=s %s /Fo - | FileCheck %s
.code
diff --git a/llvm/test/tools/llvm-ml/radix_errors.test b/llvm/test/tools/llvm-ml/radix_errors.asm
index 4745e7911900..b47619f73444 100644
--- a/llvm/test/tools/llvm-ml/radix_errors.test
+++ b/llvm/test/tools/llvm-ml/radix_errors.asm
@@ -1,4 +1,4 @@
-; RUN: not llvm-ml -filetype=asm %s 2>&1 | FileCheck %s --implicit-check-not=error:
+; RUN: not llvm-ml -filetype=s %s /Fo /dev/null 2>&1 | FileCheck %s --implicit-check-not=error:
.code
diff --git a/llvm/test/tools/llvm-ml/repeat_directives.test b/llvm/test/tools/llvm-ml/repeat_directives.asm
index 72675394f6c7..dc47d9aac725 100644
--- a/llvm/test/tools/llvm-ml/repeat_directives.test
+++ b/llvm/test/tools/llvm-ml/repeat_directives.asm
@@ -1,4 +1,4 @@
-; RUN: llvm-ml -m64 -filetype=asm %s | FileCheck %s
+; RUN: llvm-ml -m64 -filetype=s %s /Fo - | FileCheck %s
.data
diff --git a/llvm/test/tools/llvm-ml/rip-relative-addressing.asm b/llvm/test/tools/llvm-ml/rip-relative-addressing.asm
new file mode 100644
index 000000000000..5d538576f9b3
--- /dev/null
+++ b/llvm/test/tools/llvm-ml/rip-relative-addressing.asm
@@ -0,0 +1,8 @@
+# RUN: llvm-ml -m32 -filetype=s %s /Fo - | FileCheck %s --check-prefix=CHECK-32
+# RUN: llvm-ml -m64 -filetype=s %s /Fo - | FileCheck %s --check-prefix=CHECK-64
+
+.code
+mov eax, [4]
+; CHECK-32: mov eax, dword ptr [4]
+; CHECK-64: mov eax, dword ptr [rip + 4]
+END \ No newline at end of file
diff --git a/llvm/test/tools/llvm-ml/rip-relative-addressing.test b/llvm/test/tools/llvm-ml/rip-relative-addressing.test
deleted file mode 100644
index 81e5676d041e..000000000000
--- a/llvm/test/tools/llvm-ml/rip-relative-addressing.test
+++ /dev/null
@@ -1,8 +0,0 @@
-# RUN: llvm-ml -m32 -filetype=asm %s | FileCheck %s --check-prefix=CHECK-32
-# RUN: llvm-ml -m64 -filetype=asm %s | FileCheck %s --check-prefix=CHECK-64
-
-.code
-mov eax, [4]
-; CHECK-32: mov eax, dword ptr [4]
-; CHECK-64: mov eax, dword ptr [rip + 4]
-END \ No newline at end of file
diff --git a/llvm/test/tools/llvm-ml/run.test b/llvm/test/tools/llvm-ml/run.asm
index d40b63a89681..d40b63a89681 100644
--- a/llvm/test/tools/llvm-ml/run.test
+++ b/llvm/test/tools/llvm-ml/run.asm
diff --git a/llvm/test/tools/llvm-ml/size_inference.test b/llvm/test/tools/llvm-ml/size_inference.asm
index c24eb51fad42..cd3b83074c31 100644
--- a/llvm/test/tools/llvm-ml/size_inference.test
+++ b/llvm/test/tools/llvm-ml/size_inference.asm
@@ -1,4 +1,4 @@
-; RUN: not llvm-ml -filetype=asm %s 2>&1 | FileCheck %s --dump-input=always
+; RUN: not llvm-ml -filetype=s %s /Fo /dev/null 2>&1 | FileCheck %s --dump-input=always
.data
diff --git a/llvm/test/tools/llvm-ml/strings.test b/llvm/test/tools/llvm-ml/strings.asm
index c43f39d42c3f..26f402c23851 100644
--- a/llvm/test/tools/llvm-ml/strings.test
+++ b/llvm/test/tools/llvm-ml/strings.asm
@@ -1,4 +1,4 @@
-# RUN: llvm-ml -filetype=asm %s | FileCheck %s
+; RUN: llvm-ml -filetype=s %s /Fo - | FileCheck %s
.data
diff --git a/llvm/test/tools/llvm-ml/strings_errors.test b/llvm/test/tools/llvm-ml/strings_errors.asm
index 377ad29c06ff..c860d45e0801 100644
--- a/llvm/test/tools/llvm-ml/strings_errors.test
+++ b/llvm/test/tools/llvm-ml/strings_errors.asm
@@ -1,4 +1,4 @@
-; RUN: not llvm-ml -filetype=asm %s 2>&1 | FileCheck %s --implicit-check-not=error:
+; RUN: not llvm-ml -m64 -filetype=s %s /Fo /dev/null 2>&1 | FileCheck %s --implicit-check-not=error:
.code
diff --git a/llvm/test/tools/llvm-ml/struct.test b/llvm/test/tools/llvm-ml/struct.asm
index b29a069dc84c..f2cd7c1a95da 100644
--- a/llvm/test/tools/llvm-ml/struct.test
+++ b/llvm/test/tools/llvm-ml/struct.asm
@@ -1,4 +1,4 @@
-# RUN: llvm-ml -filetype=asm %s | FileCheck %s
+# RUN: llvm-ml -m64 -filetype=s %s /Fo - | FileCheck %s
.data
BAZ STRUCT
diff --git a/llvm/test/tools/llvm-ml/struct_alignment.test b/llvm/test/tools/llvm-ml/struct_alignment.asm
index cfe803872c3b..d700d4d392be 100644
--- a/llvm/test/tools/llvm-ml/struct_alignment.test
+++ b/llvm/test/tools/llvm-ml/struct_alignment.asm
@@ -1,4 +1,4 @@
-; RUN: llvm-ml -filetype=asm %s | FileCheck %s
+; RUN: llvm-ml -filetype=s %s /Fo - | FileCheck %s
.data
diff --git a/llvm/test/tools/llvm-ml/struct_errors.test b/llvm/test/tools/llvm-ml/struct_errors.asm
index 13d72a2840f0..3040c9dcf567 100644
--- a/llvm/test/tools/llvm-ml/struct_errors.test
+++ b/llvm/test/tools/llvm-ml/struct_errors.asm
@@ -1,4 +1,4 @@
-# RUN: not llvm-ml -filetype=asm %s 2>&1 | FileCheck %s --dump-input=always
+# RUN: not llvm-ml -filetype=s %s /Fo /dev/null 2>&1 | FileCheck %s --dump-input=always
.data
int_test STRUCT
diff --git a/llvm/test/tools/llvm-ml/type_operators.test b/llvm/test/tools/llvm-ml/type_operators.asm
index 7de6cdd9448e..7d5bbe603c85 100644
--- a/llvm/test/tools/llvm-ml/type_operators.test
+++ b/llvm/test/tools/llvm-ml/type_operators.asm
@@ -1,4 +1,4 @@
-# RUN: llvm-ml -filetype=asm %s | FileCheck %s
+# RUN: llvm-ml -filetype=s %s /Fo - | FileCheck %s
.data
diff --git a/llvm/test/tools/llvm-ml/variable.test b/llvm/test/tools/llvm-ml/variable.asm
index 4e89d67bd59d..b31879fc28aa 100644
--- a/llvm/test/tools/llvm-ml/variable.test
+++ b/llvm/test/tools/llvm-ml/variable.asm
@@ -1,4 +1,4 @@
-# RUN: llvm-ml -filetype=asm %s | FileCheck %s
+# RUN: llvm-ml -filetype=s %s /Fo - | FileCheck %s
.data
t1_value equ 1 or 2
diff --git a/llvm/tools/llvm-ml/CMakeLists.txt b/llvm/tools/llvm-ml/CMakeLists.txt
index 74546385e2c5..7c790392bdd1 100644
--- a/llvm/tools/llvm-ml/CMakeLists.txt
+++ b/llvm/tools/llvm-ml/CMakeLists.txt
@@ -5,9 +5,15 @@ set(LLVM_LINK_COMPONENTS
AllTargetsInfos
MC
MCParser
+ Option
Support
)
+set(LLVM_TARGET_DEFINITIONS Opts.td)
+
+tablegen(LLVM Opts.inc -gen-opt-parser-defs)
+add_public_tablegen_target(MLTableGen)
+
add_llvm_tool(llvm-ml
llvm-ml.cpp
Disassembler.cpp
diff --git a/llvm/tools/llvm-ml/Opts.td b/llvm/tools/llvm-ml/Opts.td
new file mode 100644
index 000000000000..ed52bb4771ba
--- /dev/null
+++ b/llvm/tools/llvm-ml/Opts.td
@@ -0,0 +1,108 @@
+include "llvm/Option/OptParser.td"
+
+// For LLVM-specific options, we prefer a two-dash prefix, but accept one for
+// compatibility with llvm-mc. For clear separation from ML.EXE compatible
+// options, slash is not accepted.
+class LLVMFlag<string name> : Flag<["--", "-"], name>;
+class LLVMJoined<string name> : Joined<["--", "-"], name>;
+class LLVMJoinedOrSeparate<string name> : JoinedOrSeparate<["--", "-"], name>;
+class LLVMSeparate<string name> : Separate<["--", "-"], name>;
+
+def ml_Group : OptionGroup<"<ml options>">,
+ HelpText<"ML.EXE COMPATIBILITY OPTIONS">;
+class MLFlag<string name> : Flag<["/", "-"], name>, Group<ml_Group>;
+class MLJoined<string name> : Joined<["/", "-"], name>, Group<ml_Group>;
+class MLJoinedOrSeparate<string name> : JoinedOrSeparate<["/", "-"], name>,
+ Group<ml_Group>;
+class MLSeparate<string name> : Separate<["/", "-"], name>, Group<ml_Group>;
+
+def unsupported_Group : OptionGroup<"unsupported">, Flags<[HelpHidden]>,
+ HelpText<"UNSUPPORTED ML.EXE COMPATIBILITY OPTIONS">;
+class UnsupportedFlag<string name> : Flag<["/", "-"], name>,
+ Group<unsupported_Group>;
+class UnsupportedJoined<string name> : Joined<["/", "-"], name>,
+ Group<unsupported_Group>;
+class UnsupportedJoinedOrSeparate<string name> :
+ JoinedOrSeparate<["/", "-"], name>, Group<unsupported_Group>;
+class UnsupportedSeparate<string name> : Separate<["/", "-"], name>,
+ Group<unsupported_Group>;
+
+def help : MLFlag<"?">,
+ HelpText<"Display available options">;
+def help_long : MLFlag<"help">, Alias<help>;
+def assemble_only : MLFlag<"c">, HelpText<"Assemble only; do not link">;
+def output_file : MLJoinedOrSeparate<"Fo">, HelpText<"Names the output file">;
+def include_path : MLJoinedOrSeparate<"I">,
+ HelpText<"Sets path for include files">;
+def safeseh : MLFlag<"safeseh">,
+ HelpText<"Mark resulting object files as either containing no "
+ "exception handlers or containing exception handlers "
+ "that are all declared with .SAFESEH. Only available in "
+ "32-bit.">;
+def assembly_file : MLJoinedOrSeparate<"Ta">,
+ HelpText<"Assemble source file with name not ending with "
+ "the .asm extension">;
+
+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">;
+def filetype : LLVMJoined<"filetype=">, Values<"obj,s,null">,
+ HelpText<"Emit a file with the given type">;
+def output_att_asm : LLVMFlag<"output-att-asm">,
+ HelpText<"Use ATT syntax for output assembly">;
+def show_encoding : LLVMFlag<"show-encoding">,
+ HelpText<"Show instruction encodings in output assembly">;
+def show_inst : LLVMFlag<"show-inst">,
+ HelpText<"Show internal instruction representation in output "
+ "assembly">;
+def show_inst_operands : LLVMFlag<"show-inst-operands">,
+ HelpText<"Show instructions operands as parsed">;
+def print_imm_hex : LLVMFlag<"print-imm-hex">,
+ HelpText<"Prefer hex format for immediate values in output "
+ "assembly">;
+def preserve_comments : LLVMFlag<"preserve-comments">,
+ HelpText<"Preserve comments in output assembly">;
+def save_temp_labels : LLVMFlag<"save-temp-labels">,
+ HelpText<"Don't discard temporary labels">;
+
+def tiny_model_support : UnsupportedFlag<"AT">, HelpText<"">;
+def alternate_linker : UnsupportedJoined<"Bl">, HelpText<"">;
+def coff_object_file : UnsupportedFlag<"coff">, HelpText<"">;
+def preserve_identifier_case : UnsupportedFlag<"Cp">, HelpText<"">;
+def uppercase_identifiers : UnsupportedFlag<"Cu">, HelpText<"">;
+def preserve_extern_case : UnsupportedFlag<"Cx">, HelpText<"">;
+def define : UnsupportedJoinedOrSeparate<"D">, HelpText<"">;
+def output_preprocessed : UnsupportedFlag<"EP">, HelpText<"">;
+def errorreport : UnsupportedJoined<"ERRORREPORT">, HelpText<"">;
+def stacksize : UnsupportedSeparate<"F">, HelpText<"">;
+def executable_file : UnsupportedSeparate<"Fe">, HelpText<"">;
+def code_listing_file : UnsupportedJoined<"FI">, HelpText<"">;
+def linker_map_file : UnsupportedJoined<"Fm">, HelpText<"">;
+def fp_emulator_fixups : UnsupportedFlag<"FPi">, HelpText<"">;
+def source_browser_file : UnsupportedJoined<"Fr">, HelpText<"">;
+def extended_source_browser_file : UnsupportedJoined<"FR">, HelpText<"">;
+def pascal_conventions : UnsupportedFlag<"Gc">, HelpText<"">;
+def c_conventions : UnsupportedFlag<"Gd">, HelpText<"">;
+def stdcall_conventions : UnsupportedFlag<"GZ">, HelpText<"">;
+def extern_name_limit : UnsupportedSeparate<"H">, HelpText<"">;
+def nologo : UnsupportedFlag<"nologo">, HelpText<"">;
+def omf_object_file : UnsupportedFlag<"omf">, HelpText<"">;
+def full_listing : UnsupportedFlag<"Sa">, HelpText<"">;
+def first_pass_listing : UnsupportedFlag<"Sf">, HelpText<"">;
+def listing_width : UnsupportedSeparate<"SI">, HelpText<"">;
+def listing_without_symbols : UnsupportedFlag<"Sn">, HelpText<"">;
+def listing_page_length : UnsupportedSeparate<"Sp">, HelpText<"">;
+def listing_subtitle : UnsupportedSeparate<"Ss">, HelpText<"">;
+def listing_title : UnsupportedSeparate<"St">, HelpText<"">;
+def listing_false_conditionals : UnsupportedFlag<"Sx">, HelpText<"">;
+def extra_warnings : UnsupportedFlag<"w">, HelpText<"">;
+def warning_level : UnsupportedJoined<"W">, HelpText<"">;
+def error_on_warning : UnsupportedFlag<"WX">, HelpText<"">;
+def ignore_include_envvar : UnsupportedFlag<"X">, HelpText<"">;
+def line_number_info : UnsupportedFlag<"Zd">, HelpText<"">;
+def export_all_symbols : UnsupportedFlag<"Zf">, HelpText<"">;
+def codeview_info : UnsupportedFlag<"Zi">, HelpText<"">;
+def enable_m510_option : UnsupportedFlag<"Zm">, HelpText<"">;
+def structure_packing : UnsupportedJoined<"Zp">, HelpText<"">;
+def parse_only : UnsupportedFlag<"Zs">, HelpText<"">;
diff --git a/llvm/tools/llvm-ml/llvm-ml.cpp b/llvm/tools/llvm-ml/llvm-ml.cpp
index d1ea81c20a21..ac03ef826c58 100644
--- a/llvm/tools/llvm-ml/llvm-ml.cpp
+++ b/llvm/tools/llvm-ml/llvm-ml.cpp
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-#include "Disassembler.h"
-
+#include "llvm/ADT/StringSwitch.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCCodeEmitter.h"
@@ -26,13 +25,17 @@
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCTargetOptionsCommandFlags.h"
-#include "llvm/Support/CommandLine.h"
+#include "llvm/Option/Arg.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Option/Option.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
@@ -40,131 +43,55 @@
#include "llvm/Support/WithColor.h"
using namespace llvm;
+using namespace llvm::opt;
-static mc::RegisterMCTargetOptionsFlags MOF;
-
-static cl::opt<std::string>
-InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"));
-
-static cl::opt<std::string>
-OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"),
- cl::init("-"));
-
-static cl::opt<bool>
-ShowEncoding("show-encoding", cl::desc("Show instruction encodings"));
-
-static cl::opt<bool>
-ShowInst("show-inst", cl::desc("Show internal instruction representation"));
+namespace {
-static cl::opt<bool>
-ShowInstOperands("show-inst-operands",
- cl::desc("Show instructions operands as parsed"));
-
-static cl::opt<bool>
-OutputATTAsm("output-att-asm", cl::desc("Use ATT syntax for output printing"));
-
-static cl::opt<bool>
-PrintImmHex("print-imm-hex", cl::init(false),
- cl::desc("Prefer hex format for immediate values"));
-
-static cl::opt<bool>
-PreserveComments("preserve-comments",
- cl::desc("Preserve Comments in outputted assembly"));
-
-enum OutputFileType {
- OFT_Null,
- OFT_AssemblyFile,
- OFT_ObjectFile
+enum ID {
+ OPT_INVALID = 0, // This is not an option ID.
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
+ HELPTEXT, METAVAR, VALUES) \
+ OPT_##ID,
+#include "Opts.inc"
+#undef OPTION
};
-static cl::opt<OutputFileType>
-FileType("filetype", cl::init(OFT_ObjectFile),
- cl::desc("Choose an output file type:"),
- cl::values(
- clEnumValN(OFT_AssemblyFile, "asm",
- "Emit an assembly ('.s') file"),
- clEnumValN(OFT_Null, "null",
- "Don't emit anything (for timing purposes)"),
- clEnumValN(OFT_ObjectFile, "obj",
- "Emit a native object ('.o') file")));
-
-static cl::list<std::string>
-IncludeDirs("I", cl::desc("Directory of include files"),
- cl::value_desc("directory"), cl::Prefix);
-
-enum BitnessType {
- m32,
- m64,
+
+#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
+#include "Opts.inc"
+#undef PREFIX
+
+static const opt::OptTable::Info InfoTable[] = {
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
+ HELPTEXT, METAVAR, VALUES) \
+ { \
+ PREFIX, NAME, HELPTEXT, \
+ METAVAR, OPT_##ID, opt::Option::KIND##Class, \
+ PARAM, FLAGS, OPT_##GROUP, \
+ OPT_##ALIAS, ALIASARGS, VALUES},
+#include "Opts.inc"
+#undef OPTION
};
-cl::opt<BitnessType> Bitness(cl::desc("Choose bitness:"), cl::init(m64),
- cl::values(clEnumVal(m32, "32-bit"),
- clEnumVal(m64, "64-bit (default)")));
-
-static cl::opt<bool> SafeSEH(
- "safeseh",
- cl::desc("Mark resulting object files as either containing no "
- "exception handlers or containing exception handlers that "
- "are all declared with .SAFESEH. Only available in 32-bit."));
-
-static cl::opt<std::string>
-TripleName("triple", cl::desc("Target triple to assemble for, "
- "see -version for available targets"));
-
-static cl::opt<std::string>
-DebugCompilationDir("fdebug-compilation-dir",
- cl::desc("Specifies the debug info's compilation dir"));
-
-static cl::list<std::string>
-DebugPrefixMap("fdebug-prefix-map",
- cl::desc("Map file source paths in debug info"),
- cl::value_desc("= separated key-value pairs"));
-
-static cl::opt<std::string>
-MainFileName("main-file-name",
- cl::desc("Specifies the name we should consider the input file"));
-
-static cl::opt<bool> SaveTempLabels("save-temp-labels",
- cl::desc("Don't discard temporary labels"));
-
-enum ActionType {
- AC_AsLex,
- AC_Assemble,
- AC_Disassemble,
- AC_MDisassemble,
+
+class MLOptTable : public opt::OptTable {
+public:
+ MLOptTable() : OptTable(InfoTable, /*IgnoreCase=*/false) {}
};
+} // namespace
-static cl::opt<ActionType>
-Action(cl::desc("Action to perform:"),
- cl::init(AC_Assemble),
- cl::values(clEnumValN(AC_AsLex, "as-lex",
- "Lex tokens from a .asm file"),
- clEnumValN(AC_Assemble, "assemble",
- "Assemble a .asm file (default)"),
- clEnumValN(AC_Disassemble, "disassemble",
- "Disassemble strings of hex bytes"),
- clEnumValN(AC_MDisassemble, "mdis",
- "Marked up disassembly of strings of hex bytes")));
-
-static const Target *GetTarget(const char *ProgName) {
+static Triple GetTriple(StringRef ProgName, opt::InputArgList &Args) {
// Figure out the target triple.
- if (TripleName.empty()) {
- if (Bitness == m32)
- TripleName = "i386-pc-windows";
- else if (Bitness == m64)
- TripleName = "x86_64-pc-windows";
- }
- Triple TheTriple(Triple::normalize(TripleName));
-
- // Get the target specific parser.
- std::string Error;
- const Target *TheTarget = TargetRegistry::lookupTarget("", TheTriple, Error);
- if (!TheTarget) {
- WithColor::error(errs(), ProgName) << Error;
- return nullptr;
- }
-
- // Update the triple name and return the found target.
- TripleName = TheTriple.getTriple();
- return TheTarget;
+ StringRef DefaultBitness = "32";
+ SmallString<255> Program = ProgName;
+ sys::path::replace_extension(Program, "");
+ if (Program.endswith("ml64"))
+ DefaultBitness = "64";
+
+ StringRef TripleName =
+ StringSwitch<StringRef>(Args.getLastArgValue(OPT_bitness, DefaultBitness))
+ .Case("32", "i386-pc-windows")
+ .Case("64", "x86_64-pc-windows")
+ .Default("");
+ return Triple(Triple::normalize(TripleName));
}
static std::unique_ptr<ToolOutputFile> GetOutputStream(StringRef Path) {
@@ -197,10 +124,11 @@ static int AsLexInput(SourceMgr &SrcMgr, MCAsmInfo &MAI, raw_ostream &OS) {
return Error;
}
-static int AssembleInput(const char *ProgName, const Target *TheTarget,
+static int AssembleInput(StringRef ProgName, const Target *TheTarget,
SourceMgr &SrcMgr, MCContext &Ctx, MCStreamer &Str,
MCAsmInfo &MAI, MCSubtargetInfo &STI,
- MCInstrInfo &MCII, MCTargetOptions &MCOptions) {
+ MCInstrInfo &MCII, MCTargetOptions &MCOptions,
+ const opt::ArgList &InputArgs) {
std::unique_ptr<MCAsmParser> Parser(
createMCMasmParser(SrcMgr, Ctx, Str, MAI, 0));
std::unique_ptr<MCTargetAsmParser> TAP(
@@ -212,7 +140,7 @@ static int AssembleInput(const char *ProgName, const Target *TheTarget,
return 1;
}
- Parser->setShowParsedOperands(ShowInstOperands);
+ Parser->setShowParsedOperands(InputArgs.hasArg(OPT_show_inst_operands));
Parser->setTargetParser(*TAP);
Parser->getLexer().setLexMasmIntegers(true);
Parser->getLexer().useMasmDefaultRadix(true);
@@ -224,8 +152,9 @@ static int AssembleInput(const char *ProgName, const Target *TheTarget,
return Res;
}
-int main(int argc, char **argv) {
- InitLLVM X(argc, argv);
+int main(int Argc, char **Argv) {
+ InitLLVM X(Argc, Argv);
+ StringRef ProgName = sys::path::filename(Argv[0]);
// Initialize targets and assembly printers/parsers.
llvm::InitializeAllTargetInfos();
@@ -233,21 +162,75 @@ int main(int argc, char **argv) {
llvm::InitializeAllAsmParsers();
llvm::InitializeAllDisassemblers();
- // Register the target printer for --version.
- cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
+ MLOptTable T;
+ unsigned MissingArgIndex, MissingArgCount;
+ ArrayRef<const char *> ArgsArr = makeArrayRef(Argv + 1, Argc - 1);
+ opt::InputArgList InputArgs =
+ T.ParseArgs(ArgsArr, MissingArgIndex, MissingArgCount);
+
+ std::string InputFilename;
+ for (auto *Arg : InputArgs.filtered(OPT_INPUT)) {
+ std::string ArgString = Arg->getAsString(InputArgs);
+ if (ArgString == "-" || StringRef(ArgString).endswith(".asm")) {
+ if (!InputFilename.empty()) {
+ WithColor::warning(errs(), ProgName)
+ << "does not support multiple assembly files in one command; "
+ << "ignoring '" << InputFilename << "'\n";
+ }
+ InputFilename = ArgString;
+ } else {
+ std::string Diag;
+ raw_string_ostream OS(Diag);
+ OS << "invalid option '" << ArgString << "'";
+
+ std::string Nearest;
+ if (T.findNearest(ArgString, Nearest) < 2)
+ OS << ", did you mean '" << Nearest << "'?";
+
+ WithColor::error(errs(), ProgName) << OS.str() << '\n';
+ exit(1);
+ }
+ }
+ for (auto *Arg : InputArgs.filtered(OPT_assembly_file)) {
+ if (!InputFilename.empty()) {
+ WithColor::warning(errs(), ProgName)
+ << "does not support multiple assembly files in one command; "
+ << "ignoring '" << InputFilename << "'\n";
+ }
+ InputFilename = Arg->getAsString(InputArgs);
+ }
+
+ for (auto *Arg : InputArgs.filtered(OPT_unsupported_Group)) {
+ WithColor::warning(errs(), ProgName)
+ << "ignoring unsupported '" << Arg->getOption().getName()
+ << "' option\n";
+ }
+
+ if (InputArgs.hasArg(OPT_help)) {
+ std::string Usage = llvm::formatv("{0} [ /options ] file", ProgName).str();
+ T.PrintHelp(outs(), Usage.c_str(), "LLVM MASM Assembler",
+ /*ShowHidden=*/false);
+ return 0;
+ } else if (InputFilename.empty()) {
+ outs() << "USAGE: " << ProgName << " [ /options ] file\n"
+ << "Run \"" << ProgName << " /?\" or \"" << ProgName
+ << " /help\" for more info.\n";
+ return 0;
+ }
- cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n");
- MCTargetOptions MCOptions = mc::InitMCTargetOptionsFromFlags();
+ MCTargetOptions MCOptions;
MCOptions.AssemblyLanguage = "masm";
- const char *ProgName = argv[0];
- const Target *TheTarget = GetTarget(ProgName);
- if (!TheTarget)
+ Triple TheTriple = GetTriple(ProgName, InputArgs);
+ std::string Error;
+ const Target *TheTarget = TargetRegistry::lookupTarget("", TheTriple, Error);
+ if (!TheTarget) {
+ WithColor::error(errs(), ProgName) << Error;
return 1;
- // Now that GetTarget() has (potentially) replaced TripleName, it's safe to
- // construct the Triple object.
- Triple TheTriple(TripleName);
+ }
+ const std::string &TripleName = TheTriple.getTriple();
+ bool SafeSEH = InputArgs.hasArg(OPT_safeseh);
if (SafeSEH && !(TheTriple.isArch32Bit() && TheTriple.isX86())) {
WithColor::warning()
<< "/safeseh applies only to 32-bit X86 platforms; ignoring.\n";
@@ -261,7 +244,6 @@ int main(int argc, char **argv) {
<< InputFilename << ": " << EC.message() << '\n';
return 1;
}
- MemoryBuffer *Buffer = BufferPtr->get();
SourceMgr SrcMgr;
@@ -270,7 +252,7 @@ int main(int argc, char **argv) {
// Record the location of the include directories so that the lexer can find
// it later.
- SrcMgr.setIncludeDirs(IncludeDirs);
+ SrcMgr.setIncludeDirs(InputArgs.getAllArgValues(OPT_include_path));
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
assert(MRI && "Unable to create target register info!");
@@ -279,7 +261,7 @@ int main(int argc, char **argv) {
TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
assert(MAI && "Unable to create target asm info!");
- MAI->setPreserveAsmComments(PreserveComments);
+ MAI->setPreserveAsmComments(InputArgs.hasArg(OPT_preserve_comments));
// FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
@@ -288,24 +270,25 @@ int main(int argc, char **argv) {
MOFI.InitMCObjectFileInfo(TheTriple, /*PIC=*/false, Ctx,
/*LargeCodeModel=*/true);
- if (SaveTempLabels)
+ if (InputArgs.hasArg(OPT_save_temp_labels))
Ctx.setAllowTemporaryLabels(false);
- if (!DebugCompilationDir.empty()) {
- Ctx.setCompilationDir(DebugCompilationDir);
+ // Set compilation information.
+ SmallString<128> CWD;
+ if (!sys::fs::current_path(CWD))
+ Ctx.setCompilationDir(CWD);
+ Ctx.setMainFileName(InputFilename);
+
+ StringRef FileType = InputArgs.getLastArgValue(OPT_filetype, "obj");
+ SmallString<255> DefaultOutputFilename;
+ if (InputArgs.hasArg(OPT_as_lex)) {
+ DefaultOutputFilename = "-";
} else {
- // If no compilation dir is set, try to use the current directory.
- SmallString<128> CWD;
- if (!sys::fs::current_path(CWD))
- Ctx.setCompilationDir(CWD);
- }
- for (const auto &Arg : DebugPrefixMap) {
- const auto &KV = StringRef(Arg).split('=');
- Ctx.addDebugPrefixMapEntry(std::string(KV.first), std::string(KV.second));
+ DefaultOutputFilename = InputFilename;
+ sys::path::replace_extension(DefaultOutputFilename, FileType);
}
- if (!MainFileName.empty())
- Ctx.setMainFileName(MainFileName);
-
+ const StringRef OutputFilename =
+ InputArgs.getLastArgValue(OPT_output_file, DefaultOutputFilename);
std::unique_ptr<ToolOutputFile> Out = GetOutputStream(OutputFilename);
if (!Out)
return 1;
@@ -322,11 +305,12 @@ int main(int argc, char **argv) {
assert(STI && "Unable to create subtarget info!");
MCInstPrinter *IP = nullptr;
- if (FileType == OFT_AssemblyFile) {
+ if (FileType == "s") {
+ const bool OutputATTAsm = InputArgs.hasArg(OPT_output_att_asm);
const unsigned OutputAsmVariant = OutputATTAsm ? 0U // ATT dialect
: 1U; // Intel dialect
- IP = TheTarget->createMCInstPrinter(Triple(TripleName), OutputAsmVariant,
- *MAI, *MCII, *MRI);
+ IP = TheTarget->createMCInstPrinter(TheTriple, OutputAsmVariant, *MAI,
+ *MCII, *MRI);
if (!IP) {
WithColor::error()
@@ -337,26 +321,24 @@ int main(int argc, char **argv) {
}
// Set the display preference for hex vs. decimal immediates.
- IP->setPrintImmHex(PrintImmHex);
+ IP->setPrintImmHex(InputArgs.hasArg(OPT_print_imm_hex));
// Set up the AsmStreamer.
std::unique_ptr<MCCodeEmitter> CE;
- if (ShowEncoding)
+ if (InputArgs.hasArg(OPT_show_encoding))
CE.reset(TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx));
std::unique_ptr<MCAsmBackend> MAB(
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
auto FOut = std::make_unique<formatted_raw_ostream>(*OS);
- Str.reset(
- TheTarget->createAsmStreamer(Ctx, std::move(FOut), /*asmverbose*/ true,
- /*useDwarfDirectory*/ true, IP,
- std::move(CE), std::move(MAB), ShowInst));
+ Str.reset(TheTarget->createAsmStreamer(
+ Ctx, std::move(FOut), /*asmverbose*/ true,
+ /*useDwarfDirectory*/ true, IP, std::move(CE), std::move(MAB),
+ InputArgs.hasArg(OPT_show_inst)));
- } else if (FileType == OFT_Null) {
+ } else if (FileType == "null") {
Str.reset(TheTarget->createNullStreamer(Ctx));
- } else {
- assert(FileType == OFT_ObjectFile && "Invalid file type!");
-
+ } else if (FileType == "obj") {
if (!Out->os().supportsSeeking()) {
BOS = std::make_unique<buffer_ostream>(Out->os());
OS = BOS.get();
@@ -369,6 +351,8 @@ int main(int argc, char **argv) {
MAB->createObjectWriter(*OS), std::unique_ptr<MCCodeEmitter>(CE), *STI,
MCOptions.MCRelaxAll, MCOptions.MCIncrementalLinkerCompatible,
/*DWARFMustBeAtTheEnd*/ false));
+ } else {
+ llvm_unreachable("Invalid file type!");
}
if (TheTriple.isOSBinFormatCOFF()) {
@@ -392,27 +376,13 @@ int main(int argc, char **argv) {
Str->setUseAssemblerInfoForParsing(true);
int Res = 1;
- bool disassemble = false;
- switch (Action) {
- case AC_AsLex:
+ if (InputArgs.hasArg(OPT_as_lex)) {
+ // -as-lex; Lex only, and output a stream of tokens
Res = AsLexInput(SrcMgr, *MAI, Out->os());
- break;
- case AC_Assemble:
+ } else {
Res = AssembleInput(ProgName, TheTarget, SrcMgr, Ctx, *Str, *MAI, *STI,
- *MCII, MCOptions);
- break;
- case AC_MDisassemble:
- assert(IP && "Expected assembly output");
- IP->setUseMarkup(1);
- disassemble = true;
- break;
- case AC_Disassemble:
- disassemble = true;
- break;
+ *MCII, MCOptions, InputArgs);
}
- if (disassemble)
- Res = Disassembler::disassemble(*TheTarget, TripleName, *STI, *Str, *Buffer,
- SrcMgr, Out->os());
// Keep output if no errors.
if (Res == 0)