blob: 6088d9617cf0453fb89fa08a4383e7f2527f4a7b [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;
140 virtual bool IsUnwindTablesDefault() const;
141 virtual const char *GetDefaultRelocationModel() const;
142 virtual const char *GetForcedPicModel() const;
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000143
144 /// }
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000145};
146
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000147/// DarwinClang - The Darwin toolchain used by Clang.
148class VISIBILITY_HIDDEN DarwinClang : public Darwin {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000149public:
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000150 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
151 const unsigned (&DarwinVersion)[3], bool IsIPhoneOS);
152
153 /// @name Darwin ToolChain Implementation
154 /// {
155
156 virtual void AddLinkSearchPathArgs(const ArgList &Args,
157 ArgStringList &CmdArgs) const;
158
159 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
160 ArgStringList &CmdArgs) const;
161
162 /// }
163};
164
165/// DarwinGCC - The Darwin toolchain used by GCC.
166class VISIBILITY_HIDDEN DarwinGCC : public Darwin {
167 /// GCC version to use.
Ted Kremenek55bac532009-10-07 03:21:11 +0000168 unsigned GCCVersion[3];
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000169
170 /// The directory suffix for this tool chain.
171 std::string ToolChainDir;
172
173public:
174 DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
Ted Kremenek55bac532009-10-07 03:21:11 +0000175 const unsigned (&DarwinVersion)[3], const unsigned (&GCCVersion)[3],
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000176 bool IsIPhoneOS);
177
178 /// @name Darwin ToolChain Implementation
179 /// {
180
181 virtual void AddLinkSearchPathArgs(const ArgList &Args,
182 ArgStringList &CmdArgs) const;
183
184 virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
185 ArgStringList &CmdArgs) const;
186
187 /// }
188};
189
190/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc.
191class VISIBILITY_HIDDEN Darwin_Generic_GCC : public Generic_GCC {
192public:
193 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000194 : Generic_GCC(Host, Triple) {}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000195
196 virtual const char *GetDefaultRelocationModel() const { return "pic"; }
197};
198
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000199class VISIBILITY_HIDDEN AuroraUX : public Generic_GCC {
200public:
201 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple);
202
203 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
204};
205
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000206class VISIBILITY_HIDDEN OpenBSD : public Generic_GCC {
207public:
208 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple);
209
210 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
211};
212
Daniel Dunbar75358d22009-03-30 21:06:03 +0000213class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC {
214public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000215 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32);
Daniel Dunbar75358d22009-03-30 21:06:03 +0000216
217 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
218};
219
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000220class VISIBILITY_HIDDEN DragonFly : public Generic_GCC {
221public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000222 DragonFly(const HostInfo &Host, const llvm::Triple& Triple);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000223
224 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
225};
226
Eli Friedman6b3454a2009-05-26 07:52:18 +0000227class VISIBILITY_HIDDEN Linux : public Generic_GCC {
228public:
229 Linux(const HostInfo &Host, const llvm::Triple& Triple);
230};
231
232
Daniel Dunbar83b08eb2009-03-17 21:38:00 +0000233} // end namespace toolchains
234} // end namespace driver
235} // end namespace clang
236
237#endif