opnsense-src/lib/Driver/ToolChains.h

275 lines
8.7 KiB
C
Raw Normal View History

2009-06-02 13:58:47 -04:00
//===--- ToolChains.h - ToolChain Implementations ---------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef CLANG_LIB_DRIVER_TOOLCHAINS_H_
#define CLANG_LIB_DRIVER_TOOLCHAINS_H_
#include "clang/Driver/Action.h"
#include "clang/Driver/ToolChain.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/Compiler.h"
#include "Tools.h"
namespace clang {
namespace driver {
namespace toolchains {
2009-10-14 14:03:49 -04:00
/// Generic_GCC - A tool chain using the 'gcc' command to perform
/// all subcommands; this relies on gcc translating the majority of
/// command line options.
2009-06-02 13:58:47 -04:00
class VISIBILITY_HIDDEN Generic_GCC : public ToolChain {
protected:
mutable llvm::DenseMap<unsigned, Tool*> Tools;
public:
Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple);
~Generic_GCC();
2009-10-14 14:03:49 -04:00
virtual DerivedArgList *TranslateArgs(InputArgList &Args,
const char *BoundArch) const;
2009-06-02 13:58:47 -04:00
virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
virtual bool IsUnwindTablesDefault() const;
virtual const char *GetDefaultRelocationModel() const;
virtual const char *GetForcedPicModel() const;
};
2009-10-14 14:03:49 -04:00
/// Darwin - The base Darwin tool chain.
class VISIBILITY_HIDDEN Darwin : public ToolChain {
2009-06-02 13:58:47 -04:00
mutable llvm::DenseMap<unsigned, Tool*> Tools;
2010-02-16 04:31:36 -05:00
/// Whether the information on the target has been initialized.
2009-10-14 14:03:49 -04:00
//
2010-02-16 04:31:36 -05:00
// FIXME: This should be eliminated. What we want to do is make this part of
// the "default target for arguments" selection process, once we get out of
// the argument translation business.
mutable bool TargetInitialized;
/// Whether we are targetting iPhoneOS target.
mutable bool TargetIsIPhoneOS;
/// The OS version we are targetting.
mutable unsigned TargetVersion[3];
2009-06-02 13:58:47 -04:00
/// The default macosx-version-min of this tool chain; empty until
/// initialized.
2010-02-16 04:31:36 -05:00
std::string MacosxVersionMin;
2009-06-02 13:58:47 -04:00
public:
2009-10-14 14:03:49 -04:00
Darwin(const HostInfo &Host, const llvm::Triple& Triple,
2010-02-16 04:31:36 -05:00
const unsigned (&DarwinVersion)[3]);
2009-10-14 14:03:49 -04:00
~Darwin();
/// @name Darwin Specific Toolchain API
/// {
2009-06-02 13:58:47 -04:00
2010-02-16 04:31:36 -05:00
// FIXME: Eliminate these ...Target functions and derive separate tool chains
// for these targets and put version in constructor.
void setTarget(bool isIPhoneOS, unsigned Major, unsigned Minor,
unsigned Micro) const {
// FIXME: For now, allow reinitialization as long as values don't
// change. This will go away when we move away from argument translation.
if (TargetInitialized && TargetIsIPhoneOS == isIPhoneOS &&
TargetVersion[0] == Major && TargetVersion[1] == Minor &&
TargetVersion[2] == Micro)
return;
assert(!TargetInitialized && "Target already initialized!");
TargetInitialized = true;
TargetIsIPhoneOS = isIPhoneOS;
TargetVersion[0] = Major;
TargetVersion[1] = Minor;
TargetVersion[2] = Micro;
2009-06-02 13:58:47 -04:00
}
2010-02-16 04:31:36 -05:00
bool isTargetIPhoneOS() const {
assert(TargetInitialized && "Target not initialized!");
return TargetIsIPhoneOS;
}
void getTargetVersion(unsigned (&Res)[3]) const {
assert(TargetInitialized && "Target not initialized!");
Res[0] = TargetVersion[0];
Res[1] = TargetVersion[1];
Res[2] = TargetVersion[2];
2009-06-02 13:58:47 -04:00
}
2010-01-23 06:10:26 -05:00
/// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
/// invocation. For example, Darwin treats different ARM variations as
/// distinct architectures.
llvm::StringRef getDarwinArchName(const ArgList &Args) const;
2010-02-16 04:31:36 -05:00
static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
2009-10-14 14:03:49 -04:00
for (unsigned i=0; i < 3; ++i) {
if (A[i] > B[i]) return false;
if (A[i] < B[i]) return true;
}
return false;
}
2010-02-16 04:31:36 -05:00
bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
2009-10-14 14:03:49 -04:00
unsigned B[3] = { V0, V1, V2 };
2010-02-16 04:31:36 -05:00
return isVersionLT(TargetVersion, B);
2009-10-14 14:03:49 -04:00
}
2010-02-16 04:31:36 -05:00
bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
unsigned B[3] = { V0, V1, V2 };
return isVersionLT(TargetVersion, B);
2009-06-02 13:58:47 -04:00
}
2009-10-14 14:03:49 -04:00
/// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
///
/// \param Args - The input argument list.
/// \param CmdArgs [out] - The command argument list to append the paths
/// (prefixed by -L) to.
virtual void AddLinkSearchPathArgs(const ArgList &Args,
ArgStringList &CmdArgs) const = 0;
/// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
/// runtime library.
virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
ArgStringList &CmdArgs) const = 0;
/// }
/// @name ToolChain Implementation
/// {
virtual DerivedArgList *TranslateArgs(InputArgList &Args,
const char *BoundArch) const;
2009-06-02 13:58:47 -04:00
virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
2009-11-18 09:59:57 -05:00
virtual bool IsBlocksDefault() const {
2010-02-16 04:31:36 -05:00
// Blocks default to on for OS X 10.6 and iPhoneOS 3.0 and beyond.
if (isTargetIPhoneOS())
return !isIPhoneOSVersionLT(3);
else
return !isMacosxVersionLT(10, 6);
2009-11-18 09:59:57 -05:00
}
virtual bool IsObjCNonFragileABIDefault() const {
2010-02-16 04:31:36 -05:00
// Non-fragile ABI default to on for iPhoneOS and x86-64.
return isTargetIPhoneOS() || getTriple().getArch() == llvm::Triple::x86_64;
}
virtual bool IsObjCLegacyDispatchDefault() const {
// This is only used with the non-fragile ABI.
return (getTriple().getArch() == llvm::Triple::arm ||
getTriple().getArch() == llvm::Triple::thumb);
2009-11-18 09:59:57 -05:00
}
2009-06-02 13:58:47 -04:00
virtual bool IsUnwindTablesDefault() const;
2009-11-18 09:59:57 -05:00
virtual unsigned GetDefaultStackProtectorLevel() const {
2010-02-16 04:31:36 -05:00
// Stack protectors default to on for 10.6 and beyond.
return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6);
2009-11-18 09:59:57 -05:00
}
2009-06-02 13:58:47 -04:00
virtual const char *GetDefaultRelocationModel() const;
virtual const char *GetForcedPicModel() const;
2009-10-14 14:03:49 -04:00
2010-01-01 05:34:51 -05:00
virtual bool UseDwarfDebugFlags() const;
2010-02-16 04:31:36 -05:00
virtual bool UseSjLjExceptions() const;
2009-10-14 14:03:49 -04:00
/// }
};
/// DarwinClang - The Darwin toolchain used by Clang.
class VISIBILITY_HIDDEN DarwinClang : public Darwin {
public:
DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
2010-02-16 04:31:36 -05:00
const unsigned (&DarwinVersion)[3]);
2009-10-14 14:03:49 -04:00
/// @name Darwin ToolChain Implementation
/// {
virtual void AddLinkSearchPathArgs(const ArgList &Args,
ArgStringList &CmdArgs) const;
virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
ArgStringList &CmdArgs) const;
/// }
2009-06-02 13:58:47 -04:00
};
2009-10-14 14:03:49 -04:00
/// DarwinGCC - The Darwin toolchain used by GCC.
class VISIBILITY_HIDDEN DarwinGCC : public Darwin {
/// GCC version to use.
unsigned GCCVersion[3];
/// The directory suffix for this tool chain.
std::string ToolChainDir;
2009-06-02 13:58:47 -04:00
public:
2009-10-14 14:03:49 -04:00
DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
2010-02-16 04:31:36 -05:00
const unsigned (&DarwinVersion)[3],
const unsigned (&GCCVersion)[3]);
2009-10-14 14:03:49 -04:00
/// @name Darwin ToolChain Implementation
/// {
virtual void AddLinkSearchPathArgs(const ArgList &Args,
ArgStringList &CmdArgs) const;
virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
ArgStringList &CmdArgs) const;
/// }
};
/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
class VISIBILITY_HIDDEN Darwin_Generic_GCC : public Generic_GCC {
public:
Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
2009-06-02 13:58:47 -04:00
: Generic_GCC(Host, Triple) {}
virtual const char *GetDefaultRelocationModel() const { return "pic"; }
};
2009-10-14 14:03:49 -04:00
class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC {
public:
AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
};
2009-07-04 09:58:54 -04:00
class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC {
public:
OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
};
2009-06-02 13:58:47 -04:00
class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC {
public:
FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
};
class VISIBILITY_HIDDEN DragonFly : public Generic_GCC {
public:
DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
};
class VISIBILITY_HIDDEN Linux : public Generic_GCC {
public:
Linux(const HostInfo &Host, const llvm::Triple& Triple);
};
} // end namespace toolchains
} // end namespace driver
} // end namespace clang
#endif