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 IsMathErrnoDefault() const; |
| 42 | virtual bool IsUnwindTablesDefault() const; |
| 43 | virtual const char *GetDefaultRelocationModel() const; |
| 44 | virtual const char *GetForcedPicModel() const; |
Daniel Dunbar | 83b08eb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 47 | /// Darwin - The base Darwin tool chain. |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 48 | class VISIBILITY_HIDDEN Darwin : public ToolChain { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 49 | mutable llvm::DenseMap<unsigned, Tool*> Tools; |
| 50 | |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 51 | /// Darwin version of tool chain. |
| 52 | unsigned DarwinVersion[3]; |
| 53 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 54 | /// Whether this is this an iPhoneOS toolchain. |
| 55 | // |
| 56 | // FIXME: This should go away, such differences should be completely |
| 57 | // determined by the target triple. |
| 58 | bool IsIPhoneOS; |
Daniel Dunbar | c50b00d | 2009-03-23 16:15:50 +0000 | [diff] [blame] | 59 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 60 | /// The default macosx-version-min of this tool chain; empty until |
| 61 | /// initialized. |
| 62 | mutable std::string MacosxVersionMin; |
| 63 | |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 64 | /// The default iphoneos-version-min of this tool chain. |
| 65 | std::string IPhoneOSVersionMin; |
| 66 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 67 | const char *getMacosxVersionMin() const; |
Daniel Dunbar | ec069ed | 2009-03-25 06:58:31 +0000 | [diff] [blame] | 68 | |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 69 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 70 | Darwin(const HostInfo &Host, const llvm::Triple& Triple, |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 71 | const unsigned (&DarwinVersion)[3], bool IsIPhoneOS); |
Daniel Dunbar | f395528 | 2009-09-04 18:34:51 +0000 | [diff] [blame] | 72 | ~Darwin(); |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 73 | |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 74 | /// @name Darwin Specific Toolchain API |
| 75 | /// { |
| 76 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 77 | void getDarwinVersion(unsigned (&Res)[3]) const { |
| 78 | Res[0] = DarwinVersion[0]; |
| 79 | Res[1] = DarwinVersion[1]; |
| 80 | Res[2] = DarwinVersion[2]; |
| 81 | } |
| 82 | |
| 83 | void getMacosxVersion(unsigned (&Res)[3]) const { |
| 84 | Res[0] = 10; |
| 85 | Res[1] = DarwinVersion[0] - 4; |
| 86 | Res[2] = DarwinVersion[1]; |
| 87 | } |
| 88 | |
Daniel Dunbar | 48d5aae | 2009-09-18 08:14:46 +0000 | [diff] [blame] | 89 | /// getMacosxVersionMin - Get the effective -mmacosx-version-min, which is |
| 90 | /// either the -mmacosx-version-min, or the current version if unspecified. |
| 91 | void getMacosxVersionMin(const ArgList &Args, unsigned (&Res)[3]) const; |
| 92 | |
Daniel Dunbar | 608d04c | 2009-09-18 08:14:55 +0000 | [diff] [blame] | 93 | static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) { |
| 94 | for (unsigned i=0; i < 3; ++i) { |
| 95 | if (A[i] > B[i]) return false; |
| 96 | if (A[i] < B[i]) return true; |
| 97 | } |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | static bool isMacosxVersionLT(unsigned (&A)[3], |
| 102 | unsigned V0, unsigned V1=0, unsigned V2=0) { |
| 103 | unsigned B[3] = { V0, V1, V2 }; |
| 104 | return isMacosxVersionLT(A, B); |
| 105 | } |
| 106 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 107 | const char *getMacosxVersionStr() const { |
| 108 | return MacosxVersionMin.c_str(); |
| 109 | } |
| 110 | |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 111 | const char *getIPhoneOSVersionStr() const { |
| 112 | return IPhoneOSVersionMin.c_str(); |
| 113 | } |
| 114 | |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 115 | /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs. |
| 116 | /// |
| 117 | /// \param Args - The input argument list. |
| 118 | /// \param CmdArgs [out] - The command argument list to append the paths |
| 119 | /// (prefixed by -L) to. |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 120 | virtual void AddLinkSearchPathArgs(const ArgList &Args, |
| 121 | ArgStringList &CmdArgs) const = 0; |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 122 | |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 123 | /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler |
| 124 | /// runtime library. |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 125 | virtual void AddLinkRuntimeLibArgs(const ArgList &Args, |
| 126 | ArgStringList &CmdArgs) const = 0; |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 127 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 128 | bool isIPhoneOS() const { return IsIPhoneOS; } |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 129 | |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 130 | /// } |
| 131 | /// @name ToolChain Implementation |
| 132 | /// { |
| 133 | |
Daniel Dunbar | 0dcb9a3 | 2009-09-09 18:36:12 +0000 | [diff] [blame] | 134 | virtual DerivedArgList *TranslateArgs(InputArgList &Args, |
| 135 | const char *BoundArch) const; |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 136 | |
| 137 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 138 | |
| 139 | virtual bool IsMathErrnoDefault() const; |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 140 | virtual bool IsBlocksDefault() const { |
| 141 | // Blocks default to on for 10.6 (darwin10) and beyond. |
| 142 | return (DarwinVersion[0] > 9); |
| 143 | } |
| 144 | virtual bool IsObjCNonFragileABIDefault() const { |
| 145 | // Non-fragile ABI default to on for 10.5 (darwin9) and beyond on x86-64. |
| 146 | return (DarwinVersion[0] >= 9 && |
| 147 | getTriple().getArch() == llvm::Triple::x86_64); |
| 148 | } |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 149 | virtual bool IsUnwindTablesDefault() const; |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 150 | virtual unsigned GetDefaultStackProtectorLevel() const { |
| 151 | // Stack protectors default to on for 10.6 (darwin10) and beyond. |
| 152 | return (DarwinVersion[0] > 9) ? 1 : 0; |
| 153 | } |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 154 | virtual const char *GetDefaultRelocationModel() const; |
| 155 | virtual const char *GetForcedPicModel() const; |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 156 | |
| 157 | /// } |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 158 | }; |
| 159 | |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 160 | /// DarwinClang - The Darwin toolchain used by Clang. |
| 161 | class VISIBILITY_HIDDEN DarwinClang : public Darwin { |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 162 | public: |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 163 | DarwinClang(const HostInfo &Host, const llvm::Triple& Triple, |
| 164 | const unsigned (&DarwinVersion)[3], bool IsIPhoneOS); |
| 165 | |
| 166 | /// @name Darwin ToolChain Implementation |
| 167 | /// { |
| 168 | |
| 169 | virtual void AddLinkSearchPathArgs(const ArgList &Args, |
| 170 | ArgStringList &CmdArgs) const; |
| 171 | |
| 172 | virtual void AddLinkRuntimeLibArgs(const ArgList &Args, |
| 173 | ArgStringList &CmdArgs) const; |
| 174 | |
| 175 | /// } |
| 176 | }; |
| 177 | |
| 178 | /// DarwinGCC - The Darwin toolchain used by GCC. |
| 179 | class VISIBILITY_HIDDEN DarwinGCC : public Darwin { |
| 180 | /// GCC version to use. |
Ted Kremenek | 55bac53 | 2009-10-07 03:21:11 +0000 | [diff] [blame] | 181 | unsigned GCCVersion[3]; |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 182 | |
| 183 | /// The directory suffix for this tool chain. |
| 184 | std::string ToolChainDir; |
| 185 | |
| 186 | public: |
| 187 | DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple, |
Ted Kremenek | 55bac53 | 2009-10-07 03:21:11 +0000 | [diff] [blame] | 188 | const unsigned (&DarwinVersion)[3], const unsigned (&GCCVersion)[3], |
Daniel Dunbar | 1d4612b | 2009-09-18 08:15:13 +0000 | [diff] [blame] | 189 | bool IsIPhoneOS); |
| 190 | |
| 191 | /// @name Darwin ToolChain Implementation |
| 192 | /// { |
| 193 | |
| 194 | virtual void AddLinkSearchPathArgs(const ArgList &Args, |
| 195 | ArgStringList &CmdArgs) const; |
| 196 | |
| 197 | virtual void AddLinkRuntimeLibArgs(const ArgList &Args, |
| 198 | ArgStringList &CmdArgs) const; |
| 199 | |
| 200 | /// } |
| 201 | }; |
| 202 | |
| 203 | /// Darwin_Generic_GCC - Generic Darwin tool chain using gcc. |
| 204 | class VISIBILITY_HIDDEN Darwin_Generic_GCC : public Generic_GCC { |
| 205 | public: |
| 206 | Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 207 | : Generic_GCC(Host, Triple) {} |
Daniel Dunbar | 8eddb3f | 2009-03-20 00:57:52 +0000 | [diff] [blame] | 208 | |
| 209 | virtual const char *GetDefaultRelocationModel() const { return "pic"; } |
| 210 | }; |
| 211 | |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 212 | class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC { |
| 213 | public: |
| 214 | AuroraUX(const HostInfo &Host, const llvm::Triple& Triple); |
| 215 | |
| 216 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 217 | }; |
| 218 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 219 | class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC { |
| 220 | public: |
| 221 | OpenBSD(const HostInfo &Host, const llvm::Triple& Triple); |
| 222 | |
| 223 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 224 | }; |
| 225 | |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 226 | class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC { |
| 227 | public: |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 228 | FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32); |
Daniel Dunbar | 75358d2 | 2009-03-30 21:06:03 +0000 | [diff] [blame] | 229 | |
| 230 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 231 | }; |
| 232 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 233 | class VISIBILITY_HIDDEN DragonFly : public Generic_GCC { |
| 234 | public: |
Daniel Dunbar | cb8ab23 | 2009-05-22 02:53:45 +0000 | [diff] [blame] | 235 | DragonFly(const HostInfo &Host, const llvm::Triple& Triple); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 236 | |
| 237 | virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const; |
| 238 | }; |
| 239 | |
Eli Friedman | 6b3454a | 2009-05-26 07:52:18 +0000 | [diff] [blame] | 240 | class VISIBILITY_HIDDEN Linux : public Generic_GCC { |
| 241 | public: |
| 242 | Linux(const HostInfo &Host, const llvm::Triple& Triple); |
| 243 | }; |
| 244 | |
| 245 | |
Daniel Dunbar | 83b08eb | 2009-03-17 21:38:00 +0000 | [diff] [blame] | 246 | } // end namespace toolchains |
| 247 | } // end namespace driver |
| 248 | } // end namespace clang |
| 249 | |
| 250 | #endif |