Daniel Dunbar | 83b08eb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 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 | |
Daniel Dunbar | 670b7f4 | 2009-03-17 22:07:31 +0000 | [diff] [blame] | 13 | #include "clang/Driver/Action.h" |
Daniel Dunbar | 83b08eb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 14 | #include "clang/Driver/ToolChain.h" |
| 15 | |
Daniel Dunbar | 670b7f4 | 2009-03-17 22:07:31 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/DenseMap.h" |
Daniel Dunbar | 83b08eb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Compiler.h" |
| 18 | |
Daniel Dunbar | 670b7f4 | 2009-03-17 22:07:31 +0000 | [diff] [blame] | 19 | #include "Tools.h" |
| 20 | |
Daniel Dunbar | 83b08eb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 21 | namespace clang { |
| 22 | namespace driver { |
Daniel Dunbar | 985b825 | 2009-03-17 22:18:43 +0000 | [diff] [blame] | 23 | namespace toolchains { |
Daniel Dunbar | 83b08eb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 24 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 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. |
Daniel Dunbar | 985b825 | 2009-03-17 22:18:43 +0000 | [diff] [blame] | 28 | class VISIBILITY_HIDDEN Generic_GCC : public ToolChain { |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 29 | protected: |
Daniel Dunbar | 670b7f4 | 2009-03-17 22:07:31 +0000 | [diff] [blame] | 30 | mutable llvm::DenseMap<unsigned, Tool*> Tools; |
| 31 | |
Daniel Dunbar | 83b08eb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 32 | public: |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 33 | Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple); |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 34 | ~Generic_GCC(); |
Daniel Dunbar | 83b08eb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 35 | |
Daniel Dunbar | 0dcb9a3 | 2009-09-09 18:36:12 +0000 | [diff] [blame] | 36 | virtual DerivedArgList *TranslateArgs(InputArgList &Args, |
| 37 | const char *BoundArch) const; |
Daniel Dunbar | 83b08eb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 38 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 39 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
Daniel Dunbar | 670b7f4 | 2009-03-17 22:07:31 +0000 | [diff] [blame] | 40 | |
Daniel Dunbar | 3917608 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 41 | virtual bool IsUnwindTablesDefault() const; |
| 42 | virtual const char *GetDefaultRelocationModel() const; |
| 43 | virtual const char *GetForcedPicModel() const; |
Daniel Dunbar | 83b08eb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 46 | /// Darwin - The base Darwin tool chain. |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 47 | class VISIBILITY_HIDDEN Darwin : public ToolChain { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 48 | mutable llvm::DenseMap<unsigned, Tool*> Tools; |
| 49 | |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 50 | /// Whether the information on the target has been initialized. |
| 51 | // |
| 52 | // FIXME: This should be eliminated. What we want to do is make this part of |
| 53 | // the "default target for arguments" selection process, once we get out of |
| 54 | // the argument translation business. |
| 55 | mutable bool TargetInitialized; |
| 56 | |
| 57 | /// Whether we are targetting iPhoneOS target. |
| 58 | mutable bool TargetIsIPhoneOS; |
| 59 | |
| 60 | /// The OS version we are targetting. |
| 61 | mutable unsigned TargetVersion[3]; |
| 62 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 63 | /// The default macosx-version-min of this tool chain; empty until |
| 64 | /// initialized. |
Daniel Dunbar | 816bc31 | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 65 | std::string MacosxVersionMin; |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 66 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 67 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 68 | Darwin(const HostInfo &Host, const llvm::Triple& Triple, |
Daniel Dunbar | cc8e189 | 2010-01-27 00:56:44 +0000 | [diff] [blame] | 69 | const unsigned (&DarwinVersion)[3]); |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 70 | ~Darwin(); |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 71 | |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 72 | /// @name Darwin Specific Toolchain API |
| 73 | /// { |
| 74 | |
Daniel Dunbar | 2603137 | 2010-01-27 00:56:25 +0000 | [diff] [blame] | 75 | // FIXME: Eliminate these ...Target functions and derive separate tool chains |
| 76 | // for these targets and put version in constructor. |
| 77 | void setTarget(bool isIPhoneOS, unsigned Major, unsigned Minor, |
| 78 | unsigned Micro) const { |
| 79 | // FIXME: For now, allow reinitialization as long as values don't |
| 80 | // change. This will go away when we move away from argument translation. |
| 81 | if (TargetInitialized && TargetIsIPhoneOS == isIPhoneOS && |
| 82 | TargetVersion[0] == Major && TargetVersion[1] == Minor && |
| 83 | TargetVersion[2] == Micro) |
| 84 | return; |
| 85 | |
| 86 | assert(!TargetInitialized && "Target already initialized!"); |
| 87 | TargetInitialized = true; |
| 88 | TargetIsIPhoneOS = isIPhoneOS; |
| 89 | TargetVersion[0] = Major; |
| 90 | TargetVersion[1] = Minor; |
| 91 | TargetVersion[2] = Micro; |
| 92 | } |
| 93 | |
| 94 | bool isTargetIPhoneOS() const { |
| 95 | assert(TargetInitialized && "Target not initialized!"); |
| 96 | return TargetIsIPhoneOS; |
| 97 | } |
| 98 | |
| 99 | void getTargetVersion(unsigned (&Res)[3]) const { |
| 100 | assert(TargetInitialized && "Target not initialized!"); |
| 101 | Res[0] = TargetVersion[0]; |
| 102 | Res[1] = TargetVersion[1]; |
| 103 | Res[2] = TargetVersion[2]; |
| 104 | } |
| 105 | |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 106 | /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler |
| 107 | /// invocation. For example, Darwin treats different ARM variations as |
| 108 | /// distinct architectures. |
| 109 | llvm::StringRef getDarwinArchName(const ArgList &Args) const; |
| 110 | |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 111 | static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) { |
Daniel Dunbar | 608d04c | 2009-09-18 08:14:55 +0000 | [diff] [blame] | 112 | for (unsigned i=0; i < 3; ++i) { |
| 113 | if (A[i] > B[i]) return false; |
| 114 | if (A[i] < B[i]) return true; |
| 115 | } |
| 116 | return false; |
| 117 | } |
| 118 | |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 119 | bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const { |
| 120 | assert(isTargetIPhoneOS() && "Unexpected call for OS X target!"); |
| 121 | unsigned B[3] = { V0, V1, V2 }; |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 122 | return isVersionLT(TargetVersion, B); |
| 123 | } |
| 124 | |
| 125 | bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const { |
| 126 | assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!"); |
| 127 | unsigned B[3] = { V0, V1, V2 }; |
| 128 | return isVersionLT(TargetVersion, B); |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 131 | /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs. |
| 132 | /// |
| 133 | /// \param Args - The input argument list. |
| 134 | /// \param CmdArgs [out] - The command argument list to append the paths |
| 135 | /// (prefixed by -L) to. |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 136 | virtual void AddLinkSearchPathArgs(const ArgList &Args, |
| 137 | ArgStringList &CmdArgs) const = 0; |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 138 | |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 139 | /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler |
| 140 | /// runtime library. |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 141 | virtual void AddLinkRuntimeLibArgs(const ArgList &Args, |
| 142 | ArgStringList &CmdArgs) const = 0; |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 143 | |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 144 | /// } |
| 145 | /// @name ToolChain Implementation |
| 146 | /// { |
| 147 | |
Daniel Dunbar | 0dcb9a3 | 2009-09-09 18:36:12 +0000 | [diff] [blame] | 148 | virtual DerivedArgList *TranslateArgs(InputArgList &Args, |
| 149 | const char *BoundArch) const; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 150 | |
| 151 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 152 | |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 153 | virtual bool IsBlocksDefault() const { |
Daniel Dunbar | 5435fc9 | 2010-01-27 00:57:11 +0000 | [diff] [blame] | 154 | // Blocks default to on for OS X 10.6 and iPhoneOS 3.0 and beyond. |
| 155 | if (isTargetIPhoneOS()) |
| 156 | return !isIPhoneOSVersionLT(3); |
| 157 | else |
| 158 | return !isMacosxVersionLT(10, 6); |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 159 | } |
| 160 | virtual bool IsObjCNonFragileABIDefault() const { |
Daniel Dunbar | 5435fc9 | 2010-01-27 00:57:11 +0000 | [diff] [blame] | 161 | // Non-fragile ABI default to on for iPhoneOS and x86-64. |
| 162 | return isTargetIPhoneOS() || getTriple().getArch() == llvm::Triple::x86_64; |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 163 | } |
Daniel Dunbar | 609508c | 2010-02-01 21:07:43 +0000 | [diff] [blame] | 164 | virtual bool IsObjCLegacyDispatchDefault() const { |
| 165 | // This is only used with the non-fragile ABI. |
| 166 | return (getTriple().getArch() == llvm::Triple::arm || |
| 167 | getTriple().getArch() == llvm::Triple::thumb); |
| 168 | } |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 169 | virtual bool IsUnwindTablesDefault() const; |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 170 | virtual unsigned GetDefaultStackProtectorLevel() const { |
Daniel Dunbar | 5435fc9 | 2010-01-27 00:57:11 +0000 | [diff] [blame] | 171 | // Stack protectors default to on for 10.6 and beyond. |
| 172 | return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6); |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 173 | } |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 174 | virtual const char *GetDefaultRelocationModel() const; |
| 175 | virtual const char *GetForcedPicModel() const; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 176 | |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 177 | virtual bool UseDwarfDebugFlags() const; |
| 178 | |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 179 | /// } |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 182 | /// DarwinClang - The Darwin toolchain used by Clang. |
| 183 | class VISIBILITY_HIDDEN DarwinClang : public Darwin { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 184 | public: |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 185 | DarwinClang(const HostInfo &Host, const llvm::Triple& Triple, |
Daniel Dunbar | cc8e189 | 2010-01-27 00:56:44 +0000 | [diff] [blame] | 186 | const unsigned (&DarwinVersion)[3]); |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 187 | |
| 188 | /// @name Darwin ToolChain Implementation |
| 189 | /// { |
| 190 | |
| 191 | virtual void AddLinkSearchPathArgs(const ArgList &Args, |
| 192 | ArgStringList &CmdArgs) const; |
| 193 | |
| 194 | virtual void AddLinkRuntimeLibArgs(const ArgList &Args, |
| 195 | ArgStringList &CmdArgs) const; |
| 196 | |
| 197 | /// } |
| 198 | }; |
| 199 | |
| 200 | /// DarwinGCC - The Darwin toolchain used by GCC. |
| 201 | class VISIBILITY_HIDDEN DarwinGCC : public Darwin { |
| 202 | /// GCC version to use. |
Ted Kremenek | 55bac53 | 2009-10-07 03:21:11 +0000 | [diff] [blame] | 203 | unsigned GCCVersion[3]; |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 204 | |
| 205 | /// The directory suffix for this tool chain. |
| 206 | std::string ToolChainDir; |
| 207 | |
| 208 | public: |
| 209 | DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple, |
Daniel Dunbar | cc8e189 | 2010-01-27 00:56:44 +0000 | [diff] [blame] | 210 | const unsigned (&DarwinVersion)[3], |
| 211 | const unsigned (&GCCVersion)[3]); |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 212 | |
| 213 | /// @name Darwin ToolChain Implementation |
| 214 | /// { |
| 215 | |
| 216 | virtual void AddLinkSearchPathArgs(const ArgList &Args, |
| 217 | ArgStringList &CmdArgs) const; |
| 218 | |
| 219 | virtual void AddLinkRuntimeLibArgs(const ArgList &Args, |
| 220 | ArgStringList &CmdArgs) const; |
| 221 | |
| 222 | /// } |
| 223 | }; |
| 224 | |
| 225 | /// Darwin_Generic_GCC - Generic Darwin tool chain using gcc. |
| 226 | class VISIBILITY_HIDDEN Darwin_Generic_GCC : public Generic_GCC { |
| 227 | public: |
| 228 | Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 229 | : Generic_GCC(Host, Triple) {} |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 230 | |
| 231 | virtual const char *GetDefaultRelocationModel() const { return "pic"; } |
| 232 | }; |
| 233 | |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 234 | class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC { |
| 235 | public: |
| 236 | AuroraUX(const HostInfo &Host, const llvm::Triple& Triple); |
| 237 | |
| 238 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 239 | }; |
| 240 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 241 | class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC { |
| 242 | public: |
| 243 | OpenBSD(const HostInfo &Host, const llvm::Triple& Triple); |
| 244 | |
| 245 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 246 | }; |
| 247 | |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 248 | class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC { |
| 249 | public: |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 250 | FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32); |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 251 | |
| 252 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 253 | }; |
| 254 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 255 | class VISIBILITY_HIDDEN DragonFly : public Generic_GCC { |
| 256 | public: |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 257 | DragonFly(const HostInfo &Host, const llvm::Triple& Triple); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 258 | |
| 259 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 260 | }; |
| 261 | |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 262 | class VISIBILITY_HIDDEN Linux : public Generic_GCC { |
| 263 | public: |
| 264 | Linux(const HostInfo &Host, const llvm::Triple& Triple); |
| 265 | }; |
| 266 | |
| 267 | |
Daniel Dunbar | 83b08eb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 268 | } // end namespace toolchains |
| 269 | } // end namespace driver |
| 270 | } // end namespace clang |
| 271 | |
| 272 | #endif |