blob: 3b1c2c73fd74950de16608e0504ff2efa3e7ad60 [file] [log] [blame]
Nick Lewyckybb3f9952010-12-01 04:33:27 +00001//===--- HostInfo.cpp - Host specific information -------------------------===//
Daniel Dunbare3995642009-03-10 23:50:49 +00002//
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 {
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000041 /// Cache of tool chains we have created.
Daniel Dunbar7ef7f132009-09-08 23:37:36 +000042 mutable llvm::DenseMap<unsigned, ToolChain*> ToolChains;
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000043
44public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +000045 DarwinHostInfo(const Driver &D, const llvm::Triple &Triple);
Daniel Dunbar7e4534d2009-03-18 01:09:40 +000046 ~DarwinHostInfo();
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000047
48 virtual bool useDriverDriver() const;
49
Daniel Dunbard7502d02009-09-08 23:37:19 +000050 virtual ToolChain *CreateToolChain(const ArgList &Args,
51 const char *ArchName) const;
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000052};
53
Daniel Dunbarcb8ab232009-05-22 02:53:45 +000054DarwinHostInfo::DarwinHostInfo(const Driver &D, const llvm::Triple& Triple)
55 : HostInfo(D, Triple) {
Daniel Dunbare3995642009-03-10 23:50:49 +000056}
57
Daniel Dunbar7e4534d2009-03-18 01:09:40 +000058DarwinHostInfo::~DarwinHostInfo() {
Daniel Dunbar7ef7f132009-09-08 23:37:36 +000059 for (llvm::DenseMap<unsigned, ToolChain*>::iterator
Daniel Dunbar7e4534d2009-03-18 01:09:40 +000060 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
61 delete it->second;
62}
63
Daniel Dunbarfe8aa472009-09-08 23:37:08 +000064bool DarwinHostInfo::useDriverDriver() const {
Daniel Dunbare3995642009-03-10 23:50:49 +000065 return true;
66}
67
Daniel Dunbard7502d02009-09-08 23:37:19 +000068ToolChain *DarwinHostInfo::CreateToolChain(const ArgList &Args,
69 const char *ArchName) const {
Daniel Dunbar7ef7f132009-09-08 23:37:36 +000070 llvm::Triple::ArchType Arch;
71
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000072 if (!ArchName) {
Daniel Dunbarf2edbf32009-06-16 21:39:33 +000073 // If we aren't looking for a specific arch, infer the default architecture
74 // based on -arch and -m32/-m64 command line options.
75 if (Arg *A = Args.getLastArg(options::OPT_arch)) {
76 // The gcc driver behavior with multiple -arch flags wasn't consistent for
77 // things which rely on a default architecture. We just use the last -arch
Daniel Dunbar26031372010-01-27 00:56:25 +000078 // to find the default tool chain (assuming it is valid).
Daniel Dunbar7ef7f132009-09-08 23:37:36 +000079 Arch = llvm::Triple::getArchTypeForDarwinArchName(A->getValue(Args));
Daniel Dunbarfe8aa472009-09-08 23:37:08 +000080
Daniel Dunbar7ef7f132009-09-08 23:37:36 +000081 // If it was invalid just use the host, we will reject this command line
82 // later.
83 if (Arch == llvm::Triple::UnknownArch)
84 Arch = getTriple().getArch();
Daniel Dunbarf2edbf32009-06-16 21:39:33 +000085 } else {
86 // Otherwise default to the arch of the host.
Daniel Dunbar7ef7f132009-09-08 23:37:36 +000087 Arch = getTriple().getArch();
Daniel Dunbarf2edbf32009-06-16 21:39:33 +000088 }
Daniel Dunbarfe8aa472009-09-08 23:37:08 +000089
Daniel Dunbarf2edbf32009-06-16 21:39:33 +000090 // Honor -m32 and -m64 when finding the default tool chain.
Daniel Dunbar7ef7f132009-09-08 23:37:36 +000091 //
92 // FIXME: Should this information be in llvm::Triple?
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +000093 if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
Daniel Dunbarb827a052009-11-19 03:26:40 +000094 if (A->getOption().matches(options::OPT_m32)) {
Daniel Dunbar7ef7f132009-09-08 23:37:36 +000095 if (Arch == llvm::Triple::x86_64)
96 Arch = llvm::Triple::x86;
97 if (Arch == llvm::Triple::ppc64)
98 Arch = llvm::Triple::ppc;
99 } else {
100 if (Arch == llvm::Triple::x86)
101 Arch = llvm::Triple::x86_64;
102 if (Arch == llvm::Triple::ppc)
103 Arch = llvm::Triple::ppc64;
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000104 }
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000105 }
Daniel Dunbar7ef7f132009-09-08 23:37:36 +0000106 } else
107 Arch = llvm::Triple::getArchTypeForDarwinArchName(ArchName);
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000108
Daniel Dunbar7ef7f132009-09-08 23:37:36 +0000109 assert(Arch != llvm::Triple::UnknownArch && "Unexpected arch!");
110 ToolChain *&TC = ToolChains[Arch];
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000111 if (!TC) {
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000112 llvm::Triple TCTriple(getTriple());
Daniel Dunbar7ef7f132009-09-08 23:37:36 +0000113 TCTriple.setArch(Arch);
Daniel Dunbar30392de2009-09-04 18:35:21 +0000114
Daniel Dunbar7ef7f132009-09-08 23:37:36 +0000115 // If we recognized the arch, match it to the toolchains we support.
Daniel Dunbar79be9402011-03-18 19:25:10 +0000116 if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64 ||
Daniel Dunbar2dc70ad2010-08-26 01:41:44 +0000117 Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb) {
Daniel Dunbar5edbd232010-08-26 00:55:55 +0000118 TC = new toolchains::DarwinClang(*this, TCTriple);
Daniel Dunbar3bc96eb2010-03-26 22:41:03 +0000119 } else
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000120 TC = new toolchains::Darwin_Generic_GCC(*this, TCTriple);
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000121 }
122
123 return TC;
Daniel Dunbare3995642009-03-10 23:50:49 +0000124}
125
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000126// TCE Host Info
127
128/// TCEHostInfo - TCE host information implementation (see http://tce.cs.tut.fi)
129class TCEHostInfo : public HostInfo {
130
131public:
132 TCEHostInfo(const Driver &D, const llvm::Triple &Triple);
Douglas Gregorda791492010-03-08 02:49:35 +0000133 ~TCEHostInfo() {}
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000134
135 virtual bool useDriverDriver() const;
136
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000137 virtual ToolChain *CreateToolChain(const ArgList &Args,
138 const char *ArchName) const;
139};
140
141TCEHostInfo::TCEHostInfo(const Driver &D, const llvm::Triple& Triple)
142 : HostInfo(D, Triple) {
143}
144
145bool TCEHostInfo::useDriverDriver() const {
146 return false;
147}
148
149ToolChain *TCEHostInfo::CreateToolChain(const ArgList &Args,
150 const char *ArchName) const {
151 llvm::Triple TCTriple(getTriple());
152// TCTriple.setArchName(ArchName);
153 return new toolchains::TCEToolChain(*this, TCTriple);
154}
155
156
Daniel Dunbare3995642009-03-10 23:50:49 +0000157// Unknown Host Info
158
Daniel Dunbar26031372010-01-27 00:56:25 +0000159/// UnknownHostInfo - Generic host information to use for unknown hosts.
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000160class UnknownHostInfo : public HostInfo {
161 /// Cache of tool chains we have created.
162 mutable llvm::StringMap<ToolChain*> ToolChains;
163
164public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000165 UnknownHostInfo(const Driver &D, const llvm::Triple& Triple);
Daniel Dunbar7e4534d2009-03-18 01:09:40 +0000166 ~UnknownHostInfo();
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000167
168 virtual bool useDriverDriver() const;
169
Daniel Dunbard7502d02009-09-08 23:37:19 +0000170 virtual ToolChain *CreateToolChain(const ArgList &Args,
171 const char *ArchName) const;
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000172};
173
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000174UnknownHostInfo::UnknownHostInfo(const Driver &D, const llvm::Triple& Triple)
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000175 : HostInfo(D, Triple) {
Daniel Dunbare3995642009-03-10 23:50:49 +0000176}
177
Daniel Dunbar7e4534d2009-03-18 01:09:40 +0000178UnknownHostInfo::~UnknownHostInfo() {
179 for (llvm::StringMap<ToolChain*>::iterator
180 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
181 delete it->second;
182}
183
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000184bool UnknownHostInfo::useDriverDriver() const {
Daniel Dunbare3995642009-03-10 23:50:49 +0000185 return false;
186}
187
Daniel Dunbard7502d02009-09-08 23:37:19 +0000188ToolChain *UnknownHostInfo::CreateToolChain(const ArgList &Args,
189 const char *ArchName) const {
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000190 assert(!ArchName &&
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000191 "Unexpected arch name on platform without driver driver support.");
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000192
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000193 // Automatically handle some instances of -m32/-m64 we know about.
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000194 std::string Arch = getArchName();
195 ArchName = Arch.c_str();
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000196 if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
Eli Friedman4e2567d2009-06-03 18:59:56 +0000197 if (Triple.getArch() == llvm::Triple::x86 ||
198 Triple.getArch() == llvm::Triple::x86_64) {
199 ArchName =
Daniel Dunbarb827a052009-11-19 03:26:40 +0000200 (A->getOption().matches(options::OPT_m32)) ? "i386" : "x86_64";
Eli Friedman4e2567d2009-06-03 18:59:56 +0000201 } else if (Triple.getArch() == llvm::Triple::ppc ||
202 Triple.getArch() == llvm::Triple::ppc64) {
203 ArchName =
Daniel Dunbarb827a052009-11-19 03:26:40 +0000204 (A->getOption().matches(options::OPT_m32)) ? "powerpc" : "powerpc64";
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000205 }
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000206 }
207
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000208 ToolChain *&TC = ToolChains[ArchName];
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000209 if (!TC) {
210 llvm::Triple TCTriple(getTriple());
211 TCTriple.setArchName(ArchName);
212
213 TC = new toolchains::Generic_GCC(*this, TCTriple);
214 }
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000215
Daniel Dunbarb25c7c12009-03-18 01:39:08 +0000216 return TC;
Daniel Dunbare3995642009-03-10 23:50:49 +0000217}
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000218
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000219// OpenBSD Host Info
220
221/// OpenBSDHostInfo - OpenBSD host information implementation.
222class OpenBSDHostInfo : public HostInfo {
223 /// Cache of tool chains we have created.
224 mutable llvm::StringMap<ToolChain*> ToolChains;
225
226public:
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000227 OpenBSDHostInfo(const Driver &D, const llvm::Triple& Triple)
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000228 : HostInfo(D, Triple) {}
229 ~OpenBSDHostInfo();
230
231 virtual bool useDriverDriver() const;
232
Daniel Dunbard7502d02009-09-08 23:37:19 +0000233 virtual ToolChain *CreateToolChain(const ArgList &Args,
234 const char *ArchName) const;
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000235};
236
237OpenBSDHostInfo::~OpenBSDHostInfo() {
238 for (llvm::StringMap<ToolChain*>::iterator
239 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
240 delete it->second;
241}
242
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000243bool OpenBSDHostInfo::useDriverDriver() const {
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000244 return false;
245}
246
Daniel Dunbard7502d02009-09-08 23:37:19 +0000247ToolChain *OpenBSDHostInfo::CreateToolChain(const ArgList &Args,
248 const char *ArchName) const {
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000249 assert(!ArchName &&
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000250 "Unexpected arch name on platform without driver driver support.");
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000251
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000252 std::string Arch = getArchName();
253 ArchName = Arch.c_str();
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000254
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000255 ToolChain *&TC = ToolChains[ArchName];
256 if (!TC) {
257 llvm::Triple TCTriple(getTriple());
258 TCTriple.setArchName(ArchName);
259
260 TC = new toolchains::OpenBSD(*this, TCTriple);
261 }
262
263 return TC;
264}
265
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000266// AuroraUX Host Info
267
268/// AuroraUXHostInfo - AuroraUX host information implementation.
269class AuroraUXHostInfo : public HostInfo {
270 /// Cache of tool chains we have created.
271 mutable llvm::StringMap<ToolChain*> ToolChains;
272
273public:
274 AuroraUXHostInfo(const Driver &D, const llvm::Triple& Triple)
275 : HostInfo(D, Triple) {}
276 ~AuroraUXHostInfo();
277
278 virtual bool useDriverDriver() const;
279
Daniel Dunbard7502d02009-09-08 23:37:19 +0000280 virtual ToolChain *CreateToolChain(const ArgList &Args,
281 const char *ArchName) const;
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000282};
283
284AuroraUXHostInfo::~AuroraUXHostInfo() {
285 for (llvm::StringMap<ToolChain*>::iterator
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000286 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000287 delete it->second;
288}
289
290bool AuroraUXHostInfo::useDriverDriver() const {
291 return false;
292}
293
Daniel Dunbard7502d02009-09-08 23:37:19 +0000294ToolChain *AuroraUXHostInfo::CreateToolChain(const ArgList &Args,
295 const char *ArchName) const {
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000296 assert(!ArchName &&
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000297 "Unexpected arch name on platform without driver driver support.");
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000298
299 ToolChain *&TC = ToolChains[getArchName()];
300
301 if (!TC) {
302 llvm::Triple TCTriple(getTriple());
303 TCTriple.setArchName(getArchName());
304
305 TC = new toolchains::AuroraUX(*this, TCTriple);
306 }
307
308 return TC;
309}
310
Daniel Dunbar75358d22009-03-30 21:06:03 +0000311// FreeBSD Host Info
312
Daniel Dunbarb85f59d2009-03-30 22:11:38 +0000313/// FreeBSDHostInfo - FreeBSD host information implementation.
Daniel Dunbar75358d22009-03-30 21:06:03 +0000314class FreeBSDHostInfo : public HostInfo {
315 /// Cache of tool chains we have created.
316 mutable llvm::StringMap<ToolChain*> ToolChains;
317
318public:
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000319 FreeBSDHostInfo(const Driver &D, const llvm::Triple& Triple)
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000320 : HostInfo(D, Triple) {}
Daniel Dunbar75358d22009-03-30 21:06:03 +0000321 ~FreeBSDHostInfo();
322
323 virtual bool useDriverDriver() const;
324
Daniel Dunbard7502d02009-09-08 23:37:19 +0000325 virtual ToolChain *CreateToolChain(const ArgList &Args,
326 const char *ArchName) const;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000327};
328
Daniel Dunbar75358d22009-03-30 21:06:03 +0000329FreeBSDHostInfo::~FreeBSDHostInfo() {
330 for (llvm::StringMap<ToolChain*>::iterator
331 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
332 delete it->second;
333}
334
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000335bool FreeBSDHostInfo::useDriverDriver() const {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000336 return false;
337}
338
Daniel Dunbard7502d02009-09-08 23:37:19 +0000339ToolChain *FreeBSDHostInfo::CreateToolChain(const ArgList &Args,
340 const char *ArchName) const {
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000341 assert(!ArchName &&
Daniel Dunbar75358d22009-03-30 21:06:03 +0000342 "Unexpected arch name on platform without driver driver support.");
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000343
Daniel Dunbar9d5600a2010-08-10 17:39:05 +0000344 // Automatically handle some instances of -m32/-m64 we know about.
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000345 std::string Arch = getArchName();
346 ArchName = Arch.c_str();
Daniel Dunbar9d5600a2010-08-10 17:39:05 +0000347 if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
348 if (Triple.getArch() == llvm::Triple::x86 ||
349 Triple.getArch() == llvm::Triple::x86_64) {
350 ArchName =
351 (A->getOption().matches(options::OPT_m32)) ? "i386" : "x86_64";
352 } else if (Triple.getArch() == llvm::Triple::ppc ||
353 Triple.getArch() == llvm::Triple::ppc64) {
354 ArchName =
355 (A->getOption().matches(options::OPT_m32)) ? "powerpc" : "powerpc64";
356 }
357 }
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000358
Daniel Dunbar75358d22009-03-30 21:06:03 +0000359 ToolChain *&TC = ToolChains[ArchName];
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000360 if (!TC) {
361 llvm::Triple TCTriple(getTriple());
362 TCTriple.setArchName(ArchName);
363
Daniel Dunbar214afe92010-08-02 05:43:59 +0000364 TC = new toolchains::FreeBSD(*this, TCTriple);
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000365 }
Daniel Dunbar75358d22009-03-30 21:06:03 +0000366
367 return TC;
368}
369
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000370// NetBSD Host Info
371
372/// NetBSDHostInfo - NetBSD host information implementation.
373class NetBSDHostInfo : public HostInfo {
374 /// Cache of tool chains we have created.
375 mutable llvm::StringMap<ToolChain*> ToolChains;
376
377public:
378 NetBSDHostInfo(const Driver &D, const llvm::Triple& Triple)
379 : HostInfo(D, Triple) {}
380 ~NetBSDHostInfo();
381
382 virtual bool useDriverDriver() const;
383
384 virtual ToolChain *CreateToolChain(const ArgList &Args,
385 const char *ArchName) const;
386};
387
388NetBSDHostInfo::~NetBSDHostInfo() {
389 for (llvm::StringMap<ToolChain*>::iterator
390 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
391 delete it->second;
392}
393
394bool NetBSDHostInfo::useDriverDriver() const {
395 return false;
396}
397
398ToolChain *NetBSDHostInfo::CreateToolChain(const ArgList &Args,
399 const char *ArchName) const {
400 assert(!ArchName &&
401 "Unexpected arch name on platform without driver driver support.");
402
403 // Automatically handle some instances of -m32/-m64 we know about.
404 std::string Arch = getArchName();
405 ArchName = Arch.c_str();
406 if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
407 if (Triple.getArch() == llvm::Triple::x86 ||
408 Triple.getArch() == llvm::Triple::x86_64) {
409 ArchName =
410 (A->getOption().matches(options::OPT_m32)) ? "i386" : "x86_64";
411 } else if (Triple.getArch() == llvm::Triple::ppc ||
412 Triple.getArch() == llvm::Triple::ppc64) {
413 ArchName =
414 (A->getOption().matches(options::OPT_m32)) ? "powerpc" : "powerpc64";
415 }
416 }
Joerg Sonnenberger182564c2011-05-16 13:35:02 +0000417 llvm::Triple TargetTriple(getTriple());
418 TargetTriple.setArchName(ArchName);
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000419
Joerg Sonnenberger182564c2011-05-16 13:35:02 +0000420 ToolChain *TC;
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000421
Joerg Sonnenberger182564c2011-05-16 13:35:02 +0000422 // XXX Cache toolchain even if -m32 is used
423 if (Arch == ArchName) {
424 TC = ToolChains[ArchName];
425 if (TC)
426 return TC;
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000427 }
428
Joerg Sonnenberger182564c2011-05-16 13:35:02 +0000429 TC = new toolchains::NetBSD(*this, TargetTriple, getTriple());
430
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000431 return TC;
432}
433
Chris Lattner38e317d2010-07-07 16:01:42 +0000434// Minix Host Info
435
436/// MinixHostInfo - Minix host information implementation.
437class MinixHostInfo : public HostInfo {
438 /// Cache of tool chains we have created.
439 mutable llvm::StringMap<ToolChain*> ToolChains;
440
441public:
442 MinixHostInfo(const Driver &D, const llvm::Triple& Triple)
443 : HostInfo(D, Triple) {}
444 ~MinixHostInfo();
445
446 virtual bool useDriverDriver() const;
447
Chris Lattner38e317d2010-07-07 16:01:42 +0000448 virtual ToolChain *CreateToolChain(const ArgList &Args,
449 const char *ArchName) const;
450};
451
452MinixHostInfo::~MinixHostInfo() {
453 for (llvm::StringMap<ToolChain*>::iterator
454 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it){
455 delete it->second;
456 }
457}
458
459bool MinixHostInfo::useDriverDriver() const {
460 return false;
461}
462
463ToolChain *MinixHostInfo::CreateToolChain(const ArgList &Args,
464 const char *ArchName) const {
465 assert(!ArchName &&
466 "Unexpected arch name on platform without driver driver support.");
467
468 std::string Arch = getArchName();
469 ArchName = Arch.c_str();
470
471 ToolChain *&TC = ToolChains[ArchName];
472 if (!TC) {
473 llvm::Triple TCTriple(getTriple());
474 TCTriple.setArchName(ArchName);
475
476 TC = new toolchains::Minix(*this, TCTriple);
477 }
478
479 return TC;
480}
481
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000482// DragonFly Host Info
483
484/// DragonFlyHostInfo - DragonFly host information implementation.
485class DragonFlyHostInfo : public HostInfo {
486 /// Cache of tool chains we have created.
487 mutable llvm::StringMap<ToolChain*> ToolChains;
488
489public:
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000490 DragonFlyHostInfo(const Driver &D, const llvm::Triple& Triple)
491 : HostInfo(D, Triple) {}
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000492 ~DragonFlyHostInfo();
493
494 virtual bool useDriverDriver() const;
495
Daniel Dunbard7502d02009-09-08 23:37:19 +0000496 virtual ToolChain *CreateToolChain(const ArgList &Args,
497 const char *ArchName) const;
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000498};
499
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000500DragonFlyHostInfo::~DragonFlyHostInfo() {
501 for (llvm::StringMap<ToolChain*>::iterator
502 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
503 delete it->second;
504}
505
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000506bool DragonFlyHostInfo::useDriverDriver() const {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000507 return false;
508}
509
Daniel Dunbard7502d02009-09-08 23:37:19 +0000510ToolChain *DragonFlyHostInfo::CreateToolChain(const ArgList &Args,
511 const char *ArchName) const {
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000512 assert(!ArchName &&
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000513 "Unexpected arch name on platform without driver driver support.");
514
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000515 ToolChain *&TC = ToolChains[getArchName()];
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000516
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000517 if (!TC) {
518 llvm::Triple TCTriple(getTriple());
519 TCTriple.setArchName(getArchName());
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000520
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000521 TC = new toolchains::DragonFly(*this, TCTriple);
522 }
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000523
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000524 return TC;
525}
526
Eli Friedman6b3454a2009-05-26 07:52:18 +0000527// Linux Host Info
528
529/// LinuxHostInfo - Linux host information implementation.
530class LinuxHostInfo : public HostInfo {
531 /// Cache of tool chains we have created.
532 mutable llvm::StringMap<ToolChain*> ToolChains;
533
534public:
535 LinuxHostInfo(const Driver &D, const llvm::Triple& Triple)
536 : HostInfo(D, Triple) {}
537 ~LinuxHostInfo();
538
539 virtual bool useDriverDriver() const;
540
Daniel Dunbard7502d02009-09-08 23:37:19 +0000541 virtual ToolChain *CreateToolChain(const ArgList &Args,
542 const char *ArchName) const;
Eli Friedman6b3454a2009-05-26 07:52:18 +0000543};
544
545LinuxHostInfo::~LinuxHostInfo() {
546 for (llvm::StringMap<ToolChain*>::iterator
547 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
548 delete it->second;
549}
550
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000551bool LinuxHostInfo::useDriverDriver() const {
Eli Friedman6b3454a2009-05-26 07:52:18 +0000552 return false;
553}
554
Daniel Dunbard7502d02009-09-08 23:37:19 +0000555ToolChain *LinuxHostInfo::CreateToolChain(const ArgList &Args,
556 const char *ArchName) const {
Eli Friedman6b3454a2009-05-26 07:52:18 +0000557
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000558 assert(!ArchName &&
Eli Friedman6b3454a2009-05-26 07:52:18 +0000559 "Unexpected arch name on platform without driver driver support.");
560
Eli Friedman4e2567d2009-06-03 18:59:56 +0000561 // Automatically handle some instances of -m32/-m64 we know about.
562 std::string Arch = getArchName();
563 ArchName = Arch.c_str();
564 if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
565 if (Triple.getArch() == llvm::Triple::x86 ||
566 Triple.getArch() == llvm::Triple::x86_64) {
567 ArchName =
Daniel Dunbarb827a052009-11-19 03:26:40 +0000568 (A->getOption().matches(options::OPT_m32)) ? "i386" : "x86_64";
Eli Friedman4e2567d2009-06-03 18:59:56 +0000569 } else if (Triple.getArch() == llvm::Triple::ppc ||
570 Triple.getArch() == llvm::Triple::ppc64) {
571 ArchName =
Daniel Dunbarb827a052009-11-19 03:26:40 +0000572 (A->getOption().matches(options::OPT_m32)) ? "powerpc" : "powerpc64";
Eli Friedman4e2567d2009-06-03 18:59:56 +0000573 }
574 }
575
Eli Friedman6b3454a2009-05-26 07:52:18 +0000576 ToolChain *&TC = ToolChains[ArchName];
577
578 if (!TC) {
579 llvm::Triple TCTriple(getTriple());
Eli Friedman4e2567d2009-06-03 18:59:56 +0000580 TCTriple.setArchName(ArchName);
Eli Friedman6b3454a2009-05-26 07:52:18 +0000581
582 TC = new toolchains::Linux(*this, TCTriple);
583 }
584
585 return TC;
586}
587
Michael J. Spencerff58e362010-08-21 21:55:07 +0000588// Windows Host Info
589
590/// WindowsHostInfo - Host information to use on Microsoft Windows.
591class WindowsHostInfo : public HostInfo {
592 /// Cache of tool chains we have created.
593 mutable llvm::StringMap<ToolChain*> ToolChains;
594
595public:
596 WindowsHostInfo(const Driver &D, const llvm::Triple& Triple);
597 ~WindowsHostInfo();
598
599 virtual bool useDriverDriver() const;
600
601 virtual types::ID lookupTypeForExtension(const char *Ext) const {
602 return types::lookupTypeForExtension(Ext);
603 }
604
605 virtual ToolChain *CreateToolChain(const ArgList &Args,
606 const char *ArchName) const;
607};
608
609WindowsHostInfo::WindowsHostInfo(const Driver &D, const llvm::Triple& Triple)
610 : HostInfo(D, Triple) {
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000611}
612
Michael J. Spencerff58e362010-08-21 21:55:07 +0000613WindowsHostInfo::~WindowsHostInfo() {
614 for (llvm::StringMap<ToolChain*>::iterator
615 it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
616 delete it->second;
617}
618
619bool WindowsHostInfo::useDriverDriver() const {
620 return false;
621}
622
623ToolChain *WindowsHostInfo::CreateToolChain(const ArgList &Args,
624 const char *ArchName) const {
625 assert(!ArchName &&
626 "Unexpected arch name on platform without driver driver support.");
627
628 // Automatically handle some instances of -m32/-m64 we know about.
629 std::string Arch = getArchName();
630 ArchName = Arch.c_str();
631 if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
632 if (Triple.getArch() == llvm::Triple::x86 ||
633 Triple.getArch() == llvm::Triple::x86_64) {
634 ArchName =
635 (A->getOption().matches(options::OPT_m32)) ? "i386" : "x86_64";
636 }
637 }
638
639 ToolChain *&TC = ToolChains[ArchName];
640 if (!TC) {
641 llvm::Triple TCTriple(getTriple());
642 TCTriple.setArchName(ArchName);
643
644 TC = new toolchains::Windows(*this, TCTriple);
645 }
646
647 return TC;
648}
649
650// FIXME: This is a placeholder.
651class MinGWHostInfo : public UnknownHostInfo {
652public:
653 MinGWHostInfo(const Driver &D, const llvm::Triple& Triple);
654};
655
656MinGWHostInfo::MinGWHostInfo(const Driver &D, const llvm::Triple& Triple)
657 : UnknownHostInfo(D, Triple) {}
658
659} // end anon namespace
660
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000661const HostInfo *
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000662clang::driver::createAuroraUXHostInfo(const Driver &D,
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000663 const llvm::Triple& Triple){
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000664 return new AuroraUXHostInfo(D, Triple);
665}
666
667const HostInfo *
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000668clang::driver::createDarwinHostInfo(const Driver &D,
669 const llvm::Triple& Triple){
670 return new DarwinHostInfo(D, Triple);
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000671}
672
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000673const HostInfo *
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000674clang::driver::createOpenBSDHostInfo(const Driver &D,
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000675 const llvm::Triple& Triple) {
676 return new OpenBSDHostInfo(D, Triple);
677}
678
679const HostInfo *
Daniel Dunbarfe8aa472009-09-08 23:37:08 +0000680clang::driver::createFreeBSDHostInfo(const Driver &D,
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000681 const llvm::Triple& Triple) {
682 return new FreeBSDHostInfo(D, Triple);
Daniel Dunbar75358d22009-03-30 21:06:03 +0000683}
684
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000685const HostInfo *
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000686clang::driver::createNetBSDHostInfo(const Driver &D,
687 const llvm::Triple& Triple) {
688 return new NetBSDHostInfo(D, Triple);
689}
690
691const HostInfo *
Chris Lattner38e317d2010-07-07 16:01:42 +0000692clang::driver::createMinixHostInfo(const Driver &D,
693 const llvm::Triple& Triple) {
694 return new MinixHostInfo(D, Triple);
695}
696
697const HostInfo *
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000698clang::driver::createDragonFlyHostInfo(const Driver &D,
699 const llvm::Triple& Triple) {
700 return new DragonFlyHostInfo(D, Triple);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000701}
702
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000703const HostInfo *
Eli Friedman6b3454a2009-05-26 07:52:18 +0000704clang::driver::createLinuxHostInfo(const Driver &D,
705 const llvm::Triple& Triple) {
706 return new LinuxHostInfo(D, Triple);
707}
708
709const HostInfo *
Chris Lattner3a47c4e2010-03-04 21:07:38 +0000710clang::driver::createTCEHostInfo(const Driver &D,
711 const llvm::Triple& Triple) {
712 return new TCEHostInfo(D, Triple);
713}
714
715const HostInfo *
Michael J. Spencerff58e362010-08-21 21:55:07 +0000716clang::driver::createWindowsHostInfo(const Driver &D,
717 const llvm::Triple& Triple) {
718 return new WindowsHostInfo(D, Triple);
719}
720
721const HostInfo *
722clang::driver::createMinGWHostInfo(const Driver &D,
723 const llvm::Triple& Triple) {
724 return new MinGWHostInfo(D, Triple);
725}
726
727const HostInfo *
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000728clang::driver::createUnknownHostInfo(const Driver &D,
729 const llvm::Triple& Triple) {
730 return new UnknownHostInfo(D, Triple);
Daniel Dunbar1fd6c4b2009-03-17 19:00:50 +0000731}