blob: fbb1136199db21c3b208da25069415a8e25626d8 [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.
Daniel Dunbar985b8252009-03-17 22:18:43 +000028class VISIBILITY_HIDDEN 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 Dunbar0dcb9a32009-09-09 18:36:12 +000036 virtual DerivedArgList *TranslateArgs(InputArgList &Args,
37 const char *BoundArch) const;
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000038
Daniel Dunbar39176082009-03-20 00:20:03 +000039 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
Daniel Dunbar670b7f42009-03-17 22:07:31 +000040
Daniel Dunbar39176082009-03-20 00:20:03 +000041 virtual bool IsUnwindTablesDefault() const;
42 virtual const char *GetDefaultRelocationModel() const;
43 virtual const char *GetForcedPicModel() const;
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000044};
45
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000046/// Darwin - The base Darwin tool chain.
Daniel Dunbarf3955282009-09-04 18:34:51 +000047class VISIBILITY_HIDDEN Darwin : public ToolChain {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000048 mutable llvm::DenseMap<unsigned, Tool*> Tools;
49
Daniel Dunbar26031372010-01-27 00:56:25 +000050 /// Whether the information on the target has been initialized.
51 //
52 // FIXME: This should be eliminated. What we want to do is make this part of
53 // the "default target for arguments" selection process, once we get out of
54 // the argument translation business.
55 mutable bool TargetInitialized;
56
57 /// Whether we are targetting iPhoneOS target.
58 mutable bool TargetIsIPhoneOS;
59
60 /// The OS version we are targetting.
61 mutable unsigned TargetVersion[3];
62
Daniel Dunbar02633b52009-03-26 16:23:12 +000063 /// The default macosx-version-min of this tool chain; empty until
64 /// initialized.
Daniel Dunbar816bc312010-01-26 01:45:19 +000065 std::string MacosxVersionMin;
Daniel Dunbar02633b52009-03-26 16:23:12 +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
99 void getTargetVersion(unsigned (&Res)[3]) const {
100 assert(TargetInitialized && "Target not initialized!");
101 Res[0] = TargetVersion[0];
102 Res[1] = TargetVersion[1];
103 Res[2] = TargetVersion[2];
104 }
105
Daniel Dunbareeff4062010-01-22 02:04:58 +0000106 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
107 /// invocation. For example, Darwin treats different ARM variations as
108 /// distinct architectures.
109 llvm::StringRef getDarwinArchName(const ArgList &Args) const;
110
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000111 static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
Daniel Dunbar608d04c2009-09-18 08:14:55 +0000112 for (unsigned i=0; i < 3; ++i) {
113 if (A[i] > B[i]) return false;
114 if (A[i] < B[i]) return true;
115 }
116 return false;
117 }
118
Daniel Dunbarcacb0f02010-01-27 00:56:56 +0000119 bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
120 assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
121 unsigned B[3] = { V0, V1, V2 };
Daniel Dunbarce3fdf22010-01-27 00:57:03 +0000122 return isVersionLT(TargetVersion, B);
123 }
124
125 bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
126 assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
127 unsigned B[3] = { V0, V1, V2 };
128 return isVersionLT(TargetVersion, B);
Daniel Dunbarcacb0f02010-01-27 00:56:56 +0000129 }
130
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000131 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
132 ///
133 /// \param Args - The input argument list.
134 /// \param CmdArgs [out] - The command argument list to append the paths
135 /// (prefixed by -L) to.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000136 virtual void AddLinkSearchPathArgs(const ArgList &Args,
137 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar02633b52009-03-26 16:23:12 +0000138
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000139 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
140 /// runtime library.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000141 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
142 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000143
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000144 /// }
145 /// @name ToolChain Implementation
146 /// {
147
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000148 virtual DerivedArgList *TranslateArgs(InputArgList &Args,
149 const char *BoundArch) const;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000150
151 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
152
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000153 virtual bool IsBlocksDefault() const {
Daniel Dunbar5435fc92010-01-27 00:57:11 +0000154 // Blocks default to on for OS X 10.6 and iPhoneOS 3.0 and beyond.
155 if (isTargetIPhoneOS())
156 return !isIPhoneOSVersionLT(3);
157 else
158 return !isMacosxVersionLT(10, 6);
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000159 }
160 virtual bool IsObjCNonFragileABIDefault() const {
Daniel Dunbar5435fc92010-01-27 00:57:11 +0000161 // Non-fragile ABI default to on for iPhoneOS and x86-64.
162 return isTargetIPhoneOS() || getTriple().getArch() == llvm::Triple::x86_64;
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000163 }
Daniel Dunbar609508c2010-02-01 21:07:43 +0000164 virtual bool IsObjCLegacyDispatchDefault() const {
165 // This is only used with the non-fragile ABI.
166 return (getTriple().getArch() == llvm::Triple::arm ||
167 getTriple().getArch() == llvm::Triple::thumb);
168 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000169 virtual bool IsUnwindTablesDefault() const;
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000170 virtual unsigned GetDefaultStackProtectorLevel() const {
Daniel Dunbar5435fc92010-01-27 00:57:11 +0000171 // Stack protectors default to on for 10.6 and beyond.
172 return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6);
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000173 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000174 virtual const char *GetDefaultRelocationModel() const;
175 virtual const char *GetForcedPicModel() const;
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000176
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000177 virtual bool UseDwarfDebugFlags() const;
178
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000179 /// }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000180};
181
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000182/// DarwinClang - The Darwin toolchain used by Clang.
183class VISIBILITY_HIDDEN DarwinClang : public Darwin {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000184public:
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000185 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000186 const unsigned (&DarwinVersion)[3]);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000187
188 /// @name Darwin ToolChain Implementation
189 /// {
190
191 virtual void AddLinkSearchPathArgs(const ArgList &Args,
192 ArgStringList &CmdArgs) const;
193
194 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
195 ArgStringList &CmdArgs) const;
196
197 /// }
198};
199
200/// DarwinGCC - The Darwin toolchain used by GCC.
201class VISIBILITY_HIDDEN DarwinGCC : public Darwin {
202 /// GCC version to use.
Ted Kremenek55bac532009-10-07 03:21:11 +0000203 unsigned GCCVersion[3];
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000204
205 /// The directory suffix for this tool chain.
206 std::string ToolChainDir;
207
208public:
209 DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000210 const unsigned (&DarwinVersion)[3],
211 const unsigned (&GCCVersion)[3]);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000212
213 /// @name Darwin ToolChain Implementation
214 /// {
215
216 virtual void AddLinkSearchPathArgs(const ArgList &Args,
217 ArgStringList &CmdArgs) const;
218
219 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
220 ArgStringList &CmdArgs) const;
221
222 /// }
223};
224
225/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
226class VISIBILITY_HIDDEN Darwin_Generic_GCC : public Generic_GCC {
227public:
228 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000229 : Generic_GCC(Host, Triple) {}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000230
231 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
232};
233
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000234class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC {
235public:
236 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
237
238 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
239};
240
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000241class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC {
242public:
243 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
244
245 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
246};
247
Daniel Dunbar75358d22009-03-30 21:06:03 +0000248class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC {
249public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000250 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
Daniel Dunbar75358d22009-03-30 21:06:03 +0000251
252 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
253};
254
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000255class VISIBILITY_HIDDEN DragonFly : public Generic_GCC {
256public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000257 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000258
259 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
260};
261
Eli Friedman6b3454a2009-05-26 07:52:18 +0000262class VISIBILITY_HIDDEN Linux : public Generic_GCC {
263public:
264 Linux(const HostInfo &Host, const llvm::Triple& Triple);
265};
266
267
Daniel Dunbar83b08eb2009-03-17 21:38:00 +0000268} // end namespace toolchains
269} // end namespace driver
270} // end namespace clang
271
272#endif