blob: b6cdacac300b4d3f69e4e44b8f32f8aebd295d00 [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.
Daniel Dunbar15abb2e2009-03-17 22:18:43 +000028class VISIBILITY_HIDDEN 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 Dunbare7af3412009-09-09 18:36:12 +000036 virtual DerivedArgList *TranslateArgs(InputArgList &Args,
37 const char *BoundArch) const;
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000038
Daniel Dunbar59e5e882009-03-20 00:20:03 +000039 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
Daniel Dunbar04cb0292009-03-17 22:07:31 +000040
Daniel Dunbar59e5e882009-03-20 00:20:03 +000041 virtual bool IsUnwindTablesDefault() const;
42 virtual const char *GetDefaultRelocationModel() const;
43 virtual const char *GetForcedPicModel() const;
Daniel Dunbar0a248bb2009-03-17 21:38:00 +000044};
45
Daniel Dunbar6276f992009-09-18 08:15:13 +000046/// Darwin - The base Darwin tool chain.
Daniel Dunbarf0a5b9b2009-09-04 18:34:51 +000047class VISIBILITY_HIDDEN Darwin : public ToolChain {
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000048 mutable llvm::DenseMap<unsigned, Tool*> Tools;
49
Daniel Dunbar76ce7412009-03-23 16:15:50 +000050 /// Darwin version of tool chain.
51 unsigned DarwinVersion[3];
52
Daniel Dunbar3b8e50d2010-01-27 00:56:25 +000053 /// Whether the information on the target has been initialized.
54 //
55 // FIXME: This should be eliminated. What we want to do is make this part of
56 // the "default target for arguments" selection process, once we get out of
57 // the argument translation business.
58 mutable bool TargetInitialized;
59
60 /// Whether we are targetting iPhoneOS target.
61 mutable bool TargetIsIPhoneOS;
62
63 /// The OS version we are targetting.
64 mutable unsigned TargetVersion[3];
65
Daniel Dunbar6276f992009-09-18 08:15:13 +000066 /// Whether this is this an iPhoneOS toolchain.
67 //
68 // FIXME: This should go away, such differences should be completely
69 // determined by the target triple.
Daniel Dunbard54669d2010-01-26 01:45:19 +000070 //
71 // FIXME: It is also broken, we need to distinguish the "default target" from
72 // the actual target. The -m...-version-min strings and deployment targets can
73 // change this.
Daniel Dunbar6276f992009-09-18 08:15:13 +000074 bool IsIPhoneOS;
Daniel Dunbar76ce7412009-03-23 16:15:50 +000075
Daniel Dunbarc1964212009-03-26 16:23:12 +000076 /// The default macosx-version-min of this tool chain; empty until
77 /// initialized.
Daniel Dunbard54669d2010-01-26 01:45:19 +000078 std::string MacosxVersionMin;
Daniel Dunbarc1964212009-03-26 16:23:12 +000079
Daniel Dunbar84e727f2009-09-04 18:35:21 +000080 /// The default iphoneos-version-min of this tool chain.
81 std::string IPhoneOSVersionMin;
82
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000083public:
Mike Stump11289f42009-09-09 15:08:12 +000084 Darwin(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbar6276f992009-09-18 08:15:13 +000085 const unsigned (&DarwinVersion)[3], bool IsIPhoneOS);
Daniel Dunbarf0a5b9b2009-09-04 18:34:51 +000086 ~Darwin();
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000087
Daniel Dunbar4c30b892009-09-18 08:14:36 +000088 /// @name Darwin Specific Toolchain API
89 /// {
90
Daniel Dunbar3b8e50d2010-01-27 00:56:25 +000091 // FIXME: Eliminate these ...Target functions and derive separate tool chains
92 // for these targets and put version in constructor.
93 void setTarget(bool isIPhoneOS, unsigned Major, unsigned Minor,
94 unsigned Micro) const {
95 // FIXME: For now, allow reinitialization as long as values don't
96 // change. This will go away when we move away from argument translation.
97 if (TargetInitialized && TargetIsIPhoneOS == isIPhoneOS &&
98 TargetVersion[0] == Major && TargetVersion[1] == Minor &&
99 TargetVersion[2] == Micro)
100 return;
101
102 assert(!TargetInitialized && "Target already initialized!");
103 TargetInitialized = true;
104 TargetIsIPhoneOS = isIPhoneOS;
105 TargetVersion[0] = Major;
106 TargetVersion[1] = Minor;
107 TargetVersion[2] = Micro;
108 }
109
110 bool isTargetIPhoneOS() const {
111 assert(TargetInitialized && "Target not initialized!");
112 return TargetIsIPhoneOS;
113 }
114
115 void getTargetVersion(unsigned (&Res)[3]) const {
116 assert(TargetInitialized && "Target not initialized!");
117 Res[0] = TargetVersion[0];
118 Res[1] = TargetVersion[1];
119 Res[2] = TargetVersion[2];
120 }
121
Daniel Dunbarc1964212009-03-26 16:23:12 +0000122 void getDarwinVersion(unsigned (&Res)[3]) const {
123 Res[0] = DarwinVersion[0];
124 Res[1] = DarwinVersion[1];
125 Res[2] = DarwinVersion[2];
126 }
127
128 void getMacosxVersion(unsigned (&Res)[3]) const {
129 Res[0] = 10;
130 Res[1] = DarwinVersion[0] - 4;
131 Res[2] = DarwinVersion[1];
132 }
133
Daniel Dunbardcc3b652010-01-22 02:04:58 +0000134 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
135 /// invocation. For example, Darwin treats different ARM variations as
136 /// distinct architectures.
137 llvm::StringRef getDarwinArchName(const ArgList &Args) const;
138
Daniel Dunbar510d8a82009-09-18 08:14:46 +0000139 /// getMacosxVersionMin - Get the effective -mmacosx-version-min, which is
140 /// either the -mmacosx-version-min, or the current version if unspecified.
141 void getMacosxVersionMin(const ArgList &Args, unsigned (&Res)[3]) const;
142
Daniel Dunbard5bd81e2009-09-18 08:14:55 +0000143 static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
144 for (unsigned i=0; i < 3; ++i) {
145 if (A[i] > B[i]) return false;
146 if (A[i] < B[i]) return true;
147 }
148 return false;
149 }
150
151 static bool isMacosxVersionLT(unsigned (&A)[3],
152 unsigned V0, unsigned V1=0, unsigned V2=0) {
153 unsigned B[3] = { V0, V1, V2 };
154 return isMacosxVersionLT(A, B);
155 }
156
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000157 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
158 ///
159 /// \param Args - The input argument list.
160 /// \param CmdArgs [out] - The command argument list to append the paths
161 /// (prefixed by -L) to.
Daniel Dunbar6276f992009-09-18 08:15:13 +0000162 virtual void AddLinkSearchPathArgs(const ArgList &Args,
163 ArgStringList &CmdArgs) const = 0;
Daniel Dunbarc1964212009-03-26 16:23:12 +0000164
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000165 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
166 /// runtime library.
Daniel Dunbar6276f992009-09-18 08:15:13 +0000167 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
168 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000169
Daniel Dunbar6276f992009-09-18 08:15:13 +0000170 bool isIPhoneOS() const { return IsIPhoneOS; }
Daniel Dunbar84e727f2009-09-04 18:35:21 +0000171
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000172 /// }
173 /// @name ToolChain Implementation
174 /// {
175
Daniel Dunbare7af3412009-09-09 18:36:12 +0000176 virtual DerivedArgList *TranslateArgs(InputArgList &Args,
177 const char *BoundArch) const;
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000178
179 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
180
Daniel Dunbar4930e332009-11-17 08:07:36 +0000181 virtual bool IsBlocksDefault() const {
182 // Blocks default to on for 10.6 (darwin10) and beyond.
183 return (DarwinVersion[0] > 9);
184 }
185 virtual bool IsObjCNonFragileABIDefault() const {
186 // Non-fragile ABI default to on for 10.5 (darwin9) and beyond on x86-64.
187 return (DarwinVersion[0] >= 9 &&
188 getTriple().getArch() == llvm::Triple::x86_64);
189 }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000190 virtual bool IsUnwindTablesDefault() const;
Daniel Dunbar4930e332009-11-17 08:07:36 +0000191 virtual unsigned GetDefaultStackProtectorLevel() const {
192 // Stack protectors default to on for 10.6 (darwin10) and beyond.
193 return (DarwinVersion[0] > 9) ? 1 : 0;
194 }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000195 virtual const char *GetDefaultRelocationModel() const;
196 virtual const char *GetForcedPicModel() const;
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000197
Daniel Dunbar24c7f5e2009-12-18 02:43:17 +0000198 virtual bool UseDwarfDebugFlags() const;
199
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000200 /// }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000201};
202
Daniel Dunbar6276f992009-09-18 08:15:13 +0000203/// DarwinClang - The Darwin toolchain used by Clang.
204class VISIBILITY_HIDDEN DarwinClang : public Darwin {
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000205public:
Daniel Dunbar6276f992009-09-18 08:15:13 +0000206 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
207 const unsigned (&DarwinVersion)[3], bool IsIPhoneOS);
208
209 /// @name Darwin ToolChain Implementation
210 /// {
211
212 virtual void AddLinkSearchPathArgs(const ArgList &Args,
213 ArgStringList &CmdArgs) const;
214
215 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
216 ArgStringList &CmdArgs) const;
217
218 /// }
219};
220
221/// DarwinGCC - The Darwin toolchain used by GCC.
222class VISIBILITY_HIDDEN DarwinGCC : public Darwin {
223 /// GCC version to use.
Ted Kremenek7881ac92009-10-07 03:21:11 +0000224 unsigned GCCVersion[3];
Daniel Dunbar6276f992009-09-18 08:15:13 +0000225
226 /// The directory suffix for this tool chain.
227 std::string ToolChainDir;
228
229public:
230 DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
Ted Kremenek7881ac92009-10-07 03:21:11 +0000231 const unsigned (&DarwinVersion)[3], const unsigned (&GCCVersion)[3],
Daniel Dunbar6276f992009-09-18 08:15:13 +0000232 bool IsIPhoneOS);
233
234 /// @name Darwin ToolChain Implementation
235 /// {
236
237 virtual void AddLinkSearchPathArgs(const ArgList &Args,
238 ArgStringList &CmdArgs) const;
239
240 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
241 ArgStringList &CmdArgs) const;
242
243 /// }
244};
245
246/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
247class VISIBILITY_HIDDEN Darwin_Generic_GCC : public Generic_GCC {
248public:
249 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000250 : Generic_GCC(Host, Triple) {}
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000251
252 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
253};
254
Edward O'Callaghan856e4ff2009-08-22 01:06:46 +0000255class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC {
256public:
257 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
258
259 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
260};
261
Daniel Dunbar10de9e62009-06-29 20:52:51 +0000262class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC {
263public:
264 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
265
266 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
267};
268
Daniel Dunbare24297c2009-03-30 21:06:03 +0000269class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC {
270public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000271 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
Daniel Dunbare24297c2009-03-30 21:06:03 +0000272
273 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
274};
275
Daniel Dunbarcc912342009-05-02 18:28:39 +0000276class VISIBILITY_HIDDEN DragonFly : public Generic_GCC {
277public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000278 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbarcc912342009-05-02 18:28:39 +0000279
280 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
281};
282
Eli Friedman5cd659f2009-05-26 07:52:18 +0000283class VISIBILITY_HIDDEN Linux : public Generic_GCC {
284public:
285 Linux(const HostInfo &Host, const llvm::Triple& Triple);
286};
287
288
Daniel Dunbar0a248bb2009-03-17 21:38:00 +0000289} // end namespace toolchains
290} // end namespace driver
291} // end namespace clang
292
293#endif