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