2011-01-01 01:31:54 +08:00
|
|
|
//===--- ToolChain.cpp - Collections of tools for one platform ------------===//
|
2009-03-16 13:25:36 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Driver/ToolChain.h"
|
|
|
|
|
|
|
|
#include "clang/Driver/Action.h"
|
2010-08-24 06:35:37 +08:00
|
|
|
#include "clang/Driver/Arg.h"
|
|
|
|
#include "clang/Driver/ArgList.h"
|
2009-03-16 13:25:36 +08:00
|
|
|
#include "clang/Driver/Driver.h"
|
2010-08-24 06:35:37 +08:00
|
|
|
#include "clang/Driver/DriverDiagnostic.h"
|
2011-07-06 08:26:06 +08:00
|
|
|
#include "clang/Driver/ObjCRuntime.h"
|
2010-08-24 06:35:37 +08:00
|
|
|
#include "clang/Driver/Options.h"
|
2012-03-22 01:19:12 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2011-07-06 08:26:06 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-03-16 13:25:36 +08:00
|
|
|
using namespace clang::driver;
|
2011-07-23 18:55:15 +08:00
|
|
|
using namespace clang;
|
2009-03-16 13:25:36 +08:00
|
|
|
|
2012-01-31 10:21:20 +08:00
|
|
|
ToolChain::ToolChain(const Driver &D, const llvm::Triple &T)
|
|
|
|
: D(D), Triple(T) {
|
2009-03-16 13:25:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ToolChain::~ToolChain() {
|
|
|
|
}
|
|
|
|
|
2009-12-22 02:54:17 +08:00
|
|
|
const Driver &ToolChain::getDriver() const {
|
2012-01-25 17:12:06 +08:00
|
|
|
return D;
|
2009-12-22 02:54:17 +08:00
|
|
|
}
|
|
|
|
|
2010-07-15 02:46:23 +08:00
|
|
|
std::string ToolChain::GetFilePath(const char *Name) const {
|
2012-01-25 17:12:06 +08:00
|
|
|
return D.GetFilePath(Name, *this);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-16 13:25:36 +08:00
|
|
|
}
|
|
|
|
|
2010-07-15 02:46:23 +08:00
|
|
|
std::string ToolChain::GetProgramPath(const char *Name, bool WantFile) const {
|
2012-01-25 17:12:06 +08:00
|
|
|
return D.GetProgramPath(Name, *this, WantFile);
|
2009-03-16 13:25:36 +08:00
|
|
|
}
|
2010-08-02 13:43:56 +08:00
|
|
|
|
|
|
|
types::ID ToolChain::LookupTypeForExtension(const char *Ext) const {
|
|
|
|
return types::lookupTypeForExtension(Ext);
|
|
|
|
}
|
2010-08-24 06:35:37 +08:00
|
|
|
|
2010-09-17 08:24:52 +08:00
|
|
|
bool ToolChain::HasNativeLLVMSupport() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-06 08:26:06 +08:00
|
|
|
void ToolChain::configureObjCRuntime(ObjCRuntime &runtime) const {
|
|
|
|
switch (runtime.getKind()) {
|
|
|
|
case ObjCRuntime::NeXT:
|
|
|
|
// Assume a minimal NeXT runtime.
|
|
|
|
runtime.HasARC = false;
|
|
|
|
runtime.HasWeak = false;
|
2012-03-07 04:06:33 +08:00
|
|
|
runtime.HasSubscripting = false;
|
2011-07-06 09:22:26 +08:00
|
|
|
runtime.HasTerminate = false;
|
2011-07-06 08:26:06 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
case ObjCRuntime::GNU:
|
|
|
|
// Assume a maximal GNU runtime.
|
|
|
|
runtime.HasARC = true;
|
|
|
|
runtime.HasWeak = true;
|
2012-03-07 04:06:33 +08:00
|
|
|
runtime.HasSubscripting = false; // to be added
|
2011-07-06 09:22:26 +08:00
|
|
|
runtime.HasTerminate = false; // to be added
|
2011-07-06 08:26:06 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
llvm_unreachable("invalid runtime kind!");
|
|
|
|
}
|
|
|
|
|
2011-04-15 13:22:18 +08:00
|
|
|
/// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targeting.
|
2010-08-24 06:35:37 +08:00
|
|
|
//
|
|
|
|
// FIXME: tblgen this.
|
|
|
|
static const char *getARMTargetCPU(const ArgList &Args,
|
|
|
|
const llvm::Triple &Triple) {
|
2012-03-22 00:31:37 +08:00
|
|
|
// For Darwin targets, the -arch option (which is translated to a
|
|
|
|
// corresponding -march option) should determine the architecture
|
|
|
|
// (and the Mach-O slice) regardless of any -mcpu options.
|
|
|
|
if (!Triple.isOSDarwin()) {
|
|
|
|
// FIXME: Warn on inconsistent use of -mcpu and -march.
|
|
|
|
// If we have -mcpu=, use that.
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
|
|
|
|
return A->getValue(Args);
|
|
|
|
}
|
2010-08-24 06:35:37 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef MArch;
|
2010-08-24 06:35:37 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
|
|
|
|
// Otherwise, if we have -march= choose the base CPU for that arch.
|
|
|
|
MArch = A->getValue(Args);
|
|
|
|
} else {
|
|
|
|
// Otherwise, use the Arch from the triple.
|
|
|
|
MArch = Triple.getArchName();
|
|
|
|
}
|
|
|
|
|
2012-03-22 01:19:12 +08:00
|
|
|
return llvm::StringSwitch<const char *>(MArch)
|
|
|
|
.Cases("armv2", "armv2a","arm2")
|
|
|
|
.Case("armv3", "arm6")
|
|
|
|
.Case("armv3m", "arm7m")
|
|
|
|
.Cases("armv4", "armv4t", "arm7tdmi")
|
|
|
|
.Cases("armv5", "armv5t", "arm10tdmi")
|
|
|
|
.Cases("armv5e", "armv5te", "arm1026ejs")
|
|
|
|
.Case("armv5tej", "arm926ej-s")
|
|
|
|
.Cases("armv6", "armv6k", "arm1136jf-s")
|
|
|
|
.Case("armv6j", "arm1136j-s")
|
|
|
|
.Cases("armv6z", "armv6zk", "arm1176jzf-s")
|
|
|
|
.Case("armv6t2", "arm1156t2-s")
|
|
|
|
.Cases("armv7", "armv7a", "armv7-a", "cortex-a8")
|
|
|
|
.Cases("armv7r", "armv7-r", "cortex-r4")
|
|
|
|
.Cases("armv7m", "armv7-m", "cortex-m3")
|
|
|
|
.Case("ep9312", "ep9312")
|
|
|
|
.Case("iwmmxt", "iwmmxt")
|
|
|
|
.Case("xscale", "xscale")
|
|
|
|
.Cases("armv6m", "armv6-m", "cortex-m0")
|
|
|
|
// If all else failed, return the most base CPU LLVM supports.
|
|
|
|
.Default("arm7tdmi");
|
2010-08-24 06:35:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular
|
|
|
|
/// CPU.
|
|
|
|
//
|
|
|
|
// FIXME: This is redundant with -mcpu, why does LLVM use this.
|
|
|
|
// FIXME: tblgen this, or kill it!
|
2011-07-23 18:55:15 +08:00
|
|
|
static const char *getLLVMArchSuffixForARM(StringRef CPU) {
|
2012-03-22 01:19:12 +08:00
|
|
|
return llvm::StringSwitch<const char *>(CPU)
|
|
|
|
.Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "v4t")
|
|
|
|
.Cases("arm720t", "arm9", "arm9tdmi", "v4t")
|
|
|
|
.Cases("arm920", "arm920t", "arm922t", "v4t")
|
|
|
|
.Cases("arm940t", "ep9312","v4t")
|
|
|
|
.Cases("arm10tdmi", "arm1020t", "v5")
|
|
|
|
.Cases("arm9e", "arm926ej-s", "arm946e-s", "v5e")
|
|
|
|
.Cases("arm966e-s", "arm968e-s", "arm10e", "v5e")
|
|
|
|
.Cases("arm1020e", "arm1022e", "xscale", "iwmmxt", "v5e")
|
|
|
|
.Cases("arm1136j-s", "arm1136jf-s", "arm1176jz-s", "v6")
|
|
|
|
.Cases("arm1176jzf-s", "mpcorenovfp", "mpcore", "v6")
|
|
|
|
.Cases("arm1156t2-s", "arm1156t2f-s", "v6t2")
|
|
|
|
.Cases("cortex-a8", "cortex-a9", "v7")
|
|
|
|
.Case("cortex-m3", "v7m")
|
|
|
|
.Case("cortex-m0", "v6m")
|
|
|
|
.Default("");
|
2010-08-24 06:35:37 +08:00
|
|
|
}
|
|
|
|
|
2011-09-21 04:44:06 +08:00
|
|
|
std::string ToolChain::ComputeLLVMTriple(const ArgList &Args,
|
|
|
|
types::ID InputType) const {
|
2010-08-24 06:35:37 +08:00
|
|
|
switch (getTriple().getArch()) {
|
|
|
|
default:
|
|
|
|
return getTripleString();
|
|
|
|
|
|
|
|
case llvm::Triple::arm:
|
|
|
|
case llvm::Triple::thumb: {
|
|
|
|
// FIXME: Factor into subclasses.
|
|
|
|
llvm::Triple Triple = getTriple();
|
|
|
|
|
|
|
|
// Thumb2 is the default for V7 on Darwin.
|
|
|
|
//
|
|
|
|
// FIXME: Thumb should just be another -target-feaure, not in the triple.
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Suffix =
|
2010-08-24 06:35:37 +08:00
|
|
|
getLLVMArchSuffixForARM(getARMTargetCPU(Args, Triple));
|
2011-10-14 13:03:44 +08:00
|
|
|
bool ThumbDefault = (Suffix == "v7" && getTriple().isOSDarwin());
|
2010-08-24 06:35:37 +08:00
|
|
|
std::string ArchName = "arm";
|
2011-09-21 04:44:06 +08:00
|
|
|
|
|
|
|
// Assembly files should start in ARM mode.
|
|
|
|
if (InputType != types::TY_PP_Asm &&
|
|
|
|
Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault))
|
2010-08-24 06:35:37 +08:00
|
|
|
ArchName = "thumb";
|
|
|
|
Triple.setArchName(ArchName + Suffix.str());
|
|
|
|
|
|
|
|
return Triple.getTriple();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-21 04:44:06 +08:00
|
|
|
std::string ToolChain::ComputeEffectiveClangTriple(const ArgList &Args,
|
|
|
|
types::ID InputType) const {
|
2011-04-30 12:15:58 +08:00
|
|
|
// Diagnose use of Darwin OS deployment target arguments on non-Darwin.
|
2010-08-24 06:35:37 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ,
|
2011-04-30 12:15:58 +08:00
|
|
|
options::OPT_miphoneos_version_min_EQ,
|
|
|
|
options::OPT_mios_simulator_version_min_EQ))
|
2011-07-23 18:55:15 +08:00
|
|
|
getDriver().Diag(diag::err_drv_clang_unsupported)
|
2010-08-24 06:35:37 +08:00
|
|
|
<< A->getAsString(Args);
|
|
|
|
|
2011-09-21 04:44:06 +08:00
|
|
|
return ComputeLLVMTriple(Args, InputType);
|
2010-08-24 06:35:37 +08:00
|
|
|
}
|
|
|
|
|
2011-11-04 15:12:53 +08:00
|
|
|
void ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args) const {
|
|
|
|
// Each toolchain should provide the appropriate include flags.
|
|
|
|
}
|
|
|
|
|
2011-12-08 07:03:15 +08:00
|
|
|
ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType(
|
|
|
|
const ArgList &Args) const
|
|
|
|
{
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_rtlib_EQ)) {
|
|
|
|
StringRef Value = A->getValue(Args);
|
|
|
|
if (Value == "compiler-rt")
|
|
|
|
return ToolChain::RLT_CompilerRT;
|
|
|
|
if (Value == "libgcc")
|
|
|
|
return ToolChain::RLT_Libgcc;
|
|
|
|
getDriver().Diag(diag::err_drv_invalid_rtlib_name)
|
|
|
|
<< A->getAsString(Args);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetDefaultRuntimeLibType();
|
|
|
|
}
|
|
|
|
|
2010-09-15 07:12:35 +08:00
|
|
|
ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{
|
2010-09-15 07:12:40 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Value = A->getValue(Args);
|
2010-09-15 07:12:40 +08:00
|
|
|
if (Value == "libc++")
|
|
|
|
return ToolChain::CST_Libcxx;
|
|
|
|
if (Value == "libstdc++")
|
|
|
|
return ToolChain::CST_Libstdcxx;
|
2011-07-23 18:55:15 +08:00
|
|
|
getDriver().Diag(diag::err_drv_invalid_stdlib_name)
|
2010-09-15 07:12:40 +08:00
|
|
|
<< A->getAsString(Args);
|
|
|
|
}
|
|
|
|
|
2010-09-15 07:12:35 +08:00
|
|
|
return ToolChain::CST_Libstdcxx;
|
|
|
|
}
|
|
|
|
|
2011-12-18 07:10:01 +08:00
|
|
|
/// \brief Utility function to add a system include directory to CC1 arguments.
|
|
|
|
/*static*/ void ToolChain::addSystemInclude(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args,
|
|
|
|
const Twine &Path) {
|
|
|
|
CC1Args.push_back("-internal-isystem");
|
|
|
|
CC1Args.push_back(DriverArgs.MakeArgString(Path));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Utility function to add a system include directory with extern "C"
|
|
|
|
/// semantics to CC1 arguments.
|
|
|
|
///
|
|
|
|
/// Note that this should be used rarely, and only for directories that
|
|
|
|
/// historically and for legacy reasons are treated as having implicit extern
|
|
|
|
/// "C" semantics. These semantics are *ignored* by and large today, but its
|
|
|
|
/// important to preserve the preprocessor changes resulting from the
|
|
|
|
/// classification.
|
|
|
|
/*static*/ void ToolChain::addExternCSystemInclude(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args,
|
|
|
|
const Twine &Path) {
|
|
|
|
CC1Args.push_back("-internal-externc-isystem");
|
|
|
|
CC1Args.push_back(DriverArgs.MakeArgString(Path));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Utility function to add a list of system include directories to CC1.
|
|
|
|
/*static*/ void ToolChain::addSystemIncludes(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args,
|
|
|
|
ArrayRef<StringRef> Paths) {
|
|
|
|
for (ArrayRef<StringRef>::iterator I = Paths.begin(), E = Paths.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
CC1Args.push_back("-internal-isystem");
|
|
|
|
CC1Args.push_back(DriverArgs.MakeArgString(*I));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-05 07:49:01 +08:00
|
|
|
void ToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args) const {
|
2011-11-04 15:43:33 +08:00
|
|
|
// Header search paths should be handled by each of the subclasses.
|
|
|
|
// Historically, they have not been, and instead have been handled inside of
|
|
|
|
// the CC1-layer frontend. As the logic is hoisted out, this generic function
|
|
|
|
// will slowly stop being called.
|
|
|
|
//
|
|
|
|
// While it is being called, replicate a bit of a hack to propagate the
|
|
|
|
// '-stdlib=' flag down to CC1 so that it can in turn customize the C++
|
|
|
|
// header search paths with it. Once all systems are overriding this
|
|
|
|
// function, the CC1 flag and this line can be removed.
|
2011-11-05 07:49:01 +08:00
|
|
|
DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ);
|
2010-09-15 07:12:35 +08:00
|
|
|
}
|
|
|
|
|
2010-09-17 09:20:05 +08:00
|
|
|
void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
2010-09-15 07:12:35 +08:00
|
|
|
CXXStdlibType Type = GetCXXStdlibType(Args);
|
|
|
|
|
|
|
|
switch (Type) {
|
2010-09-15 07:12:40 +08:00
|
|
|
case ToolChain::CST_Libcxx:
|
|
|
|
CmdArgs.push_back("-lc++");
|
|
|
|
break;
|
|
|
|
|
2010-09-15 07:12:35 +08:00
|
|
|
case ToolChain::CST_Libstdcxx:
|
|
|
|
CmdArgs.push_back("-lstdc++");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-18 02:39:08 +08:00
|
|
|
|
|
|
|
void ToolChain::AddCCKextLibArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
|
|
|
CmdArgs.push_back("-lcc_kext");
|
|
|
|
}
|