blob: 3ca6ad88972ceb6ec6f2cef5b52d5385a7c52e24 [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 Dunbardcc3b652010-01-22 02:04:58 +000088 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
89 /// invocation. For example, Darwin treats different ARM variations as
90 /// distinct architectures.
91 llvm::StringRef getDarwinArchName(const ArgList &Args) const;
92
Daniel Dunbar510d8a82009-09-18 08:14:46 +000093 /// getMacosxVersionMin - Get the effective -mmacosx-version-min, which is
94 /// either the -mmacosx-version-min, or the current version if unspecified.
95 void getMacosxVersionMin(const ArgList &Args, unsigned (&Res)[3]) const;
96
Daniel Dunbard5bd81e2009-09-18 08:14:55 +000097 static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
98 for (unsigned i=0; i < 3; ++i) {
99 if (A[i] > B[i]) return false;
100 if (A[i] < B[i]) return true;
101 }
102 return false;
103 }
104
105 static bool isMacosxVersionLT(unsigned (&A)[3],
106 unsigned V0, unsigned V1=0, unsigned V2=0) {
107 unsigned B[3] = { V0, V1, V2 };
108 return isMacosxVersionLT(A, B);
109 }
110
Daniel Dunbarc1964212009-03-26 16:23:12 +0000111 const char *getMacosxVersionStr() const {
112 return MacosxVersionMin.c_str();
113 }
114
Daniel Dunbar84e727f2009-09-04 18:35:21 +0000115 const char *getIPhoneOSVersionStr() const {
116 return IPhoneOSVersionMin.c_str();
117 }
118
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000119 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
120 ///
121 /// \param Args - The input argument list.
122 /// \param CmdArgs [out] - The command argument list to append the paths
123 /// (prefixed by -L) to.
Daniel Dunbar6276f992009-09-18 08:15:13 +0000124 virtual void AddLinkSearchPathArgs(const ArgList &Args,
125 ArgStringList &CmdArgs) const = 0;
Daniel Dunbarc1964212009-03-26 16:23:12 +0000126
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000127 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler
128 /// runtime library.
Daniel Dunbar6276f992009-09-18 08:15:13 +0000129 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
130 ArgStringList &CmdArgs) const = 0;
Daniel Dunbar26d482a2009-09-18 08:15:03 +0000131
Daniel Dunbar6276f992009-09-18 08:15:13 +0000132 bool isIPhoneOS() const { return IsIPhoneOS; }
Daniel Dunbar84e727f2009-09-04 18:35:21 +0000133
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000134 /// }
135 /// @name ToolChain Implementation
136 /// {
137
Daniel Dunbare7af3412009-09-09 18:36:12 +0000138 virtual DerivedArgList *TranslateArgs(InputArgList &Args,
139 const char *BoundArch) const;
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000140
141 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
142
Daniel Dunbar4930e332009-11-17 08:07:36 +0000143 virtual bool IsBlocksDefault() const {
144 // Blocks default to on for 10.6 (darwin10) and beyond.
145 return (DarwinVersion[0] > 9);
146 }
147 virtual bool IsObjCNonFragileABIDefault() const {
148 // Non-fragile ABI default to on for 10.5 (darwin9) and beyond on x86-64.
149 return (DarwinVersion[0] >= 9 &&
150 getTriple().getArch() == llvm::Triple::x86_64);
151 }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000152 virtual bool IsUnwindTablesDefault() const;
Daniel Dunbar4930e332009-11-17 08:07:36 +0000153 virtual unsigned GetDefaultStackProtectorLevel() const {
154 // Stack protectors default to on for 10.6 (darwin10) and beyond.
155 return (DarwinVersion[0] > 9) ? 1 : 0;
156 }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000157 virtual const char *GetDefaultRelocationModel() const;
158 virtual const char *GetForcedPicModel() const;
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000159
Daniel Dunbar24c7f5e2009-12-18 02:43:17 +0000160 virtual bool UseDwarfDebugFlags() const;
161
Daniel Dunbar4c30b892009-09-18 08:14:36 +0000162 /// }
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000163};
164
Daniel Dunbar6276f992009-09-18 08:15:13 +0000165/// DarwinClang - The Darwin toolchain used by Clang.
166class VISIBILITY_HIDDEN DarwinClang : public Darwin {
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000167public:
Daniel Dunbar6276f992009-09-18 08:15:13 +0000168 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
169 const unsigned (&DarwinVersion)[3], bool IsIPhoneOS);
170
171 /// @name Darwin ToolChain Implementation
172 /// {
173
174 virtual void AddLinkSearchPathArgs(const ArgList &Args,
175 ArgStringList &CmdArgs) const;
176
177 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
178 ArgStringList &CmdArgs) const;
179
180 /// }
181};
182
183/// DarwinGCC - The Darwin toolchain used by GCC.
184class VISIBILITY_HIDDEN DarwinGCC : public Darwin {
185 /// GCC version to use.
Ted Kremenek7881ac92009-10-07 03:21:11 +0000186 unsigned GCCVersion[3];
Daniel Dunbar6276f992009-09-18 08:15:13 +0000187
188 /// The directory suffix for this tool chain.
189 std::string ToolChainDir;
190
191public:
192 DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
Ted Kremenek7881ac92009-10-07 03:21:11 +0000193 const unsigned (&DarwinVersion)[3], const unsigned (&GCCVersion)[3],
Daniel Dunbar6276f992009-09-18 08:15:13 +0000194 bool IsIPhoneOS);
195
196 /// @name Darwin ToolChain Implementation
197 /// {
198
199 virtual void AddLinkSearchPathArgs(const ArgList &Args,
200 ArgStringList &CmdArgs) const;
201
202 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
203 ArgStringList &CmdArgs) const;
204
205 /// }
206};
207
208/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
209class VISIBILITY_HIDDEN Darwin_Generic_GCC : public Generic_GCC {
210public:
211 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000212 : Generic_GCC(Host, Triple) {}
Daniel Dunbar03e0a4f2009-03-20 00:57:52 +0000213
214 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
215};
216
Edward O'Callaghan856e4ff2009-08-22 01:06:46 +0000217class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC {
218public:
219 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
220
221 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
222};
223
Daniel Dunbar10de9e62009-06-29 20:52:51 +0000224class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC {
225public:
226 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
227
228 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
229};
230
Daniel Dunbare24297c2009-03-30 21:06:03 +0000231class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC {
232public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000233 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
Daniel Dunbare24297c2009-03-30 21:06:03 +0000234
235 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
236};
237
Daniel Dunbarcc912342009-05-02 18:28:39 +0000238class VISIBILITY_HIDDEN DragonFly : public Generic_GCC {
239public:
Daniel Dunbar51c7f972009-05-22 02:53:45 +0000240 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbarcc912342009-05-02 18:28:39 +0000241
242 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
243};
244
Eli Friedman5cd659f2009-05-26 07:52:18 +0000245class VISIBILITY_HIDDEN Linux : public Generic_GCC {
246public:
247 Linux(const HostInfo &Host, const llvm::Triple& Triple);
248};
249
250
Daniel Dunbar0a248bb2009-03-17 21:38:00 +0000251} // end namespace toolchains
252} // end namespace driver
253} // end namespace clang
254
255#endif