blob: 90aede7c613fe3d8ab214bf1d812552945cce4a1 [file] [log] [blame]
Daniel Dunbar39176082009-03-20 00:20:03 +00001//===--- ToolChains.cpp - ToolChain Implementations ---------------------*-===//
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#include "ToolChains.h"
11
Daniel Dunbarf3cad362009-03-25 04:13:45 +000012#include "clang/Driver/Arg.h"
13#include "clang/Driver/ArgList.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000014#include "clang/Driver/Driver.h"
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +000015#include "clang/Driver/DriverDiagnostic.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000016#include "clang/Driver/HostInfo.h"
Daniel Dunbar27e738d2009-11-19 00:15:11 +000017#include "clang/Driver/OptTable.h"
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +000018#include "clang/Driver/Option.h"
Daniel Dunbar265e9ef2009-11-19 04:25:22 +000019#include "clang/Driver/Options.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000020
21#include "llvm/ADT/StringExtras.h"
Daniel Dunbar84ec96c2009-09-09 22:33:15 +000022#include "llvm/Support/ErrorHandling.h"
Daniel Dunbarec069ed2009-03-25 06:58:31 +000023#include "llvm/Support/raw_ostream.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000024#include "llvm/System/Path.h"
25
Daniel Dunbarf36a06a2009-04-10 21:00:07 +000026#include <cstdlib> // ::getenv
27
Daniel Dunbar39176082009-03-20 00:20:03 +000028using namespace clang::driver;
29using namespace clang::driver::toolchains;
30
Daniel Dunbarf3955282009-09-04 18:34:51 +000031/// Darwin - Darwin tool chain for i386 and x86_64.
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000032
Daniel Dunbarf3955282009-09-04 18:34:51 +000033Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000034 const unsigned (&_DarwinVersion)[3], bool _IsIPhoneOS)
35 : ToolChain(Host, Triple),
36 IsIPhoneOS(_IsIPhoneOS)
37{
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000038 DarwinVersion[0] = _DarwinVersion[0];
39 DarwinVersion[1] = _DarwinVersion[1];
40 DarwinVersion[2] = _DarwinVersion[2];
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000041
Daniel Dunbar02633b52009-03-26 16:23:12 +000042 llvm::raw_string_ostream(MacosxVersionMin)
Benjamin Kramer87f9fd92009-10-21 21:05:07 +000043 << "10." << std::max(0, (int)DarwinVersion[0] - 4) << '.'
44 << DarwinVersion[1];
Daniel Dunbar02633b52009-03-26 16:23:12 +000045
Daniel Dunbar30392de2009-09-04 18:35:21 +000046 // FIXME: Lift default up.
47 IPhoneOSVersionMin = "3.0";
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000048}
49
Daniel Dunbareeff4062010-01-22 02:04:58 +000050// FIXME: Can we tablegen this?
51static const char *GetArmArchForMArch(llvm::StringRef Value) {
52 if (Value == "armv6k")
53 return "armv6";
54
55 if (Value == "armv5tej")
56 return "armv5";
57
58 if (Value == "xscale")
59 return "xscale";
60
61 if (Value == "armv4t")
62 return "armv4t";
63
64 if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" ||
65 Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" ||
66 Value == "armv7m")
67 return "armv7";
68
69 return 0;
70}
71
72// FIXME: Can we tablegen this?
73static const char *GetArmArchForMCpu(llvm::StringRef Value) {
74 if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" ||
75 Value == "arm946e-s" || Value == "arm966e-s" ||
76 Value == "arm968e-s" || Value == "arm10e" ||
77 Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" ||
78 Value == "arm1026ej-s")
79 return "armv5";
80
81 if (Value == "xscale")
82 return "xscale";
83
84 if (Value == "arm1136j-s" || Value == "arm1136jf-s" ||
85 Value == "arm1176jz-s" || Value == "arm1176jzf-s")
86 return "armv6";
87
88 if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3")
89 return "armv7";
90
91 return 0;
92}
93
94llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const {
95 switch (getTriple().getArch()) {
96 default:
97 return getArchName();
98
99 case llvm::Triple::arm: {
100 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
101 if (const char *Arch = GetArmArchForMArch(A->getValue(Args)))
102 return Arch;
103
104 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
105 if (const char *Arch = GetArmArchForMCpu(A->getValue(Args)))
106 return Arch;
107
108 return "arm";
109 }
110 }
111}
112
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000113DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
114 const unsigned (&DarwinVersion)[3],
Ted Kremenek55bac532009-10-07 03:21:11 +0000115 const unsigned (&_GCCVersion)[3], bool IsIPhoneOS)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000116 : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS)
117{
118 GCCVersion[0] = _GCCVersion[0];
119 GCCVersion[1] = _GCCVersion[1];
120 GCCVersion[2] = _GCCVersion[2];
121
122 // Set up the tool chain paths to match gcc.
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000123 ToolChainDir = "i686-apple-darwin";
Ted Kremenek55bac532009-10-07 03:21:11 +0000124 ToolChainDir += llvm::utostr(DarwinVersion[0]);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000125 ToolChainDir += "/";
126 ToolChainDir += llvm::utostr(GCCVersion[0]);
127 ToolChainDir += '.';
128 ToolChainDir += llvm::utostr(GCCVersion[1]);
129 ToolChainDir += '.';
130 ToolChainDir += llvm::utostr(GCCVersion[2]);
131
Daniel Dunbar74782b02009-10-20 19:25:43 +0000132 // Try the next major version if that tool chain dir is invalid.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000133 std::string Tmp = "/usr/lib/gcc/" + ToolChainDir;
134 if (!llvm::sys::Path(Tmp).exists()) {
Daniel Dunbar74782b02009-10-20 19:25:43 +0000135 std::string Next = "i686-apple-darwin";
136 Next += llvm::utostr(DarwinVersion[0] + 1);
137 Next += "/";
138 Next += llvm::utostr(GCCVersion[0]);
139 Next += '.';
140 Next += llvm::utostr(GCCVersion[1]);
141 Next += '.';
142 Next += llvm::utostr(GCCVersion[2]);
143
144 // Use that if it exists, otherwise hope the user isn't linking.
145 //
146 // FIXME: Drop dependency on gcc's tool chain.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000147 Tmp = "/usr/lib/gcc/" + Next;
148 if (llvm::sys::Path(Tmp).exists())
Daniel Dunbar74782b02009-10-20 19:25:43 +0000149 ToolChainDir = Next;
150 }
151
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000152 std::string Path;
153 if (getArchName() == "x86_64") {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000154 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000155 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000156 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000157 Path += "/x86_64";
158 getFilePaths().push_back(Path);
159
160 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000161 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000162 Path += "/x86_64";
163 getFilePaths().push_back(Path);
164 }
Mike Stump1eb44332009-09-09 15:08:12 +0000165
Daniel Dunbaree788e72009-12-21 18:54:17 +0000166 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000167 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000168 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000169 getFilePaths().push_back(Path);
170
171 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000172 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000173 getFilePaths().push_back(Path);
174
Daniel Dunbaree788e72009-12-21 18:54:17 +0000175 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000176 Path += "/../libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000177 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000178 getProgramPaths().push_back(Path);
179
180 Path = "/usr/libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000181 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000182 getProgramPaths().push_back(Path);
183
Daniel Dunbaree788e72009-12-21 18:54:17 +0000184 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000185}
186
Daniel Dunbarf3955282009-09-04 18:34:51 +0000187Darwin::~Darwin() {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000188 // Free tool implementations.
189 for (llvm::DenseMap<unsigned, Tool*>::iterator
190 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
191 delete it->second;
192}
193
Daniel Dunbarf3955282009-09-04 18:34:51 +0000194Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000195 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000196 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000197 Key = Action::AnalyzeJobClass;
198 else
199 Key = JA.getKind();
200
201 Tool *&T = Tools[Key];
202 if (!T) {
203 switch (Key) {
204 case Action::InputClass:
205 case Action::BindArchClass:
206 assert(0 && "Invalid tool kind.");
207 case Action::PreprocessJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000208 T = new tools::darwin::Preprocess(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000209 case Action::AnalyzeJobClass:
210 T = new tools::Clang(*this); break;
Daniel Dunbar9120f172009-03-29 22:27:40 +0000211 case Action::PrecompileJobClass:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000212 case Action::CompileJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000213 T = new tools::darwin::Compile(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000214 case Action::AssembleJobClass:
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000215 T = new tools::darwin::Assemble(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000216 case Action::LinkJobClass:
Daniel Dunbar8f289622009-09-04 17:39:02 +0000217 T = new tools::darwin::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000218 case Action::LipoJobClass:
219 T = new tools::darwin::Lipo(*this); break;
220 }
221 }
222
223 return *T;
224}
225
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000226void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args,
227 ArgStringList &CmdArgs) const {
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000228 // FIXME: Derive these correctly.
229 if (getArchName() == "x86_64") {
230 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
231 "/x86_64"));
232 // Intentionally duplicated for (temporary) gcc bug compatibility.
233 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
234 "/x86_64"));
235 }
236 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir));
237 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
238 // Intentionally duplicated for (temporary) gcc bug compatibility.
239 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
240 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
241 "/../../../" + ToolChainDir));
242 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
243 "/../../.."));
244}
245
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000246void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args,
247 ArgStringList &CmdArgs) const {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000248 unsigned MacosxVersionMin[3];
249 getMacosxVersionMin(Args, MacosxVersionMin);
250
251 // Derived from libgcc and lib specs but refactored.
252 if (Args.hasArg(options::OPT_static)) {
253 CmdArgs.push_back("-lgcc_static");
254 } else {
255 if (Args.hasArg(options::OPT_static_libgcc)) {
256 CmdArgs.push_back("-lgcc_eh");
257 } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) {
258 // Derived from darwin_iphoneos_libgcc spec.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000259 if (isIPhoneOS()) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000260 CmdArgs.push_back("-lgcc_s.1");
261 } else {
262 CmdArgs.push_back("-lgcc_s.10.5");
263 }
264 } else if (Args.hasArg(options::OPT_shared_libgcc) ||
Daniel Dunbar8a0d94d2010-01-10 00:46:10 +0000265 Args.hasFlag(options::OPT_fexceptions,
266 options::OPT_fno_exceptions) ||
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000267 Args.hasArg(options::OPT_fgnu_runtime)) {
268 // FIXME: This is probably broken on 10.3?
269 if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
270 CmdArgs.push_back("-lgcc_s.10.4");
271 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
272 CmdArgs.push_back("-lgcc_s.10.5");
273 } else {
274 if (isMacosxVersionLT(MacosxVersionMin, 10, 3, 9))
275 ; // Do nothing.
276 else if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
277 CmdArgs.push_back("-lgcc_s.10.4");
278 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
279 CmdArgs.push_back("-lgcc_s.10.5");
280 }
281
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000282 if (isIPhoneOS() || isMacosxVersionLT(MacosxVersionMin, 10, 6)) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000283 CmdArgs.push_back("-lgcc");
284 CmdArgs.push_back("-lSystem");
285 } else {
286 CmdArgs.push_back("-lSystem");
287 CmdArgs.push_back("-lgcc");
288 }
289 }
290}
291
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000292DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
293 const unsigned (&DarwinVersion)[3],
294 bool IsIPhoneOS)
295 : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS)
296{
297 // We expect 'as', 'ld', etc. to be adjacent to our install dir.
Daniel Dunbaree788e72009-12-21 18:54:17 +0000298 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000299}
300
301void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
302 ArgStringList &CmdArgs) const {
303 // The Clang toolchain uses explicit paths for internal libraries.
304}
305
306void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
307 ArgStringList &CmdArgs) const {
308 // Check for static linking.
309 if (Args.hasArg(options::OPT_static)) {
310 // FIXME: We need to have compiler-rt available (perhaps as
311 // libclang_static.a) to link against.
312 return;
313 }
314
315 // Reject -static-libgcc for now, we can deal with this when and if someone
316 // cares. This is useful in situations where someone wants to statically link
317 // something like libstdc++, and needs its runtime support routines.
318 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000319 getDriver().Diag(clang::diag::err_drv_unsupported_opt)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000320 << A->getAsString(Args);
321 return;
322 }
323
324 // Otherwise link libSystem, which should have the support routines.
325 //
326 // FIXME: This is only true for 10.6 and beyond. Legacy support isn't
327 // critical, but it should work... we should just link in the static
328 // compiler-rt library.
329 CmdArgs.push_back("-lSystem");
330}
331
Daniel Dunbar48d5aae2009-09-18 08:14:46 +0000332void Darwin::getMacosxVersionMin(const ArgList &Args,
333 unsigned (&Res)[3]) const {
334 if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) {
335 bool HadExtra;
336 if (!Driver::GetReleaseVersion(A->getValue(Args), Res[0], Res[1], Res[2],
337 HadExtra) ||
338 HadExtra) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000339 const Driver &D = getDriver();
Daniel Dunbar48d5aae2009-09-18 08:14:46 +0000340 D.Diag(clang::diag::err_drv_invalid_version_number)
341 << A->getAsString(Args);
342 }
343 } else
344 return getMacosxVersion(Res);
345}
346
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000347DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
348 const char *BoundArch) const {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000349 DerivedArgList *DAL = new DerivedArgList(Args, false);
Daniel Dunbaree788e72009-12-21 18:54:17 +0000350 const OptTable &Opts = getDriver().getOpts();
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000351
352 // FIXME: We really want to get out of the tool chain level argument
353 // translation business, as it makes the driver functionality much
354 // more opaque. For now, we follow gcc closely solely for the
355 // purpose of easily achieving feature parity & testability. Once we
356 // have something that works, we should reevaluate each translation
Mike Stump1eb44332009-09-09 15:08:12 +0000357 // and try to push it down into tool specific logic.
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000358
Mike Stump1eb44332009-09-09 15:08:12 +0000359 Arg *OSXVersion =
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000360 Args.getLastArgNoClaim(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000361 Arg *iPhoneVersion =
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000362 Args.getLastArgNoClaim(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000363 if (OSXVersion && iPhoneVersion) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000364 getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000365 << OSXVersion->getAsString(Args)
Mike Stump1eb44332009-09-09 15:08:12 +0000366 << iPhoneVersion->getAsString(Args);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000367 } else if (!OSXVersion && !iPhoneVersion) {
368 // Chose the default version based on the arch.
369 //
Daniel Dunbar30392de2009-09-04 18:35:21 +0000370 // FIXME: Are there iPhone overrides for this?
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000371
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000372 if (!isIPhoneOS()) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000373 // Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version
374 // from the host.
375 const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET");
376 if (!Version)
377 Version = MacosxVersionMin.c_str();
378 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
379 DAL->append(DAL->MakeJoinedArg(0, O, Version));
380 } else {
381 const char *Version = IPhoneOSVersionMin.c_str();
382 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
383 DAL->append(DAL->MakeJoinedArg(0, O, Version));
384 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000385 }
Mike Stump1eb44332009-09-09 15:08:12 +0000386
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000387 for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
388 Arg *A = *it;
389
390 if (A->getOption().matches(options::OPT_Xarch__)) {
391 // FIXME: Canonicalize name.
392 if (getArchName() != A->getValue(Args, 0))
393 continue;
394
395 // FIXME: The arg is leaked here, and we should have a nicer
396 // interface for this.
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000397 unsigned Prev, Index = Prev = A->getIndex() + 1;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000398 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000399
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000400 // If the argument parsing failed or more than one argument was
401 // consumed, the -Xarch_ argument's parameter tried to consume
402 // extra arguments. Emit an error and ignore.
403 //
404 // We also want to disallow any options which would alter the
405 // driver behavior; that isn't going to work in our model. We
406 // use isDriverOption() as an approximation, although things
407 // like -O4 are going to slip through.
Mike Stump1eb44332009-09-09 15:08:12 +0000408 if (!XarchArg || Index > Prev + 1 ||
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000409 XarchArg->getOption().isDriverOption()) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000410 getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000411 << A->getAsString(Args);
412 continue;
413 }
414
Daniel Dunbar478edc22009-03-29 22:29:05 +0000415 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000416 A = XarchArg;
Mike Stump1eb44332009-09-09 15:08:12 +0000417 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000418
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000419 // Sob. These is strictly gcc compatible for the time being. Apple
420 // gcc translates options twice, which means that self-expanding
421 // options add duplicates.
Daniel Dunbar9e1f9822009-11-19 04:14:53 +0000422 switch ((options::ID) A->getOption().getID()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000423 default:
424 DAL->append(A);
425 break;
426
427 case options::OPT_mkernel:
428 case options::OPT_fapple_kext:
429 DAL->append(A);
Daniel Dunbar478edc22009-03-29 22:29:05 +0000430 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
431 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000432 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000433
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000434 case options::OPT_dependency_file:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000435 DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF),
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000436 A->getValue(Args)));
437 break;
438
439 case options::OPT_gfull:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000440 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
441 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000442 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)));
443 break;
444
445 case options::OPT_gused:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000446 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
447 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000448 Opts.getOption(options::OPT_feliminate_unused_debug_symbols)));
449 break;
450
451 case options::OPT_fterminated_vtables:
452 case options::OPT_findirect_virtual_calls:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000453 DAL->append(DAL->MakeFlagArg(A,
454 Opts.getOption(options::OPT_fapple_kext)));
455 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000456 break;
457
458 case options::OPT_shared:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000459 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000460 break;
461
462 case options::OPT_fconstant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000463 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000464 Opts.getOption(options::OPT_mconstant_cfstrings)));
465 break;
466
467 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000468 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000469 Opts.getOption(options::OPT_mno_constant_cfstrings)));
470 break;
471
472 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000473 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000474 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)));
475 break;
476
477 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000478 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000479 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)));
480 break;
481
482 case options::OPT_fpascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000483 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000484 Opts.getOption(options::OPT_mpascal_strings)));
485 break;
486
487 case options::OPT_fno_pascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000488 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000489 Opts.getOption(options::OPT_mno_pascal_strings)));
490 break;
491 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000492 }
493
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000494 if (getTriple().getArch() == llvm::Triple::x86 ||
495 getTriple().getArch() == llvm::Triple::x86_64)
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000496 if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000497 DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
498 "core2"));
499
500 // Add the arch options based on the particular spelling of -arch, to match
501 // how the driver driver works.
502 if (BoundArch) {
503 llvm::StringRef Name = BoundArch;
504 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
505 const Option *MArch = Opts.getOption(options::OPT_march_EQ);
506
507 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
508 // which defines the list of which architectures we accept.
509 if (Name == "ppc")
510 ;
511 else if (Name == "ppc601")
512 DAL->append(DAL->MakeJoinedArg(0, MCpu, "601"));
513 else if (Name == "ppc603")
514 DAL->append(DAL->MakeJoinedArg(0, MCpu, "603"));
515 else if (Name == "ppc604")
516 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604"));
517 else if (Name == "ppc604e")
518 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604e"));
519 else if (Name == "ppc750")
520 DAL->append(DAL->MakeJoinedArg(0, MCpu, "750"));
521 else if (Name == "ppc7400")
522 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7400"));
523 else if (Name == "ppc7450")
524 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7450"));
525 else if (Name == "ppc970")
526 DAL->append(DAL->MakeJoinedArg(0, MCpu, "970"));
527
528 else if (Name == "ppc64")
Daniel Dunbar478edc22009-03-29 22:29:05 +0000529 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000530
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000531 else if (Name == "i386")
532 ;
533 else if (Name == "i486")
534 DAL->append(DAL->MakeJoinedArg(0, MArch, "i486"));
535 else if (Name == "i586")
536 DAL->append(DAL->MakeJoinedArg(0, MArch, "i586"));
537 else if (Name == "i686")
538 DAL->append(DAL->MakeJoinedArg(0, MArch, "i686"));
539 else if (Name == "pentium")
540 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium"));
541 else if (Name == "pentium2")
542 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
543 else if (Name == "pentpro")
544 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentiumpro"));
545 else if (Name == "pentIIm3")
546 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
547
548 else if (Name == "x86_64")
549 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
550
551 else if (Name == "arm")
552 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
553 else if (Name == "armv4t")
554 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
555 else if (Name == "armv5")
556 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv5tej"));
557 else if (Name == "xscale")
558 DAL->append(DAL->MakeJoinedArg(0, MArch, "xscale"));
559 else if (Name == "armv6")
560 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv6k"));
561 else if (Name == "armv7")
562 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv7a"));
563
564 else
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000565 llvm_unreachable("invalid Darwin arch");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000566 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000567
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000568 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000569}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000570
Daniel Dunbarf3955282009-09-04 18:34:51 +0000571bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000572 // FIXME: Gross; we should probably have some separate target
573 // definition, possibly even reusing the one in clang.
574 return getArchName() == "x86_64";
575}
576
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000577bool Darwin::UseDwarfDebugFlags() const {
578 if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
579 return S[0] != '\0';
580 return false;
581}
582
Daniel Dunbarf3955282009-09-04 18:34:51 +0000583const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000584 return "pic";
585}
586
Daniel Dunbarf3955282009-09-04 18:34:51 +0000587const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000588 if (getArchName() == "x86_64")
589 return "pic";
590 return 0;
591}
592
Daniel Dunbar39176082009-03-20 00:20:03 +0000593/// Generic_GCC - A tool chain using the 'gcc' command to perform
594/// all subcommands; this relies on gcc translating the majority of
595/// command line options.
596
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000597Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000598 : ToolChain(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000599 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000600}
601
Daniel Dunbar39176082009-03-20 00:20:03 +0000602Generic_GCC::~Generic_GCC() {
603 // Free tool implementations.
604 for (llvm::DenseMap<unsigned, Tool*>::iterator
605 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
606 delete it->second;
607}
608
Mike Stump1eb44332009-09-09 15:08:12 +0000609Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbar39176082009-03-20 00:20:03 +0000610 const JobAction &JA) const {
611 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000612 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000613 Key = Action::AnalyzeJobClass;
614 else
615 Key = JA.getKind();
616
617 Tool *&T = Tools[Key];
618 if (!T) {
619 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000620 case Action::InputClass:
621 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000622 assert(0 && "Invalid tool kind.");
623 case Action::PreprocessJobClass:
624 T = new tools::gcc::Preprocess(*this); break;
625 case Action::PrecompileJobClass:
626 T = new tools::gcc::Precompile(*this); break;
627 case Action::AnalyzeJobClass:
628 T = new tools::Clang(*this); break;
629 case Action::CompileJobClass:
630 T = new tools::gcc::Compile(*this); break;
631 case Action::AssembleJobClass:
632 T = new tools::gcc::Assemble(*this); break;
633 case Action::LinkJobClass:
634 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000635
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000636 // This is a bit ungeneric, but the only platform using a driver
637 // driver is Darwin.
638 case Action::LipoJobClass:
639 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000640 }
641 }
642
643 return *T;
644}
645
Daniel Dunbar39176082009-03-20 00:20:03 +0000646bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000647 // FIXME: Gross; we should probably have some separate target
648 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000649 return getArchName() == "x86_64";
650}
651
652const char *Generic_GCC::GetDefaultRelocationModel() const {
653 return "static";
654}
655
656const char *Generic_GCC::GetForcedPicModel() const {
657 return 0;
658}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000659
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000660DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args,
661 const char *BoundArch) const {
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000662 return new DerivedArgList(Args, true);
663}
Daniel Dunbar75358d22009-03-30 21:06:03 +0000664
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000665/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
666
667OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
668 : Generic_GCC(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000669 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000670 getFilePaths().push_back("/usr/lib");
671}
672
673Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
674 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000675 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000676 Key = Action::AnalyzeJobClass;
677 else
678 Key = JA.getKind();
679
680 Tool *&T = Tools[Key];
681 if (!T) {
682 switch (Key) {
683 case Action::AssembleJobClass:
684 T = new tools::openbsd::Assemble(*this); break;
685 case Action::LinkJobClass:
686 T = new tools::openbsd::Link(*this); break;
687 default:
688 T = &Generic_GCC::SelectTool(C, JA);
689 }
690 }
691
692 return *T;
693}
694
Daniel Dunbar75358d22009-03-30 21:06:03 +0000695/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
696
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000697FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
698 : Generic_GCC(Host, Triple) {
Daniel Dunbarbc534662009-04-02 18:30:04 +0000699 if (Lib32) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000700 getFilePaths().push_back(getDriver().Dir + "/../lib32");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000701 getFilePaths().push_back("/usr/lib32");
702 } else {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000703 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000704 getFilePaths().push_back("/usr/lib");
705 }
Daniel Dunbar75358d22009-03-30 21:06:03 +0000706}
707
708Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
709 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000710 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +0000711 Key = Action::AnalyzeJobClass;
712 else
713 Key = JA.getKind();
714
715 Tool *&T = Tools[Key];
716 if (!T) {
717 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +0000718 case Action::AssembleJobClass:
719 T = new tools::freebsd::Assemble(*this); break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +0000720 case Action::LinkJobClass:
721 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000722 default:
723 T = &Generic_GCC::SelectTool(C, JA);
724 }
725 }
726
727 return *T;
728}
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000729
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000730/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
731
732AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
733 : Generic_GCC(Host, Triple) {
734
Daniel Dunbaree788e72009-12-21 18:54:17 +0000735 getProgramPaths().push_back(getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000736
Daniel Dunbaree788e72009-12-21 18:54:17 +0000737 getFilePaths().push_back(getDriver().Dir + "/../lib");
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000738 getFilePaths().push_back("/usr/lib");
739 getFilePaths().push_back("/usr/sfw/lib");
740 getFilePaths().push_back("/opt/gcc4/lib");
Edward O'Callaghan7adf9492009-10-15 07:44:07 +0000741 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4");
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000742
743}
744
745Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
746 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000747 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000748 Key = Action::AnalyzeJobClass;
749 else
750 Key = JA.getKind();
751
752 Tool *&T = Tools[Key];
753 if (!T) {
754 switch (Key) {
755 case Action::AssembleJobClass:
756 T = new tools::auroraux::Assemble(*this); break;
757 case Action::LinkJobClass:
758 T = new tools::auroraux::Link(*this); break;
759 default:
760 T = &Generic_GCC::SelectTool(C, JA);
761 }
762 }
763
764 return *T;
765}
766
767
Eli Friedman6b3454a2009-05-26 07:52:18 +0000768/// Linux toolchain (very bare-bones at the moment).
769
770Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
771 : Generic_GCC(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000772 getFilePaths().push_back(getDriver().Dir + "/../lib/clang/1.0/");
Eli Friedman6b3454a2009-05-26 07:52:18 +0000773 getFilePaths().push_back("/lib/");
774 getFilePaths().push_back("/usr/lib/");
Daniel Dunbara9822de2009-08-06 01:47:11 +0000775
776 // Depending on the Linux distribution, any combination of lib{,32,64} is
777 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
778 // openSUSE uses lib and lib64 for the same purpose.
779 getFilePaths().push_back("/lib32/");
780 getFilePaths().push_back("/usr/lib32/");
781 getFilePaths().push_back("/lib64/");
782 getFilePaths().push_back("/usr/lib64/");
783
Eli Friedman6b3454a2009-05-26 07:52:18 +0000784 // FIXME: Figure out some way to get gcc's libdir
785 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
786 // crtbegin.o/crtend.o/etc., and want static versions of various
787 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
788 // get away with using shared versions in /usr/lib, though.
789 // We could fall back to the approach we used for includes (a massive
790 // list), but that's messy at best.
791}
792
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000793/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
794
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000795DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
796 : Generic_GCC(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000797
798 // Path mangling to find libexec
Daniel Dunbaree788e72009-12-21 18:54:17 +0000799 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000800
Daniel Dunbaree788e72009-12-21 18:54:17 +0000801 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000802 getFilePaths().push_back("/usr/lib");
803 getFilePaths().push_back("/usr/lib/gcc41");
804}
805
806Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
807 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000808 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000809 Key = Action::AnalyzeJobClass;
810 else
811 Key = JA.getKind();
812
813 Tool *&T = Tools[Key];
814 if (!T) {
815 switch (Key) {
816 case Action::AssembleJobClass:
817 T = new tools::dragonfly::Assemble(*this); break;
818 case Action::LinkJobClass:
819 T = new tools::dragonfly::Link(*this); break;
820 default:
821 T = &Generic_GCC::SelectTool(C, JA);
822 }
823 }
824
825 return *T;
826}