blob: fcd96f1e5c8c1ed84f2adaca875d5d9ee2fe16e3 [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 IsMathErrnoDefault() const;
42 virtual bool IsUnwindTablesDefault() const;
43 virtual const char *GetDefaultRelocationModel() const;
44 virtual const char *GetForcedPicModel() const;
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000045};
46
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000047/// Darwin - The base Darwin tool chain.
Daniel Dunbarf3955282009-09-04 18:34:51 +000048class VISIBILITY_HIDDEN Darwin : public ToolChain {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000049 mutable llvm::DenseMap<unsigned, Tool*> Tools;
50
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000051 /// Darwin version of tool chain.
52 unsigned DarwinVersion[3];
53
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000054 /// Whether this is this an iPhoneOS toolchain.
55 //
56 // FIXME: This should go away, such differences should be completely
57 // determined by the target triple.
58 bool IsIPhoneOS;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000059
Daniel Dunbar02633b52009-03-26 16:23:12 +000060 /// The default macosx-version-min of this tool chain; empty until
61 /// initialized.
62 mutable std::string MacosxVersionMin;
63
Daniel Dunbar30392de2009-09-04 18:35:21 +000064 /// The default iphoneos-version-min of this tool chain.
65 std::string IPhoneOSVersionMin;
66
Daniel Dunbar02633b52009-03-26 16:23:12 +000067 const char *getMacosxVersionMin() const;
Daniel Dunbarec069ed2009-03-25 06:58:31 +000068
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000069public:
Mike Stump1eb44332009-09-09 15:08:12 +000070 Darwin(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000071 const unsigned (&DarwinVersion)[3], bool IsIPhoneOS);
Daniel Dunbarf3955282009-09-04 18:34:51 +000072 ~Darwin();
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000073
Daniel Dunbar6b200b22009-09-18 08:14:36 +000074 /// @name Darwin Specific Toolchain API
75 /// {
76
Daniel Dunbar02633b52009-03-26 16:23:12 +000077 void getDarwinVersion(unsigned (&Res)[3]) const {
78 Res[0] = DarwinVersion[0];
79 Res[1] = DarwinVersion[1];
80 Res[2] = DarwinVersion[2];
81 }
82
83 void getMacosxVersion(unsigned (&Res)[3]) const {
84 Res[0] = 10;
85 Res[1] = DarwinVersion[0] - 4;
86 Res[2] = DarwinVersion[1];
87 }
88
Daniel Dunbar48d5aae2009-09-18 08:14:46 +000089 /// getMacosxVersionMin - Get the effective -mmacosx-version-min, which is
90 /// either the -mmacosx-version-min, or the current version if unspecified.
91 void getMacosxVersionMin(const ArgList &Args, unsigned (&Res)[3]) const;
92
Daniel Dunbar608d04c2009-09-18 08:14:55 +000093 static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
94 for (unsigned i=0; i < 3; ++i) {
95 if (A[i] > B[i]) return false;
96 if (A[i] < B[i]) return true;
97 }
98 return false;
99 }
100
101 static bool isMacosxVersionLT(unsigned (&A)[3],
102 unsigned V0, unsigned V1=0, unsigned V2=0) {
103 unsigned B[3] = { V0, V1, V2 };
104 return isMacosxVersionLT(A, B);
105 }
106
Daniel Dunbar02633b52009-03-26 16:23:12 +0000107 const char *getMacosxVersionStr() const {
108 return MacosxVersionMin.c_str();
109 }
110
Daniel Dunbar30392de2009-09-04 18:35:21 +0000111 const char *getIPhoneOSVersionStr() const {
112 return IPhoneOSVersionMin.c_str();
113 }
114
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000115 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
116 ///
117 /// \param Args - The input argument list.
118 /// \param CmdArgs [out] - The command argument list to append the paths
119 /// (prefixed by -L) to.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000120 virtual void AddLinkSearchPathArgs(const ArgList &Args,
121 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar02633b52009-03-26 16:23:12 +0000122
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000123 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
124 /// runtime library.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000125 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
126 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000127
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000128 bool isIPhoneOS() const { return IsIPhoneOS; }
Daniel Dunbar30392de2009-09-04 18:35:21 +0000129
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000130 /// }
131 /// @name ToolChain Implementation
132 /// {
133
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000134 virtual DerivedArgList *TranslateArgs(InputArgList &Args,
135 const char *BoundArch) const;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000136
137 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
138
139 virtual bool IsMathErrnoDefault() const;
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000140 virtual bool IsBlocksDefault() const {
141 // Blocks default to on for 10.6 (darwin10) and beyond.
142 return (DarwinVersion[0] > 9);
143 }
144 virtual bool IsObjCNonFragileABIDefault() const {
145 // Non-fragile ABI default to on for 10.5 (darwin9) and beyond on x86-64.
146 return (DarwinVersion[0] >= 9 &&
147 getTriple().getArch() == llvm::Triple::x86_64);
148 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000149 virtual bool IsUnwindTablesDefault() const;
Daniel Dunbar9e5cc6b2009-11-17 08:07:36 +0000150 virtual unsigned GetDefaultStackProtectorLevel() const {
151 // Stack protectors default to on for 10.6 (darwin10) and beyond.
152 return (DarwinVersion[0] > 9) ? 1 : 0;
153 }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000154 virtual const char *GetDefaultRelocationModel() const;
155 virtual const char *GetForcedPicModel() const;
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000156
157 /// }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000158};
159
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000160/// DarwinClang - The Darwin toolchain used by Clang.
161class VISIBILITY_HIDDEN DarwinClang : public Darwin {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000162public:
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000163 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
164 const unsigned (&DarwinVersion)[3], bool IsIPhoneOS);
165
166 /// @name Darwin ToolChain Implementation
167 /// {
168
169 virtual void AddLinkSearchPathArgs(const ArgList &Args,
170 ArgStringList &CmdArgs) const;
171
172 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
173 ArgStringList &CmdArgs) const;
174
175 /// }
176};
177
178/// DarwinGCC - The Darwin toolchain used by GCC.
179class VISIBILITY_HIDDEN DarwinGCC : public Darwin {
180 /// GCC version to use.
Ted Kremenek55bac532009-10-07 03:21:11 +0000181 unsigned GCCVersion[3];
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000182
183 /// The directory suffix for this tool chain.
184 std::string ToolChainDir;
185
186public:
187 DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
Ted Kremenek55bac532009-10-07 03:21:11 +0000188 const unsigned (&DarwinVersion)[3], const unsigned (&GCCVersion)[3],
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000189 bool IsIPhoneOS);
190
191 /// @name Darwin ToolChain Implementation
192 /// {
193
194 virtual void AddLinkSearchPathArgs(const ArgList &Args,
195 ArgStringList &CmdArgs) const;
196
197 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
198 ArgStringList &CmdArgs) const;
199
200 /// }
201};
202
203/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
204class VISIBILITY_HIDDEN Darwin_Generic_GCC : public Generic_GCC {
205public:
206 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000207 : Generic_GCC(Host, Triple) {}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000208
209 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
210};
211
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000212class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC {
213public:
214 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
215
216 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
217};
218
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000219class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC {
220public:
221 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
222
223 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
224};
225
Daniel Dunbar75358d22009-03-30 21:06:03 +0000226class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC {
227public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000228 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
Daniel Dunbar75358d22009-03-30 21:06:03 +0000229
230 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
231};
232
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000233class VISIBILITY_HIDDEN DragonFly : public Generic_GCC {
234public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000235 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000236
237 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
238};
239
Eli Friedman6b3454a2009-05-26 07:52:18 +0000240class VISIBILITY_HIDDEN Linux : public Generic_GCC {
241public:
242 Linux(const HostInfo &Host, const llvm::Triple& Triple);
243};
244
245
Daniel Dunbar83b08eb2009-03-17 21:38:00 +0000246} // end namespace toolchains
247} // end namespace driver
248} // end namespace clang
249
250#endif