blob: 374ad8c6bb8188eb629650e410df99461f60f9ed [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.
57 bool IsIPhoneOS;
Daniel Dunbar76ce7412009-03-23 16:15:50 +000058
Daniel Dunbarc1964212009-03-26 16:23:12 +000059 /// The default macosx-version-min of this tool chain; empty until
60 /// initialized.
61 mutable std::string MacosxVersionMin;
62
Daniel Dunbar84e727f2009-09-04 18:35:21 +000063 /// The default iphoneos-version-min of this tool chain.
64 std::string IPhoneOSVersionMin;
65
Daniel Dunbarc1964212009-03-26 16:23:12 +000066 const char *getMacosxVersionMin() const;
Daniel Dunbar0af75a12009-03-25 06:58:31 +000067
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000068public:
Mike Stump11289f42009-09-09 15:08:12 +000069 Darwin(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbar6276f992009-09-18 08:15:13 +000070 const unsigned (&DarwinVersion)[3], bool IsIPhoneOS);
Daniel Dunbarf0a5b9b2009-09-04 18:34:51 +000071 ~Darwin();
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +000072
Daniel Dunbar4c30b892009-09-18 08:14:36 +000073 /// @name Darwin Specific Toolchain API
74 /// {
75
Daniel Dunbarc1964212009-03-26 16:23:12 +000076 void getDarwinVersion(unsigned (&Res)[3]) const {
77 Res[0] = DarwinVersion[0];
78 Res[1] = DarwinVersion[1];
79 Res[2] = DarwinVersion[2];
80 }
81
82 void getMacosxVersion(unsigned (&Res)[3]) const {
83 Res[0] = 10;
84 Res[1] = DarwinVersion[0] - 4;
85 Res[2] = DarwinVersion[1];
86 }
87
Daniel Dunbar510d8a82009-09-18 08:14:46 +000088 /// getMacosxVersionMin - Get the effective -mmacosx-version-min, which is
89 /// either the -mmacosx-version-min, or the current version if unspecified.
90 void getMacosxVersionMin(const ArgList &Args, unsigned (&Res)[3]) const;
91
Daniel Dunbard5bd81e2009-09-18 08:14:55 +000092 static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
93 for (unsigned i=0; i < 3; ++i) {
94 if (A[i] > B[i]) return false;
95 if (A[i] < B[i]) return true;
96 }
97 return false;
98 }
99
100 static bool isMacosxVersionLT(unsigned (&A)[3],
101 unsigned V0, unsigned V1=0, unsigned V2=0) {
102 unsigned B[3] = { V0, V1, V2 };
103 return isMacosxVersionLT(A, B);
104 }
105
Daniel Dunbarc1964212009-03-26 16:23:12 +0000106 const char *getMacosxVersionStr() const {
107 return MacosxVersionMin.c_str();
108 }
109
Daniel Dunbar84e727f2009-09-04 18:35:21 +0000110 const char *getIPhoneOSVersionStr() const {
111 return IPhoneOSVersionMin.c_str();
112 }
113
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000114 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
115 ///
116 /// \param Args - The input argument list.
117 /// \param CmdArgs [out] - The command argument list to append the paths
118 /// (prefixed by -L) to.
Daniel Dunbar6276f992009-09-18 08:15:13 +0000119 virtual void AddLinkSearchPathArgs(const ArgList &Args,
120 ArgStringList &CmdArgs) const = 0;
Daniel Dunbarc1964212009-03-26 16:23:12 +0000121
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000122 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
123 /// runtime library.
Daniel Dunbar6276f992009-09-18 08:15:13 +0000124 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
125 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000126
Daniel Dunbar6276f992009-09-18 08:15:13 +0000127 bool isIPhoneOS() const { return IsIPhoneOS; }
Daniel Dunbar84e727f2009-09-04 18:35:21 +0000128
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000129 /// }
130 /// @name ToolChain Implementation
131 /// {
132
Daniel Dunbare7af3412009-09-09 18:36:12 +0000133 virtual DerivedArgList *TranslateArgs(InputArgList &Args,
134 const char *BoundArch) const;
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000135
136 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
137
Daniel Dunbar4930e332009-11-17 08:07:36 +0000138 virtual bool IsBlocksDefault() const {
139 // Blocks default to on for 10.6 (darwin10) and beyond.
140 return (DarwinVersion[0] > 9);
141 }
142 virtual bool IsObjCNonFragileABIDefault() const {
143 // Non-fragile ABI default to on for 10.5 (darwin9) and beyond on x86-64.
144 return (DarwinVersion[0] >= 9 &&
145 getTriple().getArch() == llvm::Triple::x86_64);
146 }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000147 virtual bool IsUnwindTablesDefault() const;
Daniel Dunbar4930e332009-11-17 08:07:36 +0000148 virtual unsigned GetDefaultStackProtectorLevel() const {
149 // Stack protectors default to on for 10.6 (darwin10) and beyond.
150 return (DarwinVersion[0] > 9) ? 1 : 0;
151 }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000152 virtual const char *GetDefaultRelocationModel() const;
153 virtual const char *GetForcedPicModel() const;
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000154
Daniel Dunbar24c7f5e2009-12-18 02:43:17 +0000155 virtual bool UseDwarfDebugFlags() const;
156
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000157 /// }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000158};
159
Daniel Dunbar6276f992009-09-18 08:15:13 +0000160/// DarwinClang - The Darwin toolchain used by Clang.
161class VISIBILITY_HIDDEN DarwinClang : public Darwin {
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000162public:
Daniel Dunbar6276f992009-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 Kremenek7881ac92009-10-07 03:21:11 +0000181 unsigned GCCVersion[3];
Daniel Dunbar6276f992009-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 Kremenek7881ac92009-10-07 03:21:11 +0000188 const unsigned (&DarwinVersion)[3], const unsigned (&GCCVersion)[3],
Daniel Dunbar6276f992009-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 Dunbar51c7f972009-05-22 02:53:45 +0000207 : Generic_GCC(Host, Triple) {}
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000208
209 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
210};
211
Edward O'Callaghan856e4ff2009-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 Dunbar10de9e62009-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 Dunbare24297c2009-03-30 21:06:03 +0000226class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC {
227public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000228 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
Daniel Dunbare24297c2009-03-30 21:06:03 +0000229
230 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
231};
232
Daniel Dunbarcc912342009-05-02 18:28:39 +0000233class VISIBILITY_HIDDEN DragonFly : public Generic_GCC {
234public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000235 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbarcc912342009-05-02 18:28:39 +0000236
237 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
238};
239
Eli Friedman5cd659f2009-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 Dunbar0a248bb2009-03-17 21:38:00 +0000246} // end namespace toolchains
247} // end namespace driver
248} // end namespace clang
249
250#endif