[cfe-commits] [PATCH] [clang] add --supported-targets option for clang
Saleem Abdulrasool
compnerd at compnerd.org
Thu Dec 20 23:25:12 PST 2012
Add a new driver-only option `--supported-targets` which enumerates the supported targets to stdout. This is an often requested feature, allowing for a quick inspection of supported target architectures supported by a particular build of clang.
http://llvm-reviews.chandlerc.com/D233
Files:
include/clang/Driver/Options.td
lib/Driver/Driver.cpp
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1142,6 +1142,8 @@
HelpText<"Serialize compiler diagnostics to a file">;
// We give --version different semantics from -version.
def _version : Flag<["--"], "version">, Flags<[CC1Option]>;
+def _supported_targets : Flag<["--"], "supported-targets">,
+ Flags<[DriverOption]>, HelpText<"Display supported targets">;
def _signed_char : Flag<["--"], "signed-char">, Alias<fsigned_char>;
def _std : Separate<["--"], "std">, Alias<std_EQ>;
def _stdlib : Separate<["--"], "stdlib">, Alias<stdlib_EQ>;
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -27,9 +27,11 @@
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Host.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Program.h"
+#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h"
#include <map>
@@ -628,6 +630,34 @@
return false;
}
+ if (C.getArgs().hasArg(options::OPT__supported_targets)) {
+ std::string CPU = llvm::sys::getHostCPUName();
+ llvm::raw_ostream &OS = llvm::outs();
+ llvm::TargetRegistry Registry;
+
+ if (CPU == "generic")
+ CPU = "(unknown)";
+
+ OS << getClangFullVersion() << " ("
+#if defined(__OPTIMIZE__)
+ << "optimized"
+#else
+ << "debug"
+#endif
+#if !defined(NDEBUG)
+ << "+asserts"
+#endif
+ << ")\n"
+ << "Host CPU: " << CPU << "\n"
+ << "Default Target: " << llvm::sys::getDefaultTargetTriple() << "\n"
+ << "Supported Target Architectures:\n";
+ for (llvm::TargetRegistry::iterator TI = Registry.begin(),
+ TE = Registry.end(); TI != TE; ++TI)
+ OS << "\t" << TI->getName() << "\n";
+
+ return false;
+ }
+
if (C.getArgs().hasArg(options::OPT_v) ||
C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
PrintVersion(C, llvm::errs());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D233.1.patch
Type: text/x-patch
Size: 2217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121220/5dadf9e1/attachment.bin>
More information about the cfe-commits
mailing list