]> granicus.if.org Git - clang/commitdiff
[Driver] -print-target-triple and -print-effective-triple options
authorPetr Hosek <phosek@chromium.org>
Thu, 16 Aug 2018 00:22:03 +0000 (00:22 +0000)
committerPetr Hosek <phosek@chromium.org>
Thu, 16 Aug 2018 00:22:03 +0000 (00:22 +0000)
These can be used to print Clang target and effective triple.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339834 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Options.td
lib/Driver/Driver.cpp
test/Driver/print-effective-triple.c [new file with mode: 0644]
test/Driver/print-target-triple.c [new file with mode: 0644]

index 601aa8744967ba5eb5fa4556edd32a3e0889315e..18781849bffaf11b55f93dd4a4059d71ebe73e7b 100644 (file)
@@ -2348,6 +2348,10 @@ def print_multi_directory : Flag<["-", "--"], "print-multi-directory">;
 def print_multi_lib : Flag<["-", "--"], "print-multi-lib">;
 def print_multi_os_directory : Flag<["-", "--"], "print-multi-os-directory">,
   Flags<[Unsupported]>;
+def print_target_triple : Flag<["-", "--"], "print-target-triple">,
+  HelpText<"Print the normalized target triple">;
+def print_effective_triple : Flag<["-", "--"], "print-effective-triple">,
+  HelpText<"Print the effective target triple">;
 def print_prog_name_EQ : Joined<["-", "--"], "print-prog-name=">,
   HelpText<"Print the full program path of <name>">, MetaVarName<"<name>">;
 def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
index 952a716cb6e61948ac42f576ac4944b0f38c32e2..350ee0e39dc507fbfa8f770fafcd79177f2aa5e0 100644 (file)
@@ -1672,6 +1672,18 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
     }
     return false;
   }
+
+  if (C.getArgs().hasArg(options::OPT_print_target_triple)) {
+    llvm::outs() << TC.getTripleString() << "\n";
+    return false;
+  }
+
+  if (C.getArgs().hasArg(options::OPT_print_effective_triple)) {
+    const llvm::Triple Triple(TC.ComputeEffectiveClangTriple(C.getArgs()));
+    llvm::outs() << Triple.getTriple() << "\n";
+    return false;
+  }
+
   return true;
 }
 
diff --git a/test/Driver/print-effective-triple.c b/test/Driver/print-effective-triple.c
new file mode 100644 (file)
index 0000000..65b3874
--- /dev/null
@@ -0,0 +1,6 @@
+// Test that -print-target-triple prints correct triple.
+
+// RUN: %clang -print-effective-triple 2>&1 \
+// RUN:     --target=thumb-linux-gnu \
+// RUN:   | FileCheck %s
+// CHECK: armv4t-unknown-linux-gnu
diff --git a/test/Driver/print-target-triple.c b/test/Driver/print-target-triple.c
new file mode 100644 (file)
index 0000000..70b2493
--- /dev/null
@@ -0,0 +1,6 @@
+// Test that -print-target-triple prints correct triple.
+
+// RUN: %clang -print-target-triple 2>&1 \
+// RUN:     --target=x86_64-linux-gnu \
+// RUN:   | FileCheck %s
+// CHECK: x86_64-unknown-linux-gnu