1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
//===--- HostInfo.cpp - Host specific information -----------------------*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "clang/Driver/HostInfo.h"
#include "clang/Driver/Arg.h"
#include "clang/Driver/ArgList.h"
#include "clang/Driver/Option.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Compiler.h"
#include <cassert>
using namespace clang::driver;
HostInfo::HostInfo(const char *_Arch, const char *_Platform,
const char *_OS)
: Arch(_Arch), Platform(_Platform), OS(_OS)
{
}
HostInfo::~HostInfo() {
}
namespace VISIBILITY_HIDDEN {
// Darwin Host Info
/// DarwinHostInfo - Darwin host information implementation.
class DarwinHostInfo : public HostInfo {
/// Darwin version of host.
unsigned DarwinVersion[3];
/// GCC version to use on this host.
unsigned GCCVersion[3];
/// Cache of tool chains we have created.
mutable llvm::StringMap<ToolChain*> ToolChains;
public:
DarwinHostInfo(const char *Arch, const char *Platform, const char *OS);
virtual bool useDriverDriver() const;
virtual ToolChain *getToolChain(const ArgList &Args,
const char *ArchName) const;
};
DarwinHostInfo::DarwinHostInfo(const char *_Arch, const char *_Platform,
const char *_OS)
: HostInfo(_Arch, _Platform, _OS) {
assert((getArchName() == "i386" || getArchName() == "x86_64" ||
getArchName() == "ppc" || getArchName() == "ppc64") &&
"Unknown Darwin arch.");
// FIXME: How to deal with errors?
// We can only call 4.2.1 for now.
GCCVersion[0] = 4;
GCCVersion[1] = 2;
GCCVersion[2] = 1;
}
bool DarwinHostInfo::useDriverDriver() const {
return true;
}
ToolChain *DarwinHostInfo::getToolChain(const ArgList &Args,
const char *ArchName) const {
if (!ArchName) {
ArchName = getArchName().c_str();
// If no arch name is specified, infer it from the host and
// -m32/-m64.
if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
if (getArchName() == "i386" || getArchName() == "x86_64") {
ArchName =
(A->getOption().getId() == options::OPT_m32) ? "i386" : "x86_64";
} else if (getArchName() == "ppc" || getArchName() == "ppc64") {
ArchName =
(A->getOption().getId() == options::OPT_m32) ? "ppc" : "ppc64";
}
}
}
ToolChain *&TC = ToolChains[ArchName];
if (!TC) {
TC = 0;
#if 0
if (ArchName == "i386")
TC = new Darwin_X86_ToolChain(ArchName);
else if (ArchName == "x86_64")
TC = new Darwin_X86_ToolChain(ArchName);
else
TC = new Darwin_GCC_ToolChain(ArchName);
#endif
}
return TC;
}
// Unknown Host Info
/// UnknownHostInfo - Generic host information to use for unknown
/// hosts.
class UnknownHostInfo : public HostInfo {
/// Cache of tool chains we have created.
mutable llvm::StringMap<ToolChain*> ToolChains;
public:
UnknownHostInfo(const char *Arch, const char *Platform, const char *OS);
virtual bool useDriverDriver() const;
virtual ToolChain *getToolChain(const ArgList &Args,
const char *ArchName) const;
};
UnknownHostInfo::UnknownHostInfo(const char *Arch, const char *Platform,
const char *OS)
: HostInfo(Arch, Platform, OS) {
}
bool UnknownHostInfo::useDriverDriver() const {
return false;
}
ToolChain *UnknownHostInfo::getToolChain(const ArgList &Args,
const char *ArchName) const {
assert(!ArchName &&
"Unexpected arch name on platform without driver driver support.");
// Automatically handle some instances of -m32/-m64 we know about.
ArchName = getArchName().c_str();
if (Arg *A = Args.getLastArg(options::OPT_m32, options::OPT_m64)) {
if (getArchName() == "i386" || getArchName() == "x86_64") {
ArchName =
(A->getOption().getId() == options::OPT_m32) ? "i386" : "x86_64";
} else if (getArchName() == "ppc" || getArchName() == "ppc64") {
ArchName =
(A->getOption().getId() == options::OPT_m32) ? "ppc" : "ppc64";
}
}
ToolChain *&TC = ToolChains[ArchName];
if (!TC)
TC = 0; //new Generic_GCC_ToolChain(ArchName);
return 0;
}
}
const HostInfo *clang::driver::createDarwinHostInfo(const char *Arch,
const char *Platform,
const char *OS) {
return new DarwinHostInfo(Arch, Platform, OS);
}
const HostInfo *clang::driver::createUnknownHostInfo(const char *Arch,
const char *Platform,
const char *OS) {
return new UnknownHostInfo(Arch, Platform, OS);
}
|