diff --git a/llvm/include/llvm/Support/Host.h b/llvm/include/llvm/Support/Host.h --- a/llvm/include/llvm/Support/Host.h +++ b/llvm/include/llvm/Support/Host.h @@ -19,6 +19,7 @@ class MallocAllocator; class StringRef; template class StringMap; +class raw_ostream; namespace sys { @@ -54,6 +55,10 @@ /// \return - True on success. bool getHostCPUFeatures(StringMap &Features); + /// This is a function compatible with cl::AddExtraVersionPrinter, which adds + /// info about the current target triple and detected CPU. + void printDefaultTargetAndDetectedCPU(raw_ostream &OS); + namespace detail { /// Helper functions to extract HostCPUName from /proc/cpuinfo on linux. StringRef getHostCPUNameForPowerPC(StringRef ProcCpuinfoContent); diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -28,7 +28,6 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" -#include "llvm/ADT/Triple.h" #include "llvm/ADT/Twine.h" #include "llvm/Config/config.h" #include "llvm/Support/ConvertUTF.h" @@ -36,7 +35,6 @@ #include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" -#include "llvm/Support/Host.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" @@ -1341,9 +1339,11 @@ bool cl::expandResponseFiles(int Argc, const char *const *Argv, const char *EnvVar, StringSaver &Saver, SmallVectorImpl &NewArgv) { - auto Tokenize = Triple(sys::getProcessTriple()).isOSWindows() - ? cl::TokenizeWindowsCommandLine - : cl::TokenizeGNUCommandLine; +#ifdef _WIN32 + auto Tokenize = cl::TokenizeWindowsCommandLine; +#else + auto Tokenize = cl::TokenizeGNUCommandLine; +#endif // The environment variable specifies initial options. if (EnvVar) if (llvm::Optional EnvValue = sys::Process::GetEnv(EnvVar)) @@ -1487,9 +1487,12 @@ // Expand response files. SmallVector newArgv(argv, argv + argc); BumpPtrAllocator A; - ExpansionContext ECtx(A, Triple(sys::getProcessTriple()).isOSWindows() - ? cl::TokenizeWindowsCommandLine - : cl::TokenizeGNUCommandLine); +#ifdef _WIN32 + auto Tokenize = cl::TokenizeWindowsCommandLine; +#else + auto Tokenize = cl::TokenizeGNUCommandLine; +#endif + ExpansionContext ECtx(A, Tokenize); if (Error Err = ECtx.expandResponseFiles(newArgv)) { *Errs << toString(std::move(Err)) << '\n'; return false; @@ -2517,6 +2520,8 @@ namespace { class VersionPrinter { + std::vector ExtraPrinters; + public: void print() { raw_ostream &OS = outs(); @@ -2533,18 +2538,21 @@ #endif #ifndef NDEBUG OS << " with assertions"; -#endif -#if LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO - std::string CPU = std::string(sys::getHostCPUName()); - if (CPU == "generic") - CPU = "(unknown)"; - OS << ".\n" - << " Default target: " << sys::getDefaultTargetTriple() << '\n' - << " Host CPU: " << CPU; #endif OS << '\n'; + + // Iterate over any registered extra printers and call them to add further + // information. + if (!ExtraPrinters.empty()) { + outs() << '\n'; + for (const auto &I : ExtraPrinters) + I(outs()); + } } void operator=(bool OptionWasSpecified); + void addExtraVersionPrinter(VersionPrinterTy Func) { + ExtraPrinters.push_back(Func); + } }; struct CommandLineCommonOptions { @@ -2626,8 +2634,6 @@ VersionPrinterTy OverrideVersionPrinter = nullptr; - std::vector ExtraVersionPrinters; - // Define the --version option that prints out the LLVM version for the tool VersionPrinter VersionPrinterInstance; @@ -2671,14 +2677,6 @@ } print(); - // Iterate over any registered extra printers and call them to add further - // information. - if (!CommonOptions->ExtraVersionPrinters.empty()) { - outs() << '\n'; - for (const auto &I : CommonOptions->ExtraVersionPrinters) - I(outs()); - } - exit(0); } @@ -2739,8 +2737,8 @@ CommonOptions->OverrideVersionPrinter = func; } -void cl::AddExtraVersionPrinter(VersionPrinterTy func) { - CommonOptions->ExtraVersionPrinters.push_back(func); +void cl::AddExtraVersionPrinter(VersionPrinterTy Func) { + CommonOptions->VersionPrinterInstance.addExtraVersionPrinter(Func); } StringMap