r339834 - [Driver] -print-target-triple and -print-effective-triple options

Petr Hosek via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 15 17:22:04 PDT 2018


Author: phosek
Date: Wed Aug 15 17:22:03 2018
New Revision: 339834

URL: http://llvm.org/viewvc/llvm-project?rev=339834&view=rev
Log:
[Driver] -print-target-triple and -print-effective-triple options

These can be used to print Clang target and effective triple.

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

Added:
    cfe/trunk/test/Driver/print-effective-triple.c
    cfe/trunk/test/Driver/print-target-triple.c
Modified:
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=339834&r1=339833&r2=339834&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Aug 15 17:22:03 2018
@@ -2348,6 +2348,10 @@ def print_multi_directory : Flag<["-", "
 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">,

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=339834&r1=339833&r2=339834&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Aug 15 17:22:03 2018
@@ -1672,6 +1672,18 @@ bool Driver::HandleImmediateArgs(const 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;
 }
 

Added: cfe/trunk/test/Driver/print-effective-triple.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/print-effective-triple.c?rev=339834&view=auto
==============================================================================
--- cfe/trunk/test/Driver/print-effective-triple.c (added)
+++ cfe/trunk/test/Driver/print-effective-triple.c Wed Aug 15 17:22:03 2018
@@ -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

Added: cfe/trunk/test/Driver/print-target-triple.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/print-target-triple.c?rev=339834&view=auto
==============================================================================
--- cfe/trunk/test/Driver/print-target-triple.c (added)
+++ cfe/trunk/test/Driver/print-target-triple.c Wed Aug 15 17:22:03 2018
@@ -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




More information about the cfe-commits mailing list