Daniel Dunbar | 0a248bb | 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 | 04cb029 | 2009-03-17 22:07:31 +0000 | [diff] [blame] | 13 | #include "clang/Driver/Action.h" |
Daniel Dunbar | 0a248bb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 14 | #include "clang/Driver/ToolChain.h" |
| 15 | |
Daniel Dunbar | 04cb029 | 2009-03-17 22:07:31 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/DenseMap.h" |
Daniel Dunbar | 0a248bb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Compiler.h" |
| 18 | |
Daniel Dunbar | 04cb029 | 2009-03-17 22:07:31 +0000 | [diff] [blame] | 19 | #include "Tools.h" |
| 20 | |
Daniel Dunbar | 0a248bb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 21 | namespace clang { |
| 22 | namespace driver { |
Daniel Dunbar | 15abb2e | 2009-03-17 22:18:43 +0000 | [diff] [blame] | 23 | namespace toolchains { |
Daniel Dunbar | 0a248bb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 24 | |
Daniel Dunbar | 6276f99 | 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 | 15abb2e | 2009-03-17 22:18:43 +0000 | [diff] [blame] | 28 | class VISIBILITY_HIDDEN Generic_GCC : public ToolChain { |
Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 29 | protected: |
Daniel Dunbar | 04cb029 | 2009-03-17 22:07:31 +0000 | [diff] [blame] | 30 | mutable llvm::DenseMap<unsigned, Tool*> Tools; |
| 31 | |
Daniel Dunbar | 0a248bb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 32 | public: |
Daniel Dunbar | 51c7f97 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 33 | Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple); |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 34 | ~Generic_GCC(); |
Daniel Dunbar | 0a248bb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 35 | |
Daniel Dunbar | e7af341 | 2009-09-09 18:36:12 +0000 | [diff] [blame] | 36 | virtual DerivedArgList *TranslateArgs(InputArgList &Args, |
| 37 | const char *BoundArch) const; |
Daniel Dunbar | 0a248bb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 38 | |
Daniel Dunbar | 59e5e88 | 2009-03-20 00:20:03 +0000 | [diff] [blame] | 39 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
Daniel Dunbar | 04cb029 | 2009-03-17 22:07:31 +0000 | [diff] [blame] | 40 | |
Daniel Dunbar | 59e5e88 | 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 | 0a248bb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 46 | /// Darwin - The base Darwin tool chain. |
Daniel Dunbar | f0a5b9b | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 47 | class VISIBILITY_HIDDEN Darwin : public ToolChain { |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 48 | mutable llvm::DenseMap<unsigned, Tool*> Tools; |
| 49 | |
Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 50 | /// Darwin version of tool chain. |
| 51 | unsigned DarwinVersion[3]; |
| 52 | |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame^] | 53 | /// Whether the information on the target has been initialized. |
| 54 | // |
| 55 | // FIXME: This should be eliminated. What we want to do is make this part of |
| 56 | // the "default target for arguments" selection process, once we get out of |
| 57 | // the argument translation business. |
| 58 | mutable bool TargetInitialized; |
| 59 | |
| 60 | /// Whether we are targetting iPhoneOS target. |
| 61 | mutable bool TargetIsIPhoneOS; |
| 62 | |
| 63 | /// The OS version we are targetting. |
| 64 | mutable unsigned TargetVersion[3]; |
| 65 | |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 66 | /// Whether this is this an iPhoneOS toolchain. |
| 67 | // |
| 68 | // FIXME: This should go away, such differences should be completely |
| 69 | // determined by the target triple. |
Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 70 | // |
| 71 | // FIXME: It is also broken, we need to distinguish the "default target" from |
| 72 | // the actual target. The -m...-version-min strings and deployment targets can |
| 73 | // change this. |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 74 | bool IsIPhoneOS; |
Daniel Dunbar | 76ce741 | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 75 | |
Daniel Dunbar | c196421 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 76 | /// The default macosx-version-min of this tool chain; empty until |
| 77 | /// initialized. |
Daniel Dunbar | d54669d | 2010-01-26 01:45:19 +0000 | [diff] [blame] | 78 | std::string MacosxVersionMin; |
Daniel Dunbar | c196421 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 79 | |
Daniel Dunbar | 84e727f | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 80 | /// The default iphoneos-version-min of this tool chain. |
| 81 | std::string IPhoneOSVersionMin; |
| 82 | |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 83 | public: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 84 | Darwin(const HostInfo &Host, const llvm::Triple& Triple, |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 85 | const unsigned (&DarwinVersion)[3], bool IsIPhoneOS); |
Daniel Dunbar | f0a5b9b | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 86 | ~Darwin(); |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 87 | |
Daniel Dunbar | 4c30b89 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 88 | /// @name Darwin Specific Toolchain API |
| 89 | /// { |
| 90 | |
Daniel Dunbar | 3b8e50d | 2010-01-27 00:56:25 +0000 | [diff] [blame^] | 91 | // FIXME: Eliminate these ...Target functions and derive separate tool chains |
| 92 | // for these targets and put version in constructor. |
| 93 | void setTarget(bool isIPhoneOS, unsigned Major, unsigned Minor, |
| 94 | unsigned Micro) const { |
| 95 | // FIXME: For now, allow reinitialization as long as values don't |
| 96 | // change. This will go away when we move away from argument translation. |
| 97 | if (TargetInitialized && TargetIsIPhoneOS == isIPhoneOS && |
| 98 | TargetVersion[0] == Major && TargetVersion[1] == Minor && |
| 99 | TargetVersion[2] == Micro) |
| 100 | return; |
| 101 | |
| 102 | assert(!TargetInitialized && "Target already initialized!"); |
| 103 | TargetInitialized = true; |
| 104 | TargetIsIPhoneOS = isIPhoneOS; |
| 105 | TargetVersion[0] = Major; |
| 106 | TargetVersion[1] = Minor; |
| 107 | TargetVersion[2] = Micro; |
| 108 | } |
| 109 | |
| 110 | bool isTargetIPhoneOS() const { |
| 111 | assert(TargetInitialized && "Target not initialized!"); |
| 112 | return TargetIsIPhoneOS; |
| 113 | } |
| 114 | |
| 115 | void getTargetVersion(unsigned (&Res)[3]) const { |
| 116 | assert(TargetInitialized && "Target not initialized!"); |
| 117 | Res[0] = TargetVersion[0]; |
| 118 | Res[1] = TargetVersion[1]; |
| 119 | Res[2] = TargetVersion[2]; |
| 120 | } |
| 121 | |
Daniel Dunbar | c196421 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 122 | void getDarwinVersion(unsigned (&Res)[3]) const { |
| 123 | Res[0] = DarwinVersion[0]; |
| 124 | Res[1] = DarwinVersion[1]; |
| 125 | Res[2] = DarwinVersion[2]; |
| 126 | } |
| 127 | |
| 128 | void getMacosxVersion(unsigned (&Res)[3]) const { |
| 129 | Res[0] = 10; |
| 130 | Res[1] = DarwinVersion[0] - 4; |
| 131 | Res[2] = DarwinVersion[1]; |
| 132 | } |
| 133 | |
Daniel Dunbar | dcc3b65 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 134 | /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler |
| 135 | /// invocation. For example, Darwin treats different ARM variations as |
| 136 | /// distinct architectures. |
| 137 | llvm::StringRef getDarwinArchName(const ArgList &Args) const; |
| 138 | |
Daniel Dunbar | 510d8a8 | 2009-09-18 08:14:46 +0000 | [diff] [blame] | 139 | /// getMacosxVersionMin - Get the effective -mmacosx-version-min, which is |
| 140 | /// either the -mmacosx-version-min, or the current version if unspecified. |
| 141 | void getMacosxVersionMin(const ArgList &Args, unsigned (&Res)[3]) const; |
| 142 | |
Daniel Dunbar | d5bd81e | 2009-09-18 08:14:55 +0000 | [diff] [blame] | 143 | static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) { |
| 144 | for (unsigned i=0; i < 3; ++i) { |
| 145 | if (A[i] > B[i]) return false; |
| 146 | if (A[i] < B[i]) return true; |
| 147 | } |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | static bool isMacosxVersionLT(unsigned (&A)[3], |
| 152 | unsigned V0, unsigned V1=0, unsigned V2=0) { |
| 153 | unsigned B[3] = { V0, V1, V2 }; |
| 154 | return isMacosxVersionLT(A, B); |
| 155 | } |
| 156 | |
Daniel Dunbar | 4c30b89 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 157 | /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs. |
| 158 | /// |
| 159 | /// \param Args - The input argument list. |
| 160 | /// \param CmdArgs [out] - The command argument list to append the paths |
| 161 | /// (prefixed by -L) to. |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 162 | virtual void AddLinkSearchPathArgs(const ArgList &Args, |
| 163 | ArgStringList &CmdArgs) const = 0; |
Daniel Dunbar | c196421 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 164 | |
Daniel Dunbar | 26d482a | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 165 | /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler |
| 166 | /// runtime library. |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 167 | virtual void AddLinkRuntimeLibArgs(const ArgList &Args, |
| 168 | ArgStringList &CmdArgs) const = 0; |
Daniel Dunbar | 26d482a | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 169 | |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 170 | bool isIPhoneOS() const { return IsIPhoneOS; } |
Daniel Dunbar | 84e727f | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 171 | |
Daniel Dunbar | 4c30b89 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 172 | /// } |
| 173 | /// @name ToolChain Implementation |
| 174 | /// { |
| 175 | |
Daniel Dunbar | e7af341 | 2009-09-09 18:36:12 +0000 | [diff] [blame] | 176 | virtual DerivedArgList *TranslateArgs(InputArgList &Args, |
| 177 | const char *BoundArch) const; |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 178 | |
| 179 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 180 | |
Daniel Dunbar | 4930e33 | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 181 | virtual bool IsBlocksDefault() const { |
| 182 | // Blocks default to on for 10.6 (darwin10) and beyond. |
| 183 | return (DarwinVersion[0] > 9); |
| 184 | } |
| 185 | virtual bool IsObjCNonFragileABIDefault() const { |
| 186 | // Non-fragile ABI default to on for 10.5 (darwin9) and beyond on x86-64. |
| 187 | return (DarwinVersion[0] >= 9 && |
| 188 | getTriple().getArch() == llvm::Triple::x86_64); |
| 189 | } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 190 | virtual bool IsUnwindTablesDefault() const; |
Daniel Dunbar | 4930e33 | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 191 | virtual unsigned GetDefaultStackProtectorLevel() const { |
| 192 | // Stack protectors default to on for 10.6 (darwin10) and beyond. |
| 193 | return (DarwinVersion[0] > 9) ? 1 : 0; |
| 194 | } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 195 | virtual const char *GetDefaultRelocationModel() const; |
| 196 | virtual const char *GetForcedPicModel() const; |
Daniel Dunbar | 4c30b89 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 197 | |
Daniel Dunbar | 24c7f5e | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 198 | virtual bool UseDwarfDebugFlags() const; |
| 199 | |
Daniel Dunbar | 4c30b89 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 200 | /// } |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 201 | }; |
| 202 | |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 203 | /// DarwinClang - The Darwin toolchain used by Clang. |
| 204 | class VISIBILITY_HIDDEN DarwinClang : public Darwin { |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 205 | public: |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 206 | DarwinClang(const HostInfo &Host, const llvm::Triple& Triple, |
| 207 | const unsigned (&DarwinVersion)[3], bool IsIPhoneOS); |
| 208 | |
| 209 | /// @name Darwin ToolChain Implementation |
| 210 | /// { |
| 211 | |
| 212 | virtual void AddLinkSearchPathArgs(const ArgList &Args, |
| 213 | ArgStringList &CmdArgs) const; |
| 214 | |
| 215 | virtual void AddLinkRuntimeLibArgs(const ArgList &Args, |
| 216 | ArgStringList &CmdArgs) const; |
| 217 | |
| 218 | /// } |
| 219 | }; |
| 220 | |
| 221 | /// DarwinGCC - The Darwin toolchain used by GCC. |
| 222 | class VISIBILITY_HIDDEN DarwinGCC : public Darwin { |
| 223 | /// GCC version to use. |
Ted Kremenek | 7881ac9 | 2009-10-07 03:21:11 +0000 | [diff] [blame] | 224 | unsigned GCCVersion[3]; |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 225 | |
| 226 | /// The directory suffix for this tool chain. |
| 227 | std::string ToolChainDir; |
| 228 | |
| 229 | public: |
| 230 | DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple, |
Ted Kremenek | 7881ac9 | 2009-10-07 03:21:11 +0000 | [diff] [blame] | 231 | const unsigned (&DarwinVersion)[3], const unsigned (&GCCVersion)[3], |
Daniel Dunbar | 6276f99 | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 232 | bool IsIPhoneOS); |
| 233 | |
| 234 | /// @name Darwin ToolChain Implementation |
| 235 | /// { |
| 236 | |
| 237 | virtual void AddLinkSearchPathArgs(const ArgList &Args, |
| 238 | ArgStringList &CmdArgs) const; |
| 239 | |
| 240 | virtual void AddLinkRuntimeLibArgs(const ArgList &Args, |
| 241 | ArgStringList &CmdArgs) const; |
| 242 | |
| 243 | /// } |
| 244 | }; |
| 245 | |
| 246 | /// Darwin_Generic_GCC - Generic Darwin tool chain using gcc. |
| 247 | class VISIBILITY_HIDDEN Darwin_Generic_GCC : public Generic_GCC { |
| 248 | public: |
| 249 | Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) |
Daniel Dunbar | 51c7f97 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 250 | : Generic_GCC(Host, Triple) {} |
Daniel Dunbar | 03e0a4f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 251 | |
| 252 | virtual const char *GetDefaultRelocationModel() const { return "pic"; } |
| 253 | }; |
| 254 | |
Edward O'Callaghan | 856e4ff | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 255 | class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC { |
| 256 | public: |
| 257 | AuroraUX(const HostInfo &Host, const llvm::Triple& Triple); |
| 258 | |
| 259 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 260 | }; |
| 261 | |
Daniel Dunbar | 10de9e6 | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 262 | class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC { |
| 263 | public: |
| 264 | OpenBSD(const HostInfo &Host, const llvm::Triple& Triple); |
| 265 | |
| 266 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 267 | }; |
| 268 | |
Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 269 | class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC { |
| 270 | public: |
Daniel Dunbar | 51c7f97 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 271 | FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32); |
Daniel Dunbar | e24297c | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 272 | |
| 273 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 274 | }; |
| 275 | |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 276 | class VISIBILITY_HIDDEN DragonFly : public Generic_GCC { |
| 277 | public: |
Daniel Dunbar | 51c7f97 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 278 | DragonFly(const HostInfo &Host, const llvm::Triple& Triple); |
Daniel Dunbar | cc91234 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 279 | |
| 280 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 281 | }; |
| 282 | |
Eli Friedman | 5cd659f | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 283 | class VISIBILITY_HIDDEN Linux : public Generic_GCC { |
| 284 | public: |
| 285 | Linux(const HostInfo &Host, const llvm::Triple& Triple); |
| 286 | }; |
| 287 | |
| 288 | |
Daniel Dunbar | 0a248bb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 289 | } // end namespace toolchains |
| 290 | } // end namespace driver |
| 291 | } // end namespace clang |
| 292 | |
| 293 | #endif |