blob: 82fdf825d07dca0f394213da7c38e41583f3e834 [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 Dunbar6276f992009-09-18 08:15:13 +000053 /// 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.
Daniel Dunbard54669d2010-01-26 01:45:19 +000057 //
58 // FIXME: It is also broken, we need to distinguish the "default target" from
59 // the actual target. The -m...-version-min strings and deployment targets can
60 // change this.
Daniel Dunbar6276f992009-09-18 08:15:13 +000061 bool IsIPhoneOS;
Daniel Dunbar76ce7412009-03-23 16:15:50 +000062
Daniel Dunbarc1964212009-03-26 16:23:12 +000063 /// The default macosx-version-min of this tool chain; empty until
64 /// initialized.
Daniel Dunbard54669d2010-01-26 01:45:19 +000065 std::string MacosxVersionMin;
Daniel Dunbarc1964212009-03-26 16:23:12 +000066
Daniel Dunbar84e727f2009-09-04 18:35:21 +000067 /// The default iphoneos-version-min of this tool chain.
68 std::string IPhoneOSVersionMin;
69
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000070public:
Mike Stump11289f42009-09-09 15:08:12 +000071 Darwin(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbar6276f992009-09-18 08:15:13 +000072 const unsigned (&DarwinVersion)[3], bool IsIPhoneOS);
Daniel Dunbarf0a5b9b2009-09-04 18:34:51 +000073 ~Darwin();
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000074
Daniel Dunbar4c30b892009-09-18 08:14:36 +000075 /// @name Darwin Specific Toolchain API
76 /// {
77
Daniel Dunbarc1964212009-03-26 16:23:12 +000078 void getDarwinVersion(unsigned (&Res)[3]) const {
79 Res[0] = DarwinVersion[0];
80 Res[1] = DarwinVersion[1];
81 Res[2] = DarwinVersion[2];
82 }
83
84 void getMacosxVersion(unsigned (&Res)[3]) const {
85 Res[0] = 10;
86 Res[1] = DarwinVersion[0] - 4;
87 Res[2] = DarwinVersion[1];
88 }
89
Daniel Dunbardcc3b652010-01-22 02:04:58 +000090 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
91 /// invocation. For example, Darwin treats different ARM variations as
92 /// distinct architectures.
93 llvm::StringRef getDarwinArchName(const ArgList &Args) const;
94
Daniel Dunbar510d8a82009-09-18 08:14:46 +000095 /// getMacosxVersionMin - Get the effective -mmacosx-version-min, which is
96 /// either the -mmacosx-version-min, or the current version if unspecified.
97 void getMacosxVersionMin(const ArgList &Args, unsigned (&Res)[3]) const;
98
Daniel Dunbard5bd81e2009-09-18 08:14:55 +000099 static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
100 for (unsigned i=0; i < 3; ++i) {
101 if (A[i] > B[i]) return false;
102 if (A[i] < B[i]) return true;
103 }
104 return false;
105 }
106
107 static bool isMacosxVersionLT(unsigned (&A)[3],
108 unsigned V0, unsigned V1=0, unsigned V2=0) {
109 unsigned B[3] = { V0, V1, V2 };
110 return isMacosxVersionLT(A, B);
111 }
112
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000113 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
114 ///
115 /// \param Args - The input argument list.
116 /// \param CmdArgs [out] - The command argument list to append the paths
117 /// (prefixed by -L) to.
Daniel Dunbar6276f992009-09-18 08:15:13 +0000118 virtual void AddLinkSearchPathArgs(const ArgList &Args,
119 ArgStringList &CmdArgs) const = 0;
Daniel Dunbarc1964212009-03-26 16:23:12 +0000120
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000121 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
122 /// runtime library.
Daniel Dunbar6276f992009-09-18 08:15:13 +0000123 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
124 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000125
Daniel Dunbar6276f992009-09-18 08:15:13 +0000126 bool isIPhoneOS() const { return IsIPhoneOS; }
Daniel Dunbar84e727f2009-09-04 18:35:21 +0000127
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000128 /// }
129 /// @name ToolChain Implementation
130 /// {
131
Daniel Dunbare7af3412009-09-09 18:36:12 +0000132 virtual DerivedArgList *TranslateArgs(InputArgList &Args,
133 const char *BoundArch) const;
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000134
135 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
136
Daniel Dunbar4930e332009-11-17 08:07:36 +0000137 virtual bool IsBlocksDefault() const {
138 // Blocks default to on for 10.6 (darwin10) and beyond.
139 return (DarwinVersion[0] > 9);
140 }
141 virtual bool IsObjCNonFragileABIDefault() const {
142 // Non-fragile ABI default to on for 10.5 (darwin9) and beyond on x86-64.
143 return (DarwinVersion[0] >= 9 &&
144 getTriple().getArch() == llvm::Triple::x86_64);
145 }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000146 virtual bool IsUnwindTablesDefault() const;
Daniel Dunbar4930e332009-11-17 08:07:36 +0000147 virtual unsigned GetDefaultStackProtectorLevel() const {
148 // Stack protectors default to on for 10.6 (darwin10) and beyond.
149 return (DarwinVersion[0] > 9) ? 1 : 0;
150 }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000151 virtual const char *GetDefaultRelocationModel() const;
152 virtual const char *GetForcedPicModel() const;
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000153
Daniel Dunbar24c7f5e2009-12-18 02:43:17 +0000154 virtual bool UseDwarfDebugFlags() const;
155
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000156 /// }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000157};
158
Daniel Dunbar6276f992009-09-18 08:15:13 +0000159/// DarwinClang - The Darwin toolchain used by Clang.
160class VISIBILITY_HIDDEN DarwinClang : public Darwin {
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000161public:
Daniel Dunbar6276f992009-09-18 08:15:13 +0000162 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
163 const unsigned (&DarwinVersion)[3], bool IsIPhoneOS);
164
165 /// @name Darwin ToolChain Implementation
166 /// {
167
168 virtual void AddLinkSearchPathArgs(const ArgList &Args,
169 ArgStringList &CmdArgs) const;
170
171 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
172 ArgStringList &CmdArgs) const;
173
174 /// }
175};
176
177/// DarwinGCC - The Darwin toolchain used by GCC.
178class VISIBILITY_HIDDEN DarwinGCC : public Darwin {
179 /// GCC version to use.
Ted Kremenek7881ac92009-10-07 03:21:11 +0000180 unsigned GCCVersion[3];
Daniel Dunbar6276f992009-09-18 08:15:13 +0000181
182 /// The directory suffix for this tool chain.
183 std::string ToolChainDir;
184
185public:
186 DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
Ted Kremenek7881ac92009-10-07 03:21:11 +0000187 const unsigned (&DarwinVersion)[3], const unsigned (&GCCVersion)[3],
Daniel Dunbar6276f992009-09-18 08:15:13 +0000188 bool IsIPhoneOS);
189
190 /// @name Darwin ToolChain Implementation
191 /// {
192
193 virtual void AddLinkSearchPathArgs(const ArgList &Args,
194 ArgStringList &CmdArgs) const;
195
196 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
197 ArgStringList &CmdArgs) const;
198
199 /// }
200};
201
202/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
203class VISIBILITY_HIDDEN Darwin_Generic_GCC : public Generic_GCC {
204public:
205 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000206 : Generic_GCC(Host, Triple) {}
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000207
208 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
209};
210
Edward O'Callaghan856e4ff2009-08-22 01:06:46 +0000211class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC {
212public:
213 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
214
215 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
216};
217
Daniel Dunbar10de9e62009-06-29 20:52:51 +0000218class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC {
219public:
220 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
221
222 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
223};
224
Daniel Dunbare24297c2009-03-30 21:06:03 +0000225class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC {
226public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000227 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
Daniel Dunbare24297c2009-03-30 21:06:03 +0000228
229 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
230};
231
Daniel Dunbarcc912342009-05-02 18:28:39 +0000232class VISIBILITY_HIDDEN DragonFly : public Generic_GCC {
233public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000234 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbarcc912342009-05-02 18:28:39 +0000235
236 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
237};
238
Eli Friedman5cd659f2009-05-26 07:52:18 +0000239class VISIBILITY_HIDDEN Linux : public Generic_GCC {
240public:
241 Linux(const HostInfo &Host, const llvm::Triple& Triple);
242};
243
244
Daniel Dunbar0a248bb2009-03-17 21:38:00 +0000245} // end namespace toolchains
246} // end namespace driver
247} // end namespace clang
248
249#endif