OLD | NEW |
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 Loading... |
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 /// PNaCl ToolChain |
| 3727 |
| 3728 PNaClToolChain::PNaClToolChain(const Driver &D, const llvm::Triple &Triple, |
| 3729 const ArgList &Args) |
| 3730 : Generic_BC(D, Triple, Args) { |
| 3731 std::string SysRoot = computeSysRoot(); |
| 3732 |
| 3733 getFilePaths().push_back(SysRoot + "/lib"); |
| 3734 getFilePaths().push_back(SysRoot + "/usr/lib"); |
| 3735 |
| 3736 getFilePaths().push_back(D.ResourceDir + "/lib/le32-nacl"); |
| 3737 } |
| 3738 |
| 3739 Tool *PNaClToolChain::buildLinker() const { |
| 3740 return new tools::pnacltools::Link(*this); |
| 3741 } |
| 3742 |
| 3743 Tool *PNaClToolChain::buildAssembler() const { |
| 3744 llvm_unreachable("cannot build assembler"); |
| 3745 } |
| 3746 |
| 3747 std::string PNaClToolChain::computeSysRoot() const { |
| 3748 if (!getDriver().SysRoot.empty()) |
| 3749 return getDriver().SysRoot; |
| 3750 |
| 3751 return getDriver().Dir + "/../le32-nacl"; |
| 3752 } |
| 3753 |
| 3754 void PNaClToolChain::AddLinkRuntimeLibArgs(const ArgList &Args, |
| 3755 ArgStringList &CmdArgs) const { |
| 3756 CmdArgs.push_back("-lnacl"); |
| 3757 CmdArgs.push_back("-lpnaclmm"); |
| 3758 } |
| 3759 |
| 3760 ToolChain::CXXStdlibType PNaClToolChain::GetCXXStdlibType(const ArgList &Args) c
onst { |
| 3761 Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); |
| 3762 if (!A) |
| 3763 return ToolChain::CST_Libcxx; |
| 3764 |
| 3765 StringRef Value = A->getValue(); |
| 3766 if (Value != "libc++") { |
| 3767 getDriver().Diag(diag::err_drv_invalid_stdlib_name) |
| 3768 << A->getAsString(Args); |
| 3769 } |
| 3770 |
| 3771 return ToolChain::CST_Libcxx; |
| 3772 } |
| 3773 |
| 3774 void PNaClToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 3775 ArgStringList &CC1Args) const { |
| 3776 const Driver &D = getDriver(); |
| 3777 std::string SysRoot = computeSysRoot(); |
| 3778 |
| 3779 if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 3780 return; |
| 3781 |
| 3782 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
| 3783 SmallString<128> P(D.ResourceDir); |
| 3784 llvm::sys::path::append(P, "include"); |
| 3785 addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 3786 } |
| 3787 |
| 3788 if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 3789 return; |
| 3790 |
| 3791 // Check for configure-time C include directories. |
| 3792 StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 3793 if (CIncludeDirs != "") { |
| 3794 SmallVector<StringRef, 5> dirs; |
| 3795 CIncludeDirs.split(dirs, ":"); |
| 3796 for (StringRef dir : dirs) { |
| 3797 StringRef Prefix = |
| 3798 llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""; |
| 3799 addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); |
| 3800 } |
| 3801 return; |
| 3802 } |
| 3803 |
| 3804 // Add an include of '/include' directly. This isn't provided by default by |
| 3805 // system GCCs, but is often used with cross-compiling GCCs, and harmless to |
| 3806 // add even when Clang is acting as-if it were a system compiler. |
| 3807 addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); |
| 3808 |
| 3809 addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); |
| 3810 } |
| 3811 |
| 3812 void PNaClToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 3813 ArgStringList &CC1Args) const { |
| 3814 if (DriverArgs.hasArg(options::OPT_nostdlibinc) || |
| 3815 DriverArgs.hasArg(options::OPT_nostdincxx)) |
| 3816 return; |
| 3817 |
| 3818 // Check for -stdlib= flags. We only support libc++ but this consumes the arg |
| 3819 // if the value is libc++, and emits an error for other values. |
| 3820 GetCXXStdlibType(DriverArgs); |
| 3821 |
| 3822 const std::string LibCXXIncludePathCandidates[] = { |
| 3823 // The primary location is within the Clang installation. |
| 3824 getDriver().Dir + "/../include/c++/v1", |
| 3825 |
| 3826 // We also check the system as for a long time this is the only place Clang
looked. |
| 3827 getDriver().SysRoot + "/usr/include/c++/v1" |
| 3828 }; |
| 3829 for (const auto &IncludePath : LibCXXIncludePathCandidates) { |
| 3830 if (!llvm::sys::fs::exists(IncludePath)) |
| 3831 continue; |
| 3832 // Add the first candidate that exists. |
| 3833 addSystemInclude(DriverArgs, CC1Args, IncludePath); |
| 3834 break; |
| 3835 } |
| 3836 return; |
| 3837 } |
| 3838 |
| 3839 void PNaClToolChain::AddCXXStdlibLibArgs(const ArgList &Args, |
| 3840 ArgStringList &CmdArgs) const { |
| 3841 switch (GetCXXStdlibType(Args)) { |
| 3842 case ToolChain::CST_Libcxx: |
| 3843 CmdArgs.push_back("-lc++"); |
| 3844 break; |
| 3845 case ToolChain::CST_Libstdcxx: |
| 3846 break; |
| 3847 } |
| 3848 } |
| 3849 |
| 3850 void PNaClToolChain::addClangTargetOptions(const ArgList &DriverArgs, |
| 3851 ArgStringList &CC1Args) const { |
| 3852 if (DriverArgs.hasFlag(options::OPT_fuse_init_array, |
| 3853 options::OPT_fno_use_init_array, |
| 3854 getTriple().getOS() == llvm::Triple::NaCl)) |
| 3855 CC1Args.push_back("-fuse-init-array"); |
| 3856 } |
OLD | NEW |