ToolChains.h revision 816bc31ed45002de2547d6679b44f31eb85ec491
1//===--- ToolChains.h - ToolChain Implementations ---------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef CLANG_LIB_DRIVER_TOOLCHAINS_H_ 11#define CLANG_LIB_DRIVER_TOOLCHAINS_H_ 12 13#include "clang/Driver/Action.h" 14#include "clang/Driver/ToolChain.h" 15 16#include "llvm/ADT/DenseMap.h" 17#include "llvm/Support/Compiler.h" 18 19#include "Tools.h" 20 21namespace clang { 22namespace driver { 23namespace toolchains { 24 25/// Generic_GCC - A tool chain using the 'gcc' command to perform 26/// all subcommands; this relies on gcc translating the majority of 27/// command line options. 28class VISIBILITY_HIDDEN Generic_GCC : public ToolChain { 29protected: 30 mutable llvm::DenseMap<unsigned, Tool*> Tools; 31 32public: 33 Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple); 34 ~Generic_GCC(); 35 36 virtual DerivedArgList *TranslateArgs(InputArgList &Args, 37 const char *BoundArch) const; 38 39 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; 40 41 virtual bool IsUnwindTablesDefault() const; 42 virtual const char *GetDefaultRelocationModel() const; 43 virtual const char *GetForcedPicModel() const; 44}; 45 46/// Darwin - The base Darwin tool chain. 47class VISIBILITY_HIDDEN Darwin : public ToolChain { 48 mutable llvm::DenseMap<unsigned, Tool*> Tools; 49 50 /// Darwin version of tool chain. 51 unsigned DarwinVersion[3]; 52 53 /// Whether this is this an iPhoneOS toolchain. 54 // 55 // FIXME: This should go away, such differences should be completely 56 // determined by the target triple. 57 // 58 // FIXME: It is also broken, we need to distinguish the "default target" from 59 // the actual target. The -m...-version-min strings and deployment targets can 60 // change this. 61 bool IsIPhoneOS; 62 63 /// The default macosx-version-min of this tool chain; empty until 64 /// initialized. 65 std::string MacosxVersionMin; 66 67 /// The default iphoneos-version-min of this tool chain. 68 std::string IPhoneOSVersionMin; 69 70 const char *getMacosxVersionMin() const; 71 72public: 73 Darwin(const HostInfo &Host, const llvm::Triple& Triple, 74 const unsigned (&DarwinVersion)[3], bool IsIPhoneOS); 75 ~Darwin(); 76 77 /// @name Darwin Specific Toolchain API 78 /// { 79 80 void getDarwinVersion(unsigned (&Res)[3]) const { 81 Res[0] = DarwinVersion[0]; 82 Res[1] = DarwinVersion[1]; 83 Res[2] = DarwinVersion[2]; 84 } 85 86 void getMacosxVersion(unsigned (&Res)[3]) const { 87 Res[0] = 10; 88 Res[1] = DarwinVersion[0] - 4; 89 Res[2] = DarwinVersion[1]; 90 } 91 92 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler 93 /// invocation. For example, Darwin treats different ARM variations as 94 /// distinct architectures. 95 llvm::StringRef getDarwinArchName(const ArgList &Args) const; 96 97 /// getMacosxVersionMin - Get the effective -mmacosx-version-min, which is 98 /// either the -mmacosx-version-min, or the current version if unspecified. 99 void getMacosxVersionMin(const ArgList &Args, unsigned (&Res)[3]) const; 100 101 static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) { 102 for (unsigned i=0; i < 3; ++i) { 103 if (A[i] > B[i]) return false; 104 if (A[i] < B[i]) return true; 105 } 106 return false; 107 } 108 109 static bool isMacosxVersionLT(unsigned (&A)[3], 110 unsigned V0, unsigned V1=0, unsigned V2=0) { 111 unsigned B[3] = { V0, V1, V2 }; 112 return isMacosxVersionLT(A, B); 113 } 114 115 const char *getMacosxVersionStr() const { 116 return MacosxVersionMin.c_str(); 117 } 118 119 const char *getIPhoneOSVersionStr() const { 120 return IPhoneOSVersionMin.c_str(); 121 } 122 123 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs. 124 /// 125 /// \param Args - The input argument list. 126 /// \param CmdArgs [out] - The command argument list to append the paths 127 /// (prefixed by -L) to. 128 virtual void AddLinkSearchPathArgs(const ArgList &Args, 129 ArgStringList &CmdArgs) const = 0; 130 131 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler 132 /// runtime library. 133 virtual void AddLinkRuntimeLibArgs(const ArgList &Args, 134 ArgStringList &CmdArgs) const = 0; 135 136 bool isIPhoneOS() const { return IsIPhoneOS; } 137 138 /// } 139 /// @name ToolChain Implementation 140 /// { 141 142 virtual DerivedArgList *TranslateArgs(InputArgList &Args, 143 const char *BoundArch) const; 144 145 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; 146 147 virtual bool IsBlocksDefault() const { 148 // Blocks default to on for 10.6 (darwin10) and beyond. 149 return (DarwinVersion[0] > 9); 150 } 151 virtual bool IsObjCNonFragileABIDefault() const { 152 // Non-fragile ABI default to on for 10.5 (darwin9) and beyond on x86-64. 153 return (DarwinVersion[0] >= 9 && 154 getTriple().getArch() == llvm::Triple::x86_64); 155 } 156 virtual bool IsUnwindTablesDefault() const; 157 virtual unsigned GetDefaultStackProtectorLevel() const { 158 // Stack protectors default to on for 10.6 (darwin10) and beyond. 159 return (DarwinVersion[0] > 9) ? 1 : 0; 160 } 161 virtual const char *GetDefaultRelocationModel() const; 162 virtual const char *GetForcedPicModel() const; 163 164 virtual bool UseDwarfDebugFlags() const; 165 166 /// } 167}; 168 169/// DarwinClang - The Darwin toolchain used by Clang. 170class VISIBILITY_HIDDEN DarwinClang : public Darwin { 171public: 172 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple, 173 const unsigned (&DarwinVersion)[3], bool IsIPhoneOS); 174 175 /// @name Darwin ToolChain Implementation 176 /// { 177 178 virtual void AddLinkSearchPathArgs(const ArgList &Args, 179 ArgStringList &CmdArgs) const; 180 181 virtual void AddLinkRuntimeLibArgs(const ArgList &Args, 182 ArgStringList &CmdArgs) const; 183 184 /// } 185}; 186 187/// DarwinGCC - The Darwin toolchain used by GCC. 188class VISIBILITY_HIDDEN DarwinGCC : public Darwin { 189 /// GCC version to use. 190 unsigned GCCVersion[3]; 191 192 /// The directory suffix for this tool chain. 193 std::string ToolChainDir; 194 195public: 196 DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple, 197 const unsigned (&DarwinVersion)[3], const unsigned (&GCCVersion)[3], 198 bool IsIPhoneOS); 199 200 /// @name Darwin ToolChain Implementation 201 /// { 202 203 virtual void AddLinkSearchPathArgs(const ArgList &Args, 204 ArgStringList &CmdArgs) const; 205 206 virtual void AddLinkRuntimeLibArgs(const ArgList &Args, 207 ArgStringList &CmdArgs) const; 208 209 /// } 210}; 211 212/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc. 213class VISIBILITY_HIDDEN Darwin_Generic_GCC : public Generic_GCC { 214public: 215 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) 216 : Generic_GCC(Host, Triple) {} 217 218 virtual const char *GetDefaultRelocationModel() const { return "pic"; } 219}; 220 221class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC { 222public: 223 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple); 224 225 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; 226}; 227 228class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC { 229public: 230 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple); 231 232 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; 233}; 234 235class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC { 236public: 237 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32); 238 239 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; 240}; 241 242class VISIBILITY_HIDDEN DragonFly : public Generic_GCC { 243public: 244 DragonFly(const HostInfo &Host, const llvm::Triple& Triple); 245 246 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; 247}; 248 249class VISIBILITY_HIDDEN Linux : public Generic_GCC { 250public: 251 Linux(const HostInfo &Host, const llvm::Triple& Triple); 252}; 253 254 255} // end namespace toolchains 256} // end namespace driver 257} // end namespace clang 258 259#endif 260