blob: 2be88f10bf019d5d6b37dff07dfe9b7bca067829 [file] [log] [blame]
Daniel Dunbar83b08eb2009-03-17 21:38:00 +00001//===--- 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 Dunbar670b7f42009-03-17 22:07:31 +000013#include "clang/Driver/Action.h"
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000014#include "clang/Driver/ToolChain.h"
15
Daniel Dunbar670b7f42009-03-17 22:07:31 +000016#include "llvm/ADT/DenseMap.h"
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000017#include "llvm/Support/Compiler.h"
18
Daniel Dunbar670b7f42009-03-17 22:07:31 +000019#include "Tools.h"
20
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000021namespace clang {
22namespace driver {
Daniel Dunbar985b8252009-03-17 22:18:43 +000023namespace toolchains {
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000024
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000025/// 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.
Duncan Sands92dd1912010-05-11 20:16:05 +000028class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
Daniel Dunbar75358d22009-03-30 21:06:03 +000029protected:
Daniel Dunbar670b7f42009-03-17 22:07:31 +000030 mutable llvm::DenseMap<unsigned, Tool*> Tools;
31
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000032public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +000033 Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar39176082009-03-20 00:20:03 +000034 ~Generic_GCC();
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000035
Daniel Dunbar39176082009-03-20 00:20:03 +000036 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
Daniel Dunbar670b7f42009-03-17 22:07:31 +000037
Daniel Dunbar39176082009-03-20 00:20:03 +000038 virtual bool IsUnwindTablesDefault() const;
39 virtual const char *GetDefaultRelocationModel() const;
40 virtual const char *GetForcedPicModel() const;
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000041};
42
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000043/// Darwin - The base Darwin tool chain.
Duncan Sands92dd1912010-05-11 20:16:05 +000044class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000045 mutable llvm::DenseMap<unsigned, Tool*> Tools;
46
Daniel Dunbar26031372010-01-27 00:56:25 +000047 /// Whether the information on the target has been initialized.
48 //
49 // FIXME: This should be eliminated. What we want to do is make this part of
50 // the "default target for arguments" selection process, once we get out of
51 // the argument translation business.
52 mutable bool TargetInitialized;
53
54 /// Whether we are targetting iPhoneOS target.
55 mutable bool TargetIsIPhoneOS;
Daniel Dunbareb840bd2010-05-14 02:03:00 +000056
Daniel Dunbar26031372010-01-27 00:56:25 +000057 /// The OS version we are targetting.
58 mutable unsigned TargetVersion[3];
59
Daniel Dunbar02633b52009-03-26 16:23:12 +000060 /// The default macosx-version-min of this tool chain; empty until
61 /// initialized.
Daniel Dunbar816bc312010-01-26 01:45:19 +000062 std::string MacosxVersionMin;
Daniel Dunbar02633b52009-03-26 16:23:12 +000063
Daniel Dunbarc0e665e2010-07-19 17:11:33 +000064private:
Daniel Dunbar60baf0f2010-07-19 17:11:36 +000065 void AddDeploymentTarget(DerivedArgList &Args) const;
Daniel Dunbarc0e665e2010-07-19 17:11:33 +000066
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000067public:
Mike Stump1eb44332009-09-09 15:08:12 +000068 Darwin(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbarcc8e1892010-01-27 00:56:44 +000069 const unsigned (&DarwinVersion)[3]);
Daniel Dunbarf3955282009-09-04 18:34:51 +000070 ~Darwin();
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000071
Daniel Dunbar6b200b22009-09-18 08:14:36 +000072 /// @name Darwin Specific Toolchain API
73 /// {
74
Daniel Dunbar26031372010-01-27 00:56:25 +000075 // 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
Daniel Dunbar03d87ee2010-03-20 00:50:21 +000099 bool isTargetInitialized() const { return TargetInitialized; }
100
Daniel Dunbar26031372010-01-27 00:56:25 +0000101 void getTargetVersion(unsigned (&Res)[3]) const {
102 assert(TargetInitialized && "Target not initialized!");
103 Res[0] = TargetVersion[0];
104 Res[1] = TargetVersion[1];
105 Res[2] = TargetVersion[2];
106 }
107
Daniel Dunbareeff4062010-01-22 02:04:58 +0000108 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
109 /// invocation. For example, Darwin treats different ARM variations as
110 /// distinct architectures.
111 llvm::StringRef getDarwinArchName(const ArgList &Args) const;
112
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000113 static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
Daniel Dunbar608d04c2009-09-18 08:14:55 +0000114 for (unsigned i=0; i < 3; ++i) {
115 if (A[i] > B[i]) return false;
116 if (A[i] < B[i]) return true;
117 }
118 return false;
119 }
120
Daniel Dunbarcacb0f02010-01-27 00:56:56 +0000121 bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
122 assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
123 unsigned B[3] = { V0, V1, V2 };
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000124 return isVersionLT(TargetVersion, B);
125 }
126
127 bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
128 assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
129 unsigned B[3] = { V0, V1, V2 };
130 return isVersionLT(TargetVersion, B);
Daniel Dunbarcacb0f02010-01-27 00:56:56 +0000131 }
132
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000133 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
134 ///
135 /// \param Args - The input argument list.
136 /// \param CmdArgs [out] - The command argument list to append the paths
137 /// (prefixed by -L) to.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000138 virtual void AddLinkSearchPathArgs(const ArgList &Args,
139 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar02633b52009-03-26 16:23:12 +0000140
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000141 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
142 /// runtime library.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000143 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
144 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000145
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000146 /// }
147 /// @name ToolChain Implementation
148 /// {
149
Daniel Dunbar279c1db2010-06-11 22:00:26 +0000150 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000151 const char *BoundArch) const;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000152
153 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
154
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000155 virtual bool IsBlocksDefault() const {
Daniel Dunbar5435fc92010-01-27 00:57:11 +0000156 // Blocks default to on for OS X 10.6 and iPhoneOS 3.0 and beyond.
157 if (isTargetIPhoneOS())
158 return !isIPhoneOSVersionLT(3);
159 else
160 return !isMacosxVersionLT(10, 6);
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000161 }
Daniel Dunbareb840bd2010-05-14 02:03:00 +0000162 virtual bool IsIntegratedAssemblerDefault() const {
Daniel Dunbar71a6cbc2010-06-23 18:15:13 +0000163#ifdef DISABLE_DEFAULT_INTEGRATED_ASSEMBLER
164 return false;
165#else
Daniel Dunbareb840bd2010-05-14 02:03:00 +0000166 // Default integrated assembler to on for x86.
167 return (getTriple().getArch() == llvm::Triple::x86 ||
168 getTriple().getArch() == llvm::Triple::x86_64);
Daniel Dunbar71a6cbc2010-06-23 18:15:13 +0000169#endif
Daniel Dunbareb840bd2010-05-14 02:03:00 +0000170 }
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000171 virtual bool IsObjCNonFragileABIDefault() const {
Daniel Dunbarf645aaa2010-04-24 18:37:41 +0000172 // Non-fragile ABI is default for everything but i386.
173 return getTriple().getArch() != llvm::Triple::x86;
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000174 }
Daniel Dunbar609508c2010-02-01 21:07:43 +0000175 virtual bool IsObjCLegacyDispatchDefault() const {
176 // This is only used with the non-fragile ABI.
Daniel Dunbarf645aaa2010-04-24 18:37:41 +0000177
178 // Legacy dispatch is used everywhere except on x86_64.
179 return getTriple().getArch() != llvm::Triple::x86_64;
Daniel Dunbar609508c2010-02-01 21:07:43 +0000180 }
Daniel Dunbarf643b9b2010-04-24 17:56:46 +0000181 virtual bool UseObjCMixedDispatch() const {
Daniel Dunbarf645aaa2010-04-24 18:37:41 +0000182 // This is only used with the non-fragile ABI and non-legacy dispatch.
183
184 // Mixed dispatch is used everywhere except OS X before 10.6.
185 return !(!isTargetIPhoneOS() && isMacosxVersionLT(10, 6));
Daniel Dunbarf643b9b2010-04-24 17:56:46 +0000186 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000187 virtual bool IsUnwindTablesDefault() const;
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000188 virtual unsigned GetDefaultStackProtectorLevel() const {
Daniel Dunbar5435fc92010-01-27 00:57:11 +0000189 // Stack protectors default to on for 10.6 and beyond.
190 return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6);
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000191 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000192 virtual const char *GetDefaultRelocationModel() const;
193 virtual const char *GetForcedPicModel() const;
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000194
Daniel Dunbar43a9b322010-04-10 16:20:23 +0000195 virtual bool SupportsObjCGC() const;
196
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000197 virtual bool UseDwarfDebugFlags() const;
198
Daniel Dunbarb2987d12010-02-10 18:49:11 +0000199 virtual bool UseSjLjExceptions() const;
200
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000201 /// }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000202};
203
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000204/// DarwinClang - The Darwin toolchain used by Clang.
Duncan Sands92dd1912010-05-11 20:16:05 +0000205class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000206public:
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000207 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000208 const unsigned (&DarwinVersion)[3]);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000209
210 /// @name Darwin ToolChain Implementation
211 /// {
212
213 virtual void AddLinkSearchPathArgs(const ArgList &Args,
214 ArgStringList &CmdArgs) const;
215
216 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
217 ArgStringList &CmdArgs) const;
218
219 /// }
220};
221
222/// DarwinGCC - The Darwin toolchain used by GCC.
Duncan Sands92dd1912010-05-11 20:16:05 +0000223class LLVM_LIBRARY_VISIBILITY DarwinGCC : public Darwin {
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000224 /// GCC version to use.
Ted Kremenek55bac532009-10-07 03:21:11 +0000225 unsigned GCCVersion[3];
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000226
227 /// The directory suffix for this tool chain.
228 std::string ToolChainDir;
229
230public:
231 DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000232 const unsigned (&DarwinVersion)[3],
233 const unsigned (&GCCVersion)[3]);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000234
235 /// @name Darwin ToolChain Implementation
236 /// {
237
238 virtual void AddLinkSearchPathArgs(const ArgList &Args,
239 ArgStringList &CmdArgs) const;
240
241 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
242 ArgStringList &CmdArgs) const;
243
244 /// }
245};
246
247/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
Duncan Sands92dd1912010-05-11 20:16:05 +0000248class LLVM_LIBRARY_VISIBILITY Darwin_Generic_GCC : public Generic_GCC {
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000249public:
250 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000251 : Generic_GCC(Host, Triple) {}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000252
253 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
254};
255
Duncan Sands92dd1912010-05-11 20:16:05 +0000256class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC {
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000257public:
258 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
259
260 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
261};
262
Duncan Sands92dd1912010-05-11 20:16:05 +0000263class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_GCC {
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000264public:
265 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
266
267 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
268};
269
Duncan Sands92dd1912010-05-11 20:16:05 +0000270class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_GCC {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000271public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000272 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
Daniel Dunbar75358d22009-03-30 21:06:03 +0000273
274 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
275};
276
Chris Lattner38e317d2010-07-07 16:01:42 +0000277class LLVM_LIBRARY_VISIBILITY Minix : public Generic_GCC {
278public:
279 Minix(const HostInfo &Host, const llvm::Triple& Triple);
280
281 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
282};
283
Duncan Sands92dd1912010-05-11 20:16:05 +0000284class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_GCC {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000285public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000286 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000287
288 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
289};
290
Duncan Sands92dd1912010-05-11 20:16:05 +0000291class LLVM_LIBRARY_VISIBILITY Linux : public Generic_GCC {
Eli Friedman6b3454a2009-05-26 07:52:18 +0000292public:
293 Linux(const HostInfo &Host, const llvm::Triple& Triple);
294};
295
296
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000297/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
298/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
Duncan Sands92dd1912010-05-11 20:16:05 +0000299class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000300public:
301 TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple);
302 ~TCEToolChain();
303
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000304 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
305 bool IsMathErrnoDefault() const;
306 bool IsUnwindTablesDefault() const;
307 const char* GetDefaultRelocationModel() const;
308 const char* GetForcedPicModel() const;
309
310private:
311 mutable llvm::DenseMap<unsigned, Tool*> Tools;
312
313};
314
Daniel Dunbar83b08eb2009-03-17 21:38:00 +0000315} // end namespace toolchains
316} // end namespace driver
317} // end namespace clang
318
319#endif