phosek created this revision. phosek added reviewers: hans, rnk, echristo. Herald added a subscriber: cfe-commits.
While this value is initialized with the DefaultTargetTriple, it can be later overriden using the -target flag so TargetTriple is a more accurate name. This change also provides an accessor which could be accessed from ToolChain implementations. Repository: rC Clang https://reviews.llvm.org/D47357 Files: clang/include/clang/Driver/Driver.h clang/lib/Driver/Driver.cpp
Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -84,7 +84,7 @@ using namespace clang; using namespace llvm::opt; -Driver::Driver(StringRef ClangExecutable, StringRef DefaultTargetTriple, +Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple, DiagnosticsEngine &Diags, IntrusiveRefCntPtr<vfs::FileSystem> VFS) : Opts(createDriverOptTable()), Diags(Diags), VFS(std::move(VFS)), @@ -94,7 +94,7 @@ CCPrintOptionsFilename(nullptr), CCPrintHeadersFilename(nullptr), CCLogDiagnosticsFilename(nullptr), CCCPrintBindings(false), CCPrintOptions(false), CCPrintHeaders(false), CCLogDiagnostics(false), - CCGenDiagnostics(false), DefaultTargetTriple(DefaultTargetTriple), + CCGenDiagnostics(false), TargetTriple(TargetTriple), CCCGenericGCCName(""), Saver(Alloc), CheckInputsExist(true), CCCUsePCH(true), GenReproducer(false), SuppressMissingInputWarning(false) { @@ -388,14 +388,14 @@ /// This routine provides the logic to compute a target triple from various /// args passed to the driver and the default triple string. static llvm::Triple computeTargetTriple(const Driver &D, - StringRef DefaultTargetTriple, + StringRef TargetTriple, const ArgList &Args, StringRef DarwinArchName = "") { // FIXME: Already done in Compilation *Driver::BuildCompilation if (const Arg *A = Args.getLastArg(options::OPT_target)) - DefaultTargetTriple = A->getValue(); + TargetTriple = A->getValue(); - llvm::Triple Target(llvm::Triple::normalize(DefaultTargetTriple)); + llvm::Triple Target(llvm::Triple::normalize(TargetTriple)); // Handle Apple-specific options available here. if (Target.isOSBinFormatMachO()) { @@ -941,19 +941,19 @@ GenReproducer = Args.hasFlag(options::OPT_gen_reproducer, options::OPT_fno_crash_diagnostics, !!::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH")); - // FIXME: DefaultTargetTriple is used by the target-prefixed calls to as/ld + // FIXME: TargetTriple is used by the target-prefixed calls to as/ld // and getToolChain is const. if (IsCLMode()) { // clang-cl targets MSVC-style Win32. - llvm::Triple T(DefaultTargetTriple); + llvm::Triple T(TargetTriple); T.setOS(llvm::Triple::Win32); T.setVendor(llvm::Triple::PC); T.setEnvironment(llvm::Triple::MSVC); T.setObjectFormat(llvm::Triple::COFF); - DefaultTargetTriple = T.str(); + TargetTriple = T.str(); } if (const Arg *A = Args.getLastArg(options::OPT_target)) - DefaultTargetTriple = A->getValue(); + TargetTriple = A->getValue(); if (const Arg *A = Args.getLastArg(options::OPT_ccc_install_dir)) Dir = InstalledDir = A->getValue(); for (const Arg *A : Args.filtered(options::OPT_B)) { @@ -1001,7 +1001,7 @@ // Owned by the host. const ToolChain &TC = getToolChain( - *UArgs, computeTargetTriple(*this, DefaultTargetTriple, *UArgs)); + *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs)); // The compilation takes ownership of Args. Compilation *C = new Compilation(*this, TC, UArgs.release(), TranslatedArgs, @@ -3665,7 +3665,7 @@ if (!ArchName.empty()) TC = &getToolChain(C.getArgs(), - computeTargetTriple(*this, DefaultTargetTriple, + computeTargetTriple(*this, TargetTriple, C.getArgs(), ArchName)); else TC = &C.getDefaultToolChain(); @@ -3834,7 +3834,7 @@ } const char *Driver::getDefaultImageName() const { - llvm::Triple Target(llvm::Triple::normalize(DefaultTargetTriple)); + llvm::Triple Target(llvm::Triple::normalize(TargetTriple)); return Target.isOSWindows() ? "a.exe" : "a.out"; } @@ -4073,14 +4073,14 @@ void Driver::generatePrefixedToolNames( StringRef Tool, const ToolChain &TC, SmallVectorImpl<std::string> &Names) const { - // FIXME: Needs a better variable than DefaultTargetTriple - Names.emplace_back((DefaultTargetTriple + "-" + Tool).str()); + // FIXME: Needs a better variable than TargetTriple + Names.emplace_back((TargetTriple + "-" + Tool).str()); Names.emplace_back(Tool); // Allow the discovery of tools prefixed with LLVM's default target triple. - std::string LLVMDefaultTargetTriple = llvm::sys::getDefaultTargetTriple(); - if (LLVMDefaultTargetTriple != DefaultTargetTriple) - Names.emplace_back((LLVMDefaultTargetTriple + "-" + Tool).str()); + std::string DefaultTargetTriple = llvm::sys::getDefaultTargetTriple(); + if (DefaultTargetTriple != TargetTriple) + Names.emplace_back((DefaultTargetTriple + "-" + Tool).str()); } static bool ScanDirForExecutable(SmallString<128> &Dir, Index: clang/include/clang/Driver/Driver.h =================================================================== --- clang/include/clang/Driver/Driver.h +++ clang/include/clang/Driver/Driver.h @@ -202,8 +202,8 @@ unsigned CCGenDiagnostics : 1; private: - /// Default target triple. - std::string DefaultTargetTriple; + /// Raw target triple. + std::string TargetTriple; /// Name to use when invoking gcc/g++. std::string CCCGenericGCCName; @@ -282,7 +282,7 @@ SmallString<128> &CrashDiagDir); public: - Driver(StringRef ClangExecutable, StringRef DefaultTargetTriple, + Driver(StringRef ClangExecutable, StringRef TargetTriple, DiagnosticsEngine &Diags, IntrusiveRefCntPtr<vfs::FileSystem> VFS = nullptr); @@ -309,6 +309,8 @@ const std::string &getTitle() { return DriverTitle; } void setTitle(std::string Value) { DriverTitle = std::move(Value); } + std::string getTargetTriple() const { return TargetTriple; } + /// Get the path to the main clang executable. const char *getClangProgramPath() const { return ClangExecutable.c_str();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits