Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: lib/Driver/ToolChains.cpp

Issue 1547623002: Clang toolchain driver for PNaCl (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-clang.git@master
Patch Set: Review feedback addressed Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===--- ToolChains.cpp - ToolChain Implementations -----------------------===// 1 //===--- ToolChains.cpp - ToolChain Implementations -----------------------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 9
10 #include "ToolChains.h" 10 #include "ToolChains.h"
(...skipping 3694 matching lines...) Expand 10 before | Expand all | Expand 10 after
3705 StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr)); 3705 StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
3706 ArrayRef<StringRef> DirVec(Dirs); 3706 ArrayRef<StringRef> DirVec(Dirs);
3707 addSystemIncludes(DriverArgs, CC1Args, DirVec); 3707 addSystemIncludes(DriverArgs, CC1Args, DirVec);
3708 } 3708 }
3709 } 3709 }
3710 3710
3711 void XCore::AddCXXStdlibLibArgs(const ArgList &Args, 3711 void XCore::AddCXXStdlibLibArgs(const ArgList &Args,
3712 ArgStringList &CmdArgs) const { 3712 ArgStringList &CmdArgs) const {
3713 // We don't output any lib args. This is handled by xcc. 3713 // We don't output any lib args. This is handled by xcc.
3714 } 3714 }
3715
3716 /// Generic_BC Toolchain
3717
3718 Generic_BC::Generic_BC(const Driver &D, const llvm::Triple &Triple,
3719 const ArgList &Args)
3720 : ToolChain(D, Triple, Args) {
3721 getProgramPaths().push_back(getDriver().getInstalledDir());
3722 if (getDriver().getInstalledDir() != getDriver().Dir)
3723 getProgramPaths().push_back(getDriver().Dir);
3724 }
3725
3726 void Generic_BC::anchor() {}
3727
3728 /// PNaCl ToolChain
3729
3730 PNaClToolChain::PNaClToolChain(const Driver &D, const llvm::Triple &Triple,
3731 const ArgList &Args)
3732 : Generic_BC(D, Triple, Args) {
3733 std::string SysRoot = computeSysRoot();
3734
3735 getFilePaths().push_back(SysRoot + "/lib");
3736 getFilePaths().push_back(SysRoot + "/usr/lib");
3737
3738 getFilePaths().push_back(D.ResourceDir + "/lib/le32-nacl");
3739 }
3740
3741 Tool *PNaClToolChain::buildLinker() const {
3742 return new tools::pnacltools::Link(*this);
3743 }
3744
3745 Tool *PNaClToolChain::buildAssembler() const {
3746 assert(false && "cannot build assembler");
Derek Schuff 2016/02/24 18:22:29 actually, use llvm_unreachable instead of assert(f
Petr Hosek 2016/02/26 00:43:38 Done.
3747 return nullptr;
3748 }
3749
3750 std::string PNaClToolChain::computeSysRoot() const {
3751 if (!getDriver().SysRoot.empty())
3752 return getDriver().SysRoot;
3753
3754 return getDriver().Dir + "/../le32-nacl";
3755 }
3756
3757 void PNaClToolChain::AddLinkRuntimeLibArgs(const ArgList &Args,
3758 ArgStringList &CmdArgs) const {
3759 CmdArgs.push_back("-lnacl");
3760 CmdArgs.push_back("-lpnaclmm");
3761 }
3762
3763 ToolChain::CXXStdlibType PNaClToolChain::GetCXXStdlibType(const ArgList &Args) c onst {
3764 Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
3765 if (!A)
3766 return ToolChain::CST_Libcxx;
3767
3768 StringRef Value = A->getValue();
3769 if (Value != "libc++") {
3770 getDriver().Diag(diag::err_drv_invalid_stdlib_name)
3771 << A->getAsString(Args);
3772 }
3773
3774 return ToolChain::CST_Libcxx;
3775 }
3776
3777 void PNaClToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
3778 ArgStringList &CC1Args) const {
3779 const Driver &D = getDriver();
3780 std::string SysRoot = computeSysRoot();
3781
3782 if (DriverArgs.hasArg(options::OPT_nostdinc))
3783 return;
3784
3785 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
3786 SmallString<128> P(D.ResourceDir);
3787 llvm::sys::path::append(P, "include");
3788 addSystemInclude(DriverArgs, CC1Args, P.str());
3789 }
3790
3791 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
3792 return;
3793
3794 // Check for configure-time C include directories.
3795 StringRef CIncludeDirs(C_INCLUDE_DIRS);
3796 if (CIncludeDirs != "") {
3797 SmallVector<StringRef, 5> dirs;
3798 CIncludeDirs.split(dirs, ":");
3799 for (StringRef dir : dirs) {
3800 StringRef Prefix =
3801 llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : "";
3802 addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
3803 }
3804 return;
3805 }
3806
3807 // Add an include of '/include' directly. This isn't provided by default by
3808 // system GCCs, but is often used with cross-compiling GCCs, and harmless to
3809 // add even when Clang is acting as-if it were a system compiler.
3810 addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include");
3811
3812 addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
3813 }
3814
3815 void PNaClToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
3816 ArgStringList &CC1Args) const {
3817 if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
3818 DriverArgs.hasArg(options::OPT_nostdincxx))
3819 return;
3820
3821 // Check for -stdlib= flags. We only support libc++ but this consumes the arg
3822 // if the value is libc++, and emits an error for other values.
3823 GetCXXStdlibType(DriverArgs);
3824
3825 const std::string LibCXXIncludePathCandidates[] = {
3826 // The primary location is within the Clang installation.
3827 getDriver().Dir + "/../include/c++/v1",
3828
3829 // We also check the system as for a long time this is the only place Clang looked.
3830 getDriver().SysRoot + "/usr/include/c++/v1"
3831 };
3832 for (const auto &IncludePath : LibCXXIncludePathCandidates) {
3833 if (!llvm::sys::fs::exists(IncludePath))
3834 continue;
3835 // Add the first candidate that exists.
3836 addSystemInclude(DriverArgs, CC1Args, IncludePath);
3837 break;
3838 }
3839 return;
3840 }
3841
3842 void PNaClToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
3843 ArgStringList &CmdArgs) const {
3844 switch (GetCXXStdlibType(Args)) {
3845 case ToolChain::CST_Libcxx:
3846 CmdArgs.push_back("-lc++");
3847 break;
3848 case ToolChain::CST_Libstdcxx:
3849 break;
3850 }
3851 }
3852
3853 void PNaClToolChain::addClangTargetOptions(const ArgList &DriverArgs,
3854 ArgStringList &CC1Args) const {
3855 if (DriverArgs.hasFlag(options::OPT_fuse_init_array,
3856 options::OPT_fno_use_init_array,
3857 getTriple().getOS() == llvm::Triple::NaCl))
3858 CC1Args.push_back("-fuse-init-array");
3859 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698