blob: 4bdd00fc2583484f5df8b1011bee5cc57fe2f9eb [file] [log] [blame]
Daniel Dunbar0a248bb2009-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 Dunbar04cb0292009-03-17 22:07:31 +000013#include "clang/Driver/Action.h"
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000014#include "clang/Driver/ToolChain.h"
15
Daniel Dunbar04cb0292009-03-17 22:07:31 +000016#include "llvm/ADT/DenseMap.h"
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000017#include "llvm/Support/Compiler.h"
18
Daniel Dunbar04cb0292009-03-17 22:07:31 +000019#include "Tools.h"
20
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000021namespace clang {
22namespace driver {
Daniel Dunbar15abb2e2009-03-17 22:18:43 +000023namespace toolchains {
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000024
Daniel Dunbar6276f992009-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 Sandsaf260b92010-05-11 20:16:05 +000028class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
Daniel Dunbare24297c2009-03-30 21:06:03 +000029protected:
Daniel Dunbar04cb0292009-03-17 22:07:31 +000030 mutable llvm::DenseMap<unsigned, Tool*> Tools;
31
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000032public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +000033 Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar59e5e882009-03-20 00:20:03 +000034 ~Generic_GCC();
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000035
Daniel Dunbar59e5e882009-03-20 00:20:03 +000036 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
Daniel Dunbar04cb0292009-03-17 22:07:31 +000037
Daniel Dunbar59e5e882009-03-20 00:20:03 +000038 virtual bool IsUnwindTablesDefault() const;
39 virtual const char *GetDefaultRelocationModel() const;
40 virtual const char *GetForcedPicModel() const;
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000041};
42
Daniel Dunbar6276f992009-09-18 08:15:13 +000043/// Darwin - The base Darwin tool chain.
Duncan Sandsaf260b92010-05-11 20:16:05 +000044class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000045 mutable llvm::DenseMap<unsigned, Tool*> Tools;
46
Daniel Dunbar3b8e50d2010-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 Dunbarf9ff3502010-05-14 02:03:00 +000056
Daniel Dunbar3b8e50d2010-01-27 00:56:25 +000057 /// The OS version we are targetting.
58 mutable unsigned TargetVersion[3];
59
Daniel Dunbarc1964212009-03-26 16:23:12 +000060 /// The default macosx-version-min of this tool chain; empty until
61 /// initialized.
Daniel Dunbard54669d2010-01-26 01:45:19 +000062 std::string MacosxVersionMin;
Daniel Dunbarc1964212009-03-26 16:23:12 +000063
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000064public:
Mike Stump11289f42009-09-09 15:08:12 +000065 Darwin(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbar7c8701752010-01-27 00:56:44 +000066 const unsigned (&DarwinVersion)[3]);
Daniel Dunbarf0a5b9b2009-09-04 18:34:51 +000067 ~Darwin();
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000068
Daniel Dunbar4c30b892009-09-18 08:14:36 +000069 /// @name Darwin Specific Toolchain API
70 /// {
71
Daniel Dunbar3b8e50d2010-01-27 00:56:25 +000072 // FIXME: Eliminate these ...Target functions and derive separate tool chains
73 // for these targets and put version in constructor.
74 void setTarget(bool isIPhoneOS, unsigned Major, unsigned Minor,
75 unsigned Micro) const {
76 // FIXME: For now, allow reinitialization as long as values don't
77 // change. This will go away when we move away from argument translation.
78 if (TargetInitialized && TargetIsIPhoneOS == isIPhoneOS &&
79 TargetVersion[0] == Major && TargetVersion[1] == Minor &&
80 TargetVersion[2] == Micro)
81 return;
82
83 assert(!TargetInitialized && "Target already initialized!");
84 TargetInitialized = true;
85 TargetIsIPhoneOS = isIPhoneOS;
86 TargetVersion[0] = Major;
87 TargetVersion[1] = Minor;
88 TargetVersion[2] = Micro;
89 }
90
91 bool isTargetIPhoneOS() const {
92 assert(TargetInitialized && "Target not initialized!");
93 return TargetIsIPhoneOS;
94 }
95
Daniel Dunbar47d25b12010-03-20 00:50:21 +000096 bool isTargetInitialized() const { return TargetInitialized; }
97
Daniel Dunbar3b8e50d2010-01-27 00:56:25 +000098 void getTargetVersion(unsigned (&Res)[3]) const {
99 assert(TargetInitialized && "Target not initialized!");
100 Res[0] = TargetVersion[0];
101 Res[1] = TargetVersion[1];
102 Res[2] = TargetVersion[2];
103 }
104
Daniel Dunbardcc3b652010-01-22 02:04:58 +0000105 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
106 /// invocation. For example, Darwin treats different ARM variations as
107 /// distinct architectures.
108 llvm::StringRef getDarwinArchName(const ArgList &Args) const;
109
Daniel Dunbar6d23b2f2010-01-27 00:57:03 +0000110 static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
Daniel Dunbard5bd81e2009-09-18 08:14:55 +0000111 for (unsigned i=0; i < 3; ++i) {
112 if (A[i] > B[i]) return false;
113 if (A[i] < B[i]) return true;
114 }
115 return false;
116 }
117
Daniel Dunbar83608032010-01-27 00:56:56 +0000118 bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
119 assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
120 unsigned B[3] = { V0, V1, V2 };
Daniel Dunbar6d23b2f2010-01-27 00:57:03 +0000121 return isVersionLT(TargetVersion, B);
122 }
123
124 bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
125 assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
126 unsigned B[3] = { V0, V1, V2 };
127 return isVersionLT(TargetVersion, B);
Daniel Dunbar83608032010-01-27 00:56:56 +0000128 }
129
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000130 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
131 ///
132 /// \param Args - The input argument list.
133 /// \param CmdArgs [out] - The command argument list to append the paths
134 /// (prefixed by -L) to.
Daniel Dunbar6276f992009-09-18 08:15:13 +0000135 virtual void AddLinkSearchPathArgs(const ArgList &Args,
136 ArgStringList &CmdArgs) const = 0;
Daniel Dunbarc1964212009-03-26 16:23:12 +0000137
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000138 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
139 /// runtime library.
Daniel Dunbar6276f992009-09-18 08:15:13 +0000140 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
141 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000142
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000143 /// }
144 /// @name ToolChain Implementation
145 /// {
146
Daniel Dunbar775d4062010-06-11 22:00:26 +0000147 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
Daniel Dunbare7af3412009-09-09 18:36:12 +0000148 const char *BoundArch) const;
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000149
150 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
151
Daniel Dunbar4930e332009-11-17 08:07:36 +0000152 virtual bool IsBlocksDefault() const {
Daniel Dunbarf48d51d2010-01-27 00:57:11 +0000153 // Blocks default to on for OS X 10.6 and iPhoneOS 3.0 and beyond.
154 if (isTargetIPhoneOS())
155 return !isIPhoneOSVersionLT(3);
156 else
157 return !isMacosxVersionLT(10, 6);
Daniel Dunbar4930e332009-11-17 08:07:36 +0000158 }
Daniel Dunbarf9ff3502010-05-14 02:03:00 +0000159 virtual bool IsIntegratedAssemblerDefault() const {
Daniel Dunbara99a3c12010-06-23 18:15:13 +0000160#ifdef DISABLE_DEFAULT_INTEGRATED_ASSEMBLER
161 return false;
162#else
Daniel Dunbarf9ff3502010-05-14 02:03:00 +0000163 // Default integrated assembler to on for x86.
164 return (getTriple().getArch() == llvm::Triple::x86 ||
165 getTriple().getArch() == llvm::Triple::x86_64);
Daniel Dunbara99a3c12010-06-23 18:15:13 +0000166#endif
Daniel Dunbarf9ff3502010-05-14 02:03:00 +0000167 }
Daniel Dunbar4930e332009-11-17 08:07:36 +0000168 virtual bool IsObjCNonFragileABIDefault() const {
Daniel Dunbardf3d1c22010-04-24 18:37:41 +0000169 // Non-fragile ABI is default for everything but i386.
170 return getTriple().getArch() != llvm::Triple::x86;
Daniel Dunbar4930e332009-11-17 08:07:36 +0000171 }
Daniel Dunbar98188412010-02-01 21:07:43 +0000172 virtual bool IsObjCLegacyDispatchDefault() const {
173 // This is only used with the non-fragile ABI.
Daniel Dunbardf3d1c22010-04-24 18:37:41 +0000174
175 // Legacy dispatch is used everywhere except on x86_64.
176 return getTriple().getArch() != llvm::Triple::x86_64;
Daniel Dunbar98188412010-02-01 21:07:43 +0000177 }
Daniel Dunbarfca18c1b42010-04-24 17:56:46 +0000178 virtual bool UseObjCMixedDispatch() const {
Daniel Dunbardf3d1c22010-04-24 18:37:41 +0000179 // This is only used with the non-fragile ABI and non-legacy dispatch.
180
181 // Mixed dispatch is used everywhere except OS X before 10.6.
182 return !(!isTargetIPhoneOS() && isMacosxVersionLT(10, 6));
Daniel Dunbarfca18c1b42010-04-24 17:56:46 +0000183 }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000184 virtual bool IsUnwindTablesDefault() const;
Daniel Dunbar4930e332009-11-17 08:07:36 +0000185 virtual unsigned GetDefaultStackProtectorLevel() const {
Daniel Dunbarf48d51d2010-01-27 00:57:11 +0000186 // Stack protectors default to on for 10.6 and beyond.
187 return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6);
Daniel Dunbar4930e332009-11-17 08:07:36 +0000188 }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000189 virtual const char *GetDefaultRelocationModel() const;
190 virtual const char *GetForcedPicModel() const;
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000191
Daniel Dunbar16334e12010-04-10 16:20:23 +0000192 virtual bool SupportsObjCGC() const;
193
Daniel Dunbar24c7f5e2009-12-18 02:43:17 +0000194 virtual bool UseDwarfDebugFlags() const;
195
Daniel Dunbar3241d402010-02-10 18:49:11 +0000196 virtual bool UseSjLjExceptions() const;
197
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000198 /// }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000199};
200
Daniel Dunbar6276f992009-09-18 08:15:13 +0000201/// DarwinClang - The Darwin toolchain used by Clang.
Duncan Sandsaf260b92010-05-11 20:16:05 +0000202class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000203public:
Daniel Dunbar6276f992009-09-18 08:15:13 +0000204 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbar7c8701752010-01-27 00:56:44 +0000205 const unsigned (&DarwinVersion)[3]);
Daniel Dunbar6276f992009-09-18 08:15:13 +0000206
207 /// @name Darwin ToolChain Implementation
208 /// {
209
210 virtual void AddLinkSearchPathArgs(const ArgList &Args,
211 ArgStringList &CmdArgs) const;
212
213 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
214 ArgStringList &CmdArgs) const;
215
216 /// }
217};
218
219/// DarwinGCC - The Darwin toolchain used by GCC.
Duncan Sandsaf260b92010-05-11 20:16:05 +0000220class LLVM_LIBRARY_VISIBILITY DarwinGCC : public Darwin {
Daniel Dunbar6276f992009-09-18 08:15:13 +0000221 /// GCC version to use.
Ted Kremenek7881ac92009-10-07 03:21:11 +0000222 unsigned GCCVersion[3];
Daniel Dunbar6276f992009-09-18 08:15:13 +0000223
224 /// The directory suffix for this tool chain.
225 std::string ToolChainDir;
226
227public:
228 DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbar7c8701752010-01-27 00:56:44 +0000229 const unsigned (&DarwinVersion)[3],
230 const unsigned (&GCCVersion)[3]);
Daniel Dunbar6276f992009-09-18 08:15:13 +0000231
232 /// @name Darwin ToolChain Implementation
233 /// {
234
235 virtual void AddLinkSearchPathArgs(const ArgList &Args,
236 ArgStringList &CmdArgs) const;
237
238 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
239 ArgStringList &CmdArgs) const;
240
241 /// }
242};
243
244/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
Duncan Sandsaf260b92010-05-11 20:16:05 +0000245class LLVM_LIBRARY_VISIBILITY Darwin_Generic_GCC : public Generic_GCC {
Daniel Dunbar6276f992009-09-18 08:15:13 +0000246public:
247 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000248 : Generic_GCC(Host, Triple) {}
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000249
250 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
251};
252
Duncan Sandsaf260b92010-05-11 20:16:05 +0000253class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC {
Edward O'Callaghan856e4ff2009-08-22 01:06:46 +0000254public:
255 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
256
257 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
258};
259
Duncan Sandsaf260b92010-05-11 20:16:05 +0000260class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_GCC {
Daniel Dunbar10de9e62009-06-29 20:52:51 +0000261public:
262 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
263
264 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
265};
266
Duncan Sandsaf260b92010-05-11 20:16:05 +0000267class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_GCC {
Daniel Dunbare24297c2009-03-30 21:06:03 +0000268public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000269 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
Daniel Dunbare24297c2009-03-30 21:06:03 +0000270
271 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
272};
273
Chris Lattner3e2ee142010-07-07 16:01:42 +0000274class LLVM_LIBRARY_VISIBILITY Minix : public Generic_GCC {
275public:
276 Minix(const HostInfo &Host, const llvm::Triple& Triple);
277
278 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
279};
280
Duncan Sandsaf260b92010-05-11 20:16:05 +0000281class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_GCC {
Daniel Dunbarcc912342009-05-02 18:28:39 +0000282public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000283 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbarcc912342009-05-02 18:28:39 +0000284
285 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
286};
287
Duncan Sandsaf260b92010-05-11 20:16:05 +0000288class LLVM_LIBRARY_VISIBILITY Linux : public Generic_GCC {
Eli Friedman5cd659f2009-05-26 07:52:18 +0000289public:
290 Linux(const HostInfo &Host, const llvm::Triple& Triple);
291};
292
293
Chris Lattner09797542010-03-04 21:07:38 +0000294/// TCEToolChain - A tool chain using the llvm bitcode tools to perform
295/// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
Duncan Sandsaf260b92010-05-11 20:16:05 +0000296class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
Chris Lattner09797542010-03-04 21:07:38 +0000297public:
298 TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple);
299 ~TCEToolChain();
300
Chris Lattner09797542010-03-04 21:07:38 +0000301 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
302 bool IsMathErrnoDefault() const;
303 bool IsUnwindTablesDefault() const;
304 const char* GetDefaultRelocationModel() const;
305 const char* GetForcedPicModel() const;
306
307private:
308 mutable llvm::DenseMap<unsigned, Tool*> Tools;
309
310};
311
Daniel Dunbar0a248bb2009-03-17 21:38:00 +0000312} // end namespace toolchains
313} // end namespace driver
314} // end namespace clang
315
316#endif