blob: d9e2e379745faa537b67ab16572897d43df1cbf8 [file] [log] [blame]
Daniel Dunbare3995642009-03-10 23:50:49 +00001//===--- HostInfo.cpp - Host specific information -----------------------*-===//
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 "clang/Driver/HostInfo.h"
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000011
12#include "clang/Driver/Arg.h"
13#include "clang/Driver/ArgList.h"
Daniel Dunbarfc6a8992009-03-20 18:21:51 +000014#include "clang/Driver/Driver.h"
15#include "clang/Driver/DriverDiagnostic.h"
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000016#include "clang/Driver/Option.h"
17#include "clang/Driver/Options.h"
18
19#include "llvm/ADT/StringMap.h"
20#include "llvm/Support/Compiler.h"
21
Daniel Dunbar83b08eb2009-03-17 21:38:00 +000022#include "ToolChains.h"
23
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000024#include <cassert>
Daniel Dunbarfe8aa472009-09-08 23:37:08 +000025
Daniel Dunbare3995642009-03-10 23:50:49 +000026using namespace clang::driver;
27
Daniel Dunbarcb8ab232009-05-22 02:53:45 +000028HostInfo::HostInfo(const Driver &D, const llvm::Triple &_Triple)
Mike Stump1eb44332009-09-09 15:08:12 +000029 : TheDriver(D), Triple(_Triple) {
Daniel Dunbare3995642009-03-10 23:50:49 +000030}
31
32HostInfo::~HostInfo() {
33}
34
Chris Lattneraae82f12009-03-17 22:24:01 +000035namespace {
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000036
Daniel Dunbare3995642009-03-10 23:50:49 +000037// Darwin Host Info
38
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000039/// DarwinHostInfo - Darwin host information implementation.
40class DarwinHostInfo : public HostInfo {
41 /// Darwin version of host.
42 unsigned DarwinVersion[3];
43
44 /// GCC version to use on this host.
Ted Kremenek55bac532009-10-07 03:21:11 +000045 unsigned GCCVersion[3];
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000046
47 /// Cache of tool chains we have created.
Daniel Dunbar7ef7f132009-09-08 23:37:36 +000048 mutable llvm::DenseMap<unsigned, ToolChain*> ToolChains;
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000049
50public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +000051 DarwinHostInfo(const Driver &D, const llvm::Triple &Triple);
Daniel Dunbar7e4534d2009-03-18 01:09:40 +000052 ~DarwinHostInfo();
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000053
54 virtual bool useDriverDriver() const;
55
Daniel Dunbare33bea42009-03-20 23:39:23 +000056 virtual types::ID lookupTypeForExtension(const char *Ext) const {
57 types::ID Ty = types::lookupTypeForExtension(Ext);
58
59 // Darwin always preprocesses assembly files (unless -x is used
60 // explicitly).
61 if (Ty == types::TY_PP_Asm)
62 return types::TY_Asm;
63
64 return Ty;
65 }
66
Daniel Dunbard7502d02009-09-08 23:37:19 +000067 virtual ToolChain *CreateToolChain(const ArgList &Args,
68 const char *ArchName) const;
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000069};
70
Daniel Dunbarcb8ab232009-05-22 02:53:45 +000071DarwinHostInfo::DarwinHostInfo(const Driver &D, const llvm::Triple& Triple)
72 : HostInfo(D, Triple) {
Daniel Dunbarfe8aa472009-09-08 23:37:08 +000073
Daniel Dunbar7ef7f132009-09-08 23:37:36 +000074 assert(Triple.getArch() != llvm::Triple::UnknownArch && "Invalid arch!");
Daniel Dunbarfc6a8992009-03-20 18:21:51 +000075 assert(memcmp(&getOSName()[0], "darwin", 6) == 0 &&
76 "Unknown Darwin platform.");
Daniel Dunbard73fe9b2009-03-26 15:58:36 +000077 bool HadExtra;
Daniel Dunbarfe8aa472009-09-08 23:37:08 +000078 if (!Driver::GetReleaseVersion(&getOSName()[6],
79 DarwinVersion[0], DarwinVersion[1],
Daniel Dunbar7ef7f132009-09-08 23:37:36 +000080 DarwinVersion[2], HadExtra))
81 D.Diag(clang::diag::err_drv_invalid_darwin_version) << getOSName();
Daniel Dunbarfe8aa472009-09-08 23:37:08 +000082
Daniel Dunbare3995642009-03-10 23:50:49 +000083 // We can only call 4.2.1 for now.
84 GCCVersion[0] = 4;
85 GCCVersion[1] = 2;
86 GCCVersion[2] = 1;
87}
88
Daniel Dunbar7e4534d2009-03-18 01:09:40 +000089DarwinHostInfo::~DarwinHostInfo() {
Daniel Dunbar7ef7f132009-09-08 23:37:36 +000090 for (llvm::DenseMap<unsigned, ToolChain*>::iterator
Daniel Dunbar7e4534d2009-03-18 01:09:40 +000091 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
92 delete it->second;
93}
94
Daniel Dunbarfe8aa472009-09-08 23:37:08 +000095bool DarwinHostInfo::useDriverDriver() const {
Daniel Dunbare3995642009-03-10 23:50:49 +000096 return true;
97}
98
Daniel Dunbard7502d02009-09-08 23:37:19 +000099ToolChain *DarwinHostInfo::CreateToolChain(const ArgList &Args,
100 const char *ArchName) const {
Daniel Dunbar7ef7f132009-09-08 23:37:36 +0000101 llvm::Triple::ArchType Arch;
102
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000103 if (!ArchName) {
Daniel Dunbarf2edbf32009-06-16 21:39:33 +0000104 // If we aren't looking for a specific arch, infer the default architecture
105 // based on -arch and -m32/-m64 command line options.
106 if (Arg *A = Args.getLastArg(options::OPT_arch)) {
107 // The gcc driver behavior with multiple -arch flags wasn't consistent for
108 // things which rely on a default architecture. We just use the last -arch
Daniel Dunbar26031372010-01-27 00:56:25 +0000109 // to find the default tool chain (assuming it is valid).
Daniel Dunbar7ef7f132009-09-08 23:37:36 +0000110 Arch = llvm::Triple::getArchTypeForDarwinArchName(A->getValue(Args));
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000111
Daniel Dunbar7ef7f132009-09-08 23:37:36 +0000112 // If it was invalid just use the host, we will reject this command line
113 // later.
114 if (Arch == llvm::Triple::UnknownArch)
115 Arch = getTriple().getArch();
Daniel Dunbarf2edbf32009-06-16 21:39:33 +0000116 } else {
117 // Otherwise default to the arch of the host.
Daniel Dunbar7ef7f132009-09-08 23:37:36 +0000118 Arch = getTriple().getArch();
Daniel Dunbarf2edbf32009-06-16 21:39:33 +0000119 }
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000120
Daniel Dunbarf2edbf32009-06-16 21:39:33 +0000121 // Honor -m32 and -m64 when finding the default tool chain.
Daniel Dunbar7ef7f132009-09-08 23:37:36 +0000122 //
123 // FIXME: Should this information be in llvm::Triple?
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000124 if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
Daniel Dunbarb827a052009-11-19 03:26:40 +0000125 if (A->getOption().matches(options::OPT_m32)) {
Daniel Dunbar7ef7f132009-09-08 23:37:36 +0000126 if (Arch == llvm::Triple::x86_64)
127 Arch = llvm::Triple::x86;
128 if (Arch == llvm::Triple::ppc64)
129 Arch = llvm::Triple::ppc;
130 } else {
131 if (Arch == llvm::Triple::x86)
132 Arch = llvm::Triple::x86_64;
133 if (Arch == llvm::Triple::ppc)
134 Arch = llvm::Triple::ppc64;
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000135 }
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000136 }
Daniel Dunbar7ef7f132009-09-08 23:37:36 +0000137 } else
138 Arch = llvm::Triple::getArchTypeForDarwinArchName(ArchName);
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000139
Daniel Dunbar7ef7f132009-09-08 23:37:36 +0000140 assert(Arch != llvm::Triple::UnknownArch && "Unexpected arch!");
141 ToolChain *&TC = ToolChains[Arch];
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000142 if (!TC) {
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000143 llvm::Triple TCTriple(getTriple());
Daniel Dunbar7ef7f132009-09-08 23:37:36 +0000144 TCTriple.setArch(Arch);
Daniel Dunbar30392de2009-09-04 18:35:21 +0000145
Daniel Dunbar7ef7f132009-09-08 23:37:36 +0000146 // If we recognized the arch, match it to the toolchains we support.
Daniel Dunbar3bc96eb2010-03-26 22:41:03 +0000147 const char *UseNewToolChain = ::getenv("CCC_ENABLE_NEW_DARWIN_TOOLCHAIN");
148 if (UseNewToolChain ||
149 Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) {
150 TC = new toolchains::DarwinClang(*this, TCTriple, DarwinVersion);
151 } else if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000152 // We still use the legacy DarwinGCC toolchain on X86.
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000153 TC = new toolchains::DarwinGCC(*this, TCTriple, DarwinVersion,
154 GCCVersion);
Daniel Dunbar3bc96eb2010-03-26 22:41:03 +0000155 } else
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000156 TC = new toolchains::Darwin_Generic_GCC(*this, TCTriple);
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000157 }
158
159 return TC;
Daniel Dunbare3995642009-03-10 23:50:49 +0000160}
161
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000162// TCE Host Info
163
164/// TCEHostInfo - TCE host information implementation (see http://tce.cs.tut.fi)
165class TCEHostInfo : public HostInfo {
166
167public:
168 TCEHostInfo(const Driver &D, const llvm::Triple &Triple);
Douglas Gregorda791492010-03-08 02:49:35 +0000169 ~TCEHostInfo() {}
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000170
171 virtual bool useDriverDriver() const;
172
173 virtual types::ID lookupTypeForExtension(const char *Ext) const {
174 types::ID Ty = types::lookupTypeForExtension(Ext);
175
176 if (Ty == types::TY_PP_Asm)
177 return types::TY_Asm;
178
179 return Ty;
180 }
181
182 virtual ToolChain *CreateToolChain(const ArgList &Args,
183 const char *ArchName) const;
184};
185
186TCEHostInfo::TCEHostInfo(const Driver &D, const llvm::Triple& Triple)
187 : HostInfo(D, Triple) {
188}
189
190bool TCEHostInfo::useDriverDriver() const {
191 return false;
192}
193
194ToolChain *TCEHostInfo::CreateToolChain(const ArgList &Args,
195 const char *ArchName) const {
196 llvm::Triple TCTriple(getTriple());
197// TCTriple.setArchName(ArchName);
198 return new toolchains::TCEToolChain(*this, TCTriple);
199}
200
201
Daniel Dunbare3995642009-03-10 23:50:49 +0000202// Unknown Host Info
203
Daniel Dunbar26031372010-01-27 00:56:25 +0000204/// UnknownHostInfo - Generic host information to use for unknown hosts.
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000205class UnknownHostInfo : public HostInfo {
206 /// Cache of tool chains we have created.
207 mutable llvm::StringMap<ToolChain*> ToolChains;
208
209public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000210 UnknownHostInfo(const Driver &D, const llvm::Triple& Triple);
Daniel Dunbar7e4534d2009-03-18 01:09:40 +0000211 ~UnknownHostInfo();
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000212
213 virtual bool useDriverDriver() const;
214
Daniel Dunbare33bea42009-03-20 23:39:23 +0000215 virtual types::ID lookupTypeForExtension(const char *Ext) const {
216 return types::lookupTypeForExtension(Ext);
217 }
218
Daniel Dunbard7502d02009-09-08 23:37:19 +0000219 virtual ToolChain *CreateToolChain(const ArgList &Args,
220 const char *ArchName) const;
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000221};
222
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000223UnknownHostInfo::UnknownHostInfo(const Driver &D, const llvm::Triple& Triple)
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000224 : HostInfo(D, Triple) {
Daniel Dunbare3995642009-03-10 23:50:49 +0000225}
226
Daniel Dunbar7e4534d2009-03-18 01:09:40 +0000227UnknownHostInfo::~UnknownHostInfo() {
228 for (llvm::StringMap<ToolChain*>::iterator
229 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
230 delete it->second;
231}
232
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000233bool UnknownHostInfo::useDriverDriver() const {
Daniel Dunbare3995642009-03-10 23:50:49 +0000234 return false;
235}
236
Daniel Dunbard7502d02009-09-08 23:37:19 +0000237ToolChain *UnknownHostInfo::CreateToolChain(const ArgList &Args,
238 const char *ArchName) const {
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000239 assert(!ArchName &&
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000240 "Unexpected arch name on platform without driver driver support.");
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000241
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000242 // Automatically handle some instances of -m32/-m64 we know about.
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000243 std::string Arch = getArchName();
244 ArchName = Arch.c_str();
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000245 if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
Eli Friedman4e2567d2009-06-03 18:59:56 +0000246 if (Triple.getArch() == llvm::Triple::x86 ||
247 Triple.getArch() == llvm::Triple::x86_64) {
248 ArchName =
Daniel Dunbarb827a052009-11-19 03:26:40 +0000249 (A->getOption().matches(options::OPT_m32)) ? "i386" : "x86_64";
Eli Friedman4e2567d2009-06-03 18:59:56 +0000250 } else if (Triple.getArch() == llvm::Triple::ppc ||
251 Triple.getArch() == llvm::Triple::ppc64) {
252 ArchName =
Daniel Dunbarb827a052009-11-19 03:26:40 +0000253 (A->getOption().matches(options::OPT_m32)) ? "powerpc" : "powerpc64";
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000254 }
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000255 }
256
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000257 ToolChain *&TC = ToolChains[ArchName];
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000258 if (!TC) {
259 llvm::Triple TCTriple(getTriple());
260 TCTriple.setArchName(ArchName);
261
262 TC = new toolchains::Generic_GCC(*this, TCTriple);
263 }
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000264
Daniel Dunbarb25c7c12009-03-18 01:39:08 +0000265 return TC;
Daniel Dunbare3995642009-03-10 23:50:49 +0000266}
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000267
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000268// OpenBSD Host Info
269
270/// OpenBSDHostInfo - OpenBSD host information implementation.
271class OpenBSDHostInfo : public HostInfo {
272 /// Cache of tool chains we have created.
273 mutable llvm::StringMap<ToolChain*> ToolChains;
274
275public:
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000276 OpenBSDHostInfo(const Driver &D, const llvm::Triple& Triple)
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000277 : HostInfo(D, Triple) {}
278 ~OpenBSDHostInfo();
279
280 virtual bool useDriverDriver() const;
281
282 virtual types::ID lookupTypeForExtension(const char *Ext) const {
283 return types::lookupTypeForExtension(Ext);
284 }
285
Daniel Dunbard7502d02009-09-08 23:37:19 +0000286 virtual ToolChain *CreateToolChain(const ArgList &Args,
287 const char *ArchName) const;
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000288};
289
290OpenBSDHostInfo::~OpenBSDHostInfo() {
291 for (llvm::StringMap<ToolChain*>::iterator
292 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
293 delete it->second;
294}
295
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000296bool OpenBSDHostInfo::useDriverDriver() const {
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000297 return false;
298}
299
Daniel Dunbard7502d02009-09-08 23:37:19 +0000300ToolChain *OpenBSDHostInfo::CreateToolChain(const ArgList &Args,
301 const char *ArchName) const {
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000302 assert(!ArchName &&
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000303 "Unexpected arch name on platform without driver driver support.");
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000304
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000305 std::string Arch = getArchName();
306 ArchName = Arch.c_str();
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000307
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000308 ToolChain *&TC = ToolChains[ArchName];
309 if (!TC) {
310 llvm::Triple TCTriple(getTriple());
311 TCTriple.setArchName(ArchName);
312
313 TC = new toolchains::OpenBSD(*this, TCTriple);
314 }
315
316 return TC;
317}
318
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000319// AuroraUX Host Info
320
321/// AuroraUXHostInfo - AuroraUX host information implementation.
322class AuroraUXHostInfo : public HostInfo {
323 /// Cache of tool chains we have created.
324 mutable llvm::StringMap<ToolChain*> ToolChains;
325
326public:
327 AuroraUXHostInfo(const Driver &D, const llvm::Triple& Triple)
328 : HostInfo(D, Triple) {}
329 ~AuroraUXHostInfo();
330
331 virtual bool useDriverDriver() const;
332
333 virtual types::ID lookupTypeForExtension(const char *Ext) const {
334 return types::lookupTypeForExtension(Ext);
335 }
336
Daniel Dunbard7502d02009-09-08 23:37:19 +0000337 virtual ToolChain *CreateToolChain(const ArgList &Args,
338 const char *ArchName) const;
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000339};
340
341AuroraUXHostInfo::~AuroraUXHostInfo() {
342 for (llvm::StringMap<ToolChain*>::iterator
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000343 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000344 delete it->second;
345}
346
347bool AuroraUXHostInfo::useDriverDriver() const {
348 return false;
349}
350
Daniel Dunbard7502d02009-09-08 23:37:19 +0000351ToolChain *AuroraUXHostInfo::CreateToolChain(const ArgList &Args,
352 const char *ArchName) const {
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000353 assert(!ArchName &&
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000354 "Unexpected arch name on platform without driver driver support.");
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000355
356 ToolChain *&TC = ToolChains[getArchName()];
357
358 if (!TC) {
359 llvm::Triple TCTriple(getTriple());
360 TCTriple.setArchName(getArchName());
361
362 TC = new toolchains::AuroraUX(*this, TCTriple);
363 }
364
365 return TC;
366}
367
Daniel Dunbar75358d22009-03-30 21:06:03 +0000368// FreeBSD Host Info
369
Daniel Dunbarb85f59d2009-03-30 22:11:38 +0000370/// FreeBSDHostInfo - FreeBSD host information implementation.
Daniel Dunbar75358d22009-03-30 21:06:03 +0000371class FreeBSDHostInfo : public HostInfo {
372 /// Cache of tool chains we have created.
373 mutable llvm::StringMap<ToolChain*> ToolChains;
374
375public:
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000376 FreeBSDHostInfo(const Driver &D, const llvm::Triple& Triple)
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000377 : HostInfo(D, Triple) {}
Daniel Dunbar75358d22009-03-30 21:06:03 +0000378 ~FreeBSDHostInfo();
379
380 virtual bool useDriverDriver() const;
381
382 virtual types::ID lookupTypeForExtension(const char *Ext) const {
383 return types::lookupTypeForExtension(Ext);
384 }
385
Daniel Dunbard7502d02009-09-08 23:37:19 +0000386 virtual ToolChain *CreateToolChain(const ArgList &Args,
387 const char *ArchName) const;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000388};
389
Daniel Dunbar75358d22009-03-30 21:06:03 +0000390FreeBSDHostInfo::~FreeBSDHostInfo() {
391 for (llvm::StringMap<ToolChain*>::iterator
392 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
393 delete it->second;
394}
395
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000396bool FreeBSDHostInfo::useDriverDriver() const {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000397 return false;
398}
399
Daniel Dunbard7502d02009-09-08 23:37:19 +0000400ToolChain *FreeBSDHostInfo::CreateToolChain(const ArgList &Args,
401 const char *ArchName) const {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000402 bool Lib32 = false;
403
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000404 assert(!ArchName &&
Daniel Dunbar75358d22009-03-30 21:06:03 +0000405 "Unexpected arch name on platform without driver driver support.");
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000406
Daniel Dunbar75358d22009-03-30 21:06:03 +0000407 // On x86_64 we need to be able to compile 32-bits binaries as well.
408 // Compiling 64-bit binaries on i386 is not supported. We don't have a
409 // lib64.
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000410 std::string Arch = getArchName();
411 ArchName = Arch.c_str();
Daniel Dunbar75358d22009-03-30 21:06:03 +0000412 if (Args.hasArg(options::OPT_m32) && getArchName() == "x86_64") {
413 ArchName = "i386";
414 Lib32 = true;
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000415 }
416
Daniel Dunbar75358d22009-03-30 21:06:03 +0000417 ToolChain *&TC = ToolChains[ArchName];
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000418 if (!TC) {
419 llvm::Triple TCTriple(getTriple());
420 TCTriple.setArchName(ArchName);
421
422 TC = new toolchains::FreeBSD(*this, TCTriple, Lib32);
423 }
Daniel Dunbar75358d22009-03-30 21:06:03 +0000424
425 return TC;
426}
427
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000428// DragonFly Host Info
429
430/// DragonFlyHostInfo - DragonFly host information implementation.
431class DragonFlyHostInfo : public HostInfo {
432 /// Cache of tool chains we have created.
433 mutable llvm::StringMap<ToolChain*> ToolChains;
434
435public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000436 DragonFlyHostInfo(const Driver &D, const llvm::Triple& Triple)
437 : HostInfo(D, Triple) {}
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000438 ~DragonFlyHostInfo();
439
440 virtual bool useDriverDriver() const;
441
442 virtual types::ID lookupTypeForExtension(const char *Ext) const {
443 return types::lookupTypeForExtension(Ext);
444 }
445
Daniel Dunbard7502d02009-09-08 23:37:19 +0000446 virtual ToolChain *CreateToolChain(const ArgList &Args,
447 const char *ArchName) const;
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000448};
449
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000450DragonFlyHostInfo::~DragonFlyHostInfo() {
451 for (llvm::StringMap<ToolChain*>::iterator
452 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
453 delete it->second;
454}
455
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000456bool DragonFlyHostInfo::useDriverDriver() const {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000457 return false;
458}
459
Daniel Dunbard7502d02009-09-08 23:37:19 +0000460ToolChain *DragonFlyHostInfo::CreateToolChain(const ArgList &Args,
461 const char *ArchName) const {
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000462 assert(!ArchName &&
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000463 "Unexpected arch name on platform without driver driver support.");
464
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000465 ToolChain *&TC = ToolChains[getArchName()];
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000466
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000467 if (!TC) {
468 llvm::Triple TCTriple(getTriple());
469 TCTriple.setArchName(getArchName());
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000470
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000471 TC = new toolchains::DragonFly(*this, TCTriple);
472 }
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000473
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000474 return TC;
475}
476
Eli Friedman6b3454a2009-05-26 07:52:18 +0000477// Linux Host Info
478
479/// LinuxHostInfo - Linux host information implementation.
480class LinuxHostInfo : public HostInfo {
481 /// Cache of tool chains we have created.
482 mutable llvm::StringMap<ToolChain*> ToolChains;
483
484public:
485 LinuxHostInfo(const Driver &D, const llvm::Triple& Triple)
486 : HostInfo(D, Triple) {}
487 ~LinuxHostInfo();
488
489 virtual bool useDriverDriver() const;
490
491 virtual types::ID lookupTypeForExtension(const char *Ext) const {
492 return types::lookupTypeForExtension(Ext);
493 }
494
Daniel Dunbard7502d02009-09-08 23:37:19 +0000495 virtual ToolChain *CreateToolChain(const ArgList &Args,
496 const char *ArchName) const;
Eli Friedman6b3454a2009-05-26 07:52:18 +0000497};
498
499LinuxHostInfo::~LinuxHostInfo() {
500 for (llvm::StringMap<ToolChain*>::iterator
501 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
502 delete it->second;
503}
504
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000505bool LinuxHostInfo::useDriverDriver() const {
Eli Friedman6b3454a2009-05-26 07:52:18 +0000506 return false;
507}
508
Daniel Dunbard7502d02009-09-08 23:37:19 +0000509ToolChain *LinuxHostInfo::CreateToolChain(const ArgList &Args,
510 const char *ArchName) const {
Eli Friedman6b3454a2009-05-26 07:52:18 +0000511
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000512 assert(!ArchName &&
Eli Friedman6b3454a2009-05-26 07:52:18 +0000513 "Unexpected arch name on platform without driver driver support.");
514
Eli Friedman4e2567d2009-06-03 18:59:56 +0000515 // Automatically handle some instances of -m32/-m64 we know about.
516 std::string Arch = getArchName();
517 ArchName = Arch.c_str();
518 if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
519 if (Triple.getArch() == llvm::Triple::x86 ||
520 Triple.getArch() == llvm::Triple::x86_64) {
521 ArchName =
Daniel Dunbarb827a052009-11-19 03:26:40 +0000522 (A->getOption().matches(options::OPT_m32)) ? "i386" : "x86_64";
Eli Friedman4e2567d2009-06-03 18:59:56 +0000523 } else if (Triple.getArch() == llvm::Triple::ppc ||
524 Triple.getArch() == llvm::Triple::ppc64) {
525 ArchName =
Daniel Dunbarb827a052009-11-19 03:26:40 +0000526 (A->getOption().matches(options::OPT_m32)) ? "powerpc" : "powerpc64";
Eli Friedman4e2567d2009-06-03 18:59:56 +0000527 }
528 }
529
Eli Friedman6b3454a2009-05-26 07:52:18 +0000530 ToolChain *&TC = ToolChains[ArchName];
531
532 if (!TC) {
533 llvm::Triple TCTriple(getTriple());
Eli Friedman4e2567d2009-06-03 18:59:56 +0000534 TCTriple.setArchName(ArchName);
Eli Friedman6b3454a2009-05-26 07:52:18 +0000535
536 TC = new toolchains::Linux(*this, TCTriple);
537 }
538
539 return TC;
540}
541
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000542}
543
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000544const HostInfo *
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000545clang::driver::createAuroraUXHostInfo(const Driver &D,
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000546 const llvm::Triple& Triple){
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000547 return new AuroraUXHostInfo(D, Triple);
548}
549
550const HostInfo *
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000551clang::driver::createDarwinHostInfo(const Driver &D,
552 const llvm::Triple& Triple){
553 return new DarwinHostInfo(D, Triple);
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000554}
555
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000556const HostInfo *
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000557clang::driver::createOpenBSDHostInfo(const Driver &D,
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000558 const llvm::Triple& Triple) {
559 return new OpenBSDHostInfo(D, Triple);
560}
561
562const HostInfo *
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000563clang::driver::createFreeBSDHostInfo(const Driver &D,
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000564 const llvm::Triple& Triple) {
565 return new FreeBSDHostInfo(D, Triple);
Daniel Dunbar75358d22009-03-30 21:06:03 +0000566}
567
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000568const HostInfo *
569clang::driver::createDragonFlyHostInfo(const Driver &D,
570 const llvm::Triple& Triple) {
571 return new DragonFlyHostInfo(D, Triple);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000572}
573
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000574const HostInfo *
Eli Friedman6b3454a2009-05-26 07:52:18 +0000575clang::driver::createLinuxHostInfo(const Driver &D,
576 const llvm::Triple& Triple) {
577 return new LinuxHostInfo(D, Triple);
578}
579
580const HostInfo *
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000581clang::driver::createTCEHostInfo(const Driver &D,
582 const llvm::Triple& Triple) {
583 return new TCEHostInfo(D, Triple);
584}
585
586const HostInfo *
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000587clang::driver::createUnknownHostInfo(const Driver &D,
588 const llvm::Triple& Triple) {
589 return new UnknownHostInfo(D, Triple);
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000590}