forked from OSchip/llvm-project
Driver: Factor out some code for handling the C++ standard library.
llvm-svn: 113890
This commit is contained in:
parent
30a12b8d88
commit
bf11f79053
|
@ -10,6 +10,7 @@
|
|||
#ifndef CLANG_DRIVER_TOOLCHAIN_H_
|
||||
#define CLANG_DRIVER_TOOLCHAIN_H_
|
||||
|
||||
#include "clang/Driver/Util.h"
|
||||
#include "clang/Driver/Types.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
|
@ -32,6 +33,10 @@ class ToolChain {
|
|||
public:
|
||||
typedef llvm::SmallVector<std::string, 4> path_list;
|
||||
|
||||
enum CXXStdlibType {
|
||||
CST_Libstdcxx
|
||||
};
|
||||
|
||||
private:
|
||||
const HostInfo &Host;
|
||||
const llvm::Triple Triple;
|
||||
|
@ -153,6 +158,20 @@ public:
|
|||
/// sets the deployment target) determines the version in the triple passed to
|
||||
/// Clang.
|
||||
virtual std::string ComputeEffectiveClangTriple(const ArgList &Args) const;
|
||||
|
||||
// GetCXXStdlibType - Determine the C++ standard library type to use with the
|
||||
// given compilation arguments.
|
||||
virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const;
|
||||
|
||||
/// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
|
||||
/// the include paths to use for the given C++ standard library type.
|
||||
virtual void AddClangCXXStdlibIncludeArgs(const ArgList &Args,
|
||||
ArgStringList &CmdArgs) const;
|
||||
|
||||
/// AddClangCXXStdlibLibArgs - Add the system specific linker arguments to use
|
||||
/// for the given C++ standard library type.
|
||||
virtual void AddClangCXXStdlibLibArgs(const ArgList &Args,
|
||||
ArgStringList &CmdArgs) const;
|
||||
};
|
||||
|
||||
} // end namespace driver
|
||||
|
|
|
@ -174,3 +174,28 @@ std::string ToolChain::ComputeEffectiveClangTriple(const ArgList &Args) const {
|
|||
return ComputeLLVMTriple(Args);
|
||||
}
|
||||
|
||||
ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{
|
||||
return ToolChain::CST_Libstdcxx;
|
||||
}
|
||||
|
||||
void ToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &Args,
|
||||
ArgStringList &CmdArgs) const {
|
||||
CXXStdlibType Type = GetCXXStdlibType(Args);
|
||||
|
||||
switch (Type) {
|
||||
case ToolChain::CST_Libstdcxx:
|
||||
// Currently handled by the mass of goop in InitHeaderSearch.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ToolChain::AddClangCXXStdlibLibArgs(const ArgList &Args,
|
||||
ArgStringList &CmdArgs) const {
|
||||
CXXStdlibType Type = GetCXXStdlibType(Args);
|
||||
|
||||
switch (Type) {
|
||||
case ToolChain::CST_Libstdcxx:
|
||||
CmdArgs.push_back("-lstdc++");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -230,6 +230,11 @@ void Clang::AddPreprocessingOptions(const Driver &D,
|
|||
Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U);
|
||||
Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F);
|
||||
|
||||
// Add C++ include arguments, if needed.
|
||||
types::ID InputType = Inputs[0].getType();
|
||||
if (types::isCXX(InputType))
|
||||
getToolChain().AddClangCXXStdlibIncludeArgs(Args, CmdArgs);
|
||||
|
||||
// Add -Wp, and -Xassembler if using the preprocessor.
|
||||
|
||||
// FIXME: There is a very unfortunate problem here, some troubled
|
||||
|
@ -2503,10 +2508,8 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
|
||||
if (!Args.hasArg(options::OPT_nostdlib) &&
|
||||
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
||||
// FIXME: g++ is more complicated here, it tries to put -lstdc++
|
||||
// before -lm, for example.
|
||||
if (getToolChain().getDriver().CCCIsCXX)
|
||||
CmdArgs.push_back("-lstdc++");
|
||||
getToolChain().AddClangCXXStdlibLibArgs(Args, CmdArgs);
|
||||
|
||||
// link_ssp spec is empty.
|
||||
|
||||
|
@ -2797,7 +2800,7 @@ void openbsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
if (!Args.hasArg(options::OPT_nostdlib) &&
|
||||
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
||||
if (D.CCCIsCXX) {
|
||||
CmdArgs.push_back("-lstdc++");
|
||||
getToolChain().AddClangCXXStdlibLibArgs(Args, CmdArgs);
|
||||
CmdArgs.push_back("-lm");
|
||||
}
|
||||
|
||||
|
@ -2941,7 +2944,7 @@ void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
if (!Args.hasArg(options::OPT_nostdlib) &&
|
||||
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
||||
if (D.CCCIsCXX) {
|
||||
CmdArgs.push_back("-lstdc++");
|
||||
getToolChain().AddClangCXXStdlibLibArgs(Args, CmdArgs);
|
||||
CmdArgs.push_back("-lm");
|
||||
}
|
||||
// FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
|
||||
|
@ -3090,7 +3093,7 @@ void minix::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
if (!Args.hasArg(options::OPT_nostdlib) &&
|
||||
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
||||
if (D.CCCIsCXX) {
|
||||
CmdArgs.push_back("-lstdc++");
|
||||
getToolChain().AddClangCXXStdlibLibArgs(Args, CmdArgs);
|
||||
CmdArgs.push_back("-lm");
|
||||
}
|
||||
|
||||
|
@ -3239,7 +3242,7 @@ void dragonfly::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
}
|
||||
|
||||
if (D.CCCIsCXX) {
|
||||
CmdArgs.push_back("-lstdc++");
|
||||
getToolChain().AddClangCXXStdlibLibArgs(Args, CmdArgs);
|
||||
CmdArgs.push_back("-lm");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue