blob: 898f12e8f2502a6afecf769d922bbc1d48b83225 [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"
15#include "clang/Driver/HostInfo.h"
16
17#include "llvm/ADT/StringExtras.h"
18#include "llvm/System/Path.h"
19
Daniel Dunbar39176082009-03-20 00:20:03 +000020using namespace clang::driver;
21using namespace clang::driver::toolchains;
22
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000023/// Darwin_X86 - Darwin tool chain for i386 and x86_64.
24
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000025Darwin_X86::Darwin_X86(const HostInfo &Host, const char *Arch,
26 const char *Platform, const char *OS,
27 const unsigned (&_DarwinVersion)[3],
28 const unsigned (&_GCCVersion)[3])
29 : ToolChain(Host, Arch, Platform, OS)
30{
31 DarwinVersion[0] = _DarwinVersion[0];
32 DarwinVersion[1] = _DarwinVersion[1];
33 DarwinVersion[2] = _DarwinVersion[2];
34 GCCVersion[0] = _GCCVersion[0];
35 GCCVersion[1] = _GCCVersion[1];
36 GCCVersion[2] = _GCCVersion[2];
37
38 ToolChainDir = "i686-apple-darwin";
39 ToolChainDir += llvm::utostr(DarwinVersion[0]);
40 ToolChainDir += "/";
41 ToolChainDir += llvm::utostr(GCCVersion[0]);
42 ToolChainDir += '.';
43 ToolChainDir += llvm::utostr(GCCVersion[1]);
44 ToolChainDir += '.';
45 ToolChainDir += llvm::utostr(GCCVersion[2]);
46
47 std::string Path;
48 if (getArchName() == "x86_64") {
49 Path = getHost().getDriver().Dir;
50 Path += "/../lib/gcc/";
51 Path += getToolChainDir();
52 Path += "/x86_64";
53 getFilePaths().push_back(Path);
54
55 Path = "/usr/lib/gcc/";
56 Path += getToolChainDir();
57 Path += "/x86_64";
58 getFilePaths().push_back(Path);
59 }
60
61 Path = getHost().getDriver().Dir;
62 Path += "/../lib/gcc/";
63 Path += getToolChainDir();
64 getFilePaths().push_back(Path);
65
66 Path = "/usr/lib/gcc/";
67 Path += getToolChainDir();
68 getFilePaths().push_back(Path);
69
70 Path = getHost().getDriver().Dir;
71 Path += "/../libexec/gcc/";
72 Path += getToolChainDir();
73 getProgramPaths().push_back(Path);
74
75 Path = "/usr/libexec/gcc/";
76 Path += getToolChainDir();
77 getProgramPaths().push_back(Path);
78
Daniel Dunbar82fa7c52009-03-24 04:07:10 +000079 Path = getHost().getDriver().Dir;
80 Path += "/../libexec";
81 getProgramPaths().push_back(Path);
82
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000083 getProgramPaths().push_back(getHost().getDriver().Dir);
84}
85
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000086Darwin_X86::~Darwin_X86() {
87 // Free tool implementations.
88 for (llvm::DenseMap<unsigned, Tool*>::iterator
89 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
90 delete it->second;
91}
92
93Tool &Darwin_X86::SelectTool(const Compilation &C,
94 const JobAction &JA) const {
95 Action::ActionClass Key;
Daniel Dunbaraf80e1f2009-03-24 18:57:02 +000096 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName()))
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000097 Key = Action::AnalyzeJobClass;
98 else
99 Key = JA.getKind();
100
101 Tool *&T = Tools[Key];
102 if (!T) {
103 switch (Key) {
104 case Action::InputClass:
105 case Action::BindArchClass:
106 assert(0 && "Invalid tool kind.");
107 case Action::PreprocessJobClass:
108 T = new tools::gcc::Preprocess(*this); break;
109 case Action::PrecompileJobClass:
110 T = new tools::gcc::Precompile(*this); break;
111 case Action::AnalyzeJobClass:
112 T = new tools::Clang(*this); break;
113 case Action::CompileJobClass:
114 T = new tools::gcc::Compile(*this); break;
115 case Action::AssembleJobClass:
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000116 T = new tools::darwin::Assemble(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000117 case Action::LinkJobClass:
118 T = new tools::gcc::Link(*this); break;
119 case Action::LipoJobClass:
120 T = new tools::darwin::Lipo(*this); break;
121 }
122 }
123
124 return *T;
125}
126
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000127DerivedArgList *Darwin_X86::TranslateArgs(InputArgList &Args) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000128 // FIXME: Implement!
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000129 return new DerivedArgList(Args, true);
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000130}
131
132bool Darwin_X86::IsMathErrnoDefault() const {
133 return false;
134}
135
136bool Darwin_X86::IsUnwindTablesDefault() const {
137 // FIXME: Gross; we should probably have some separate target
138 // definition, possibly even reusing the one in clang.
139 return getArchName() == "x86_64";
140}
141
142const char *Darwin_X86::GetDefaultRelocationModel() const {
143 return "pic";
144}
145
146const char *Darwin_X86::GetForcedPicModel() const {
147 if (getArchName() == "x86_64")
148 return "pic";
149 return 0;
150}
151
Daniel Dunbar39176082009-03-20 00:20:03 +0000152/// Generic_GCC - A tool chain using the 'gcc' command to perform
153/// all subcommands; this relies on gcc translating the majority of
154/// command line options.
155
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000156Generic_GCC::Generic_GCC(const HostInfo &Host, const char *Arch,
157 const char *Platform, const char *OS)
158 : ToolChain(Host, Arch, Platform, OS)
159{
Daniel Dunbar82fa7c52009-03-24 04:07:10 +0000160 std::string Path(getHost().getDriver().Dir);
161 Path += "/../libexec";
162 getProgramPaths().push_back(Path);
163
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000164 getProgramPaths().push_back(getHost().getDriver().Dir);
165}
166
Daniel Dunbar39176082009-03-20 00:20:03 +0000167Generic_GCC::~Generic_GCC() {
168 // Free tool implementations.
169 for (llvm::DenseMap<unsigned, Tool*>::iterator
170 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
171 delete it->second;
172}
173
174Tool &Generic_GCC::SelectTool(const Compilation &C,
175 const JobAction &JA) const {
176 Action::ActionClass Key;
Daniel Dunbaraf80e1f2009-03-24 18:57:02 +0000177 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000178 Key = Action::AnalyzeJobClass;
179 else
180 Key = JA.getKind();
181
182 Tool *&T = Tools[Key];
183 if (!T) {
184 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000185 case Action::InputClass:
186 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000187 assert(0 && "Invalid tool kind.");
188 case Action::PreprocessJobClass:
189 T = new tools::gcc::Preprocess(*this); break;
190 case Action::PrecompileJobClass:
191 T = new tools::gcc::Precompile(*this); break;
192 case Action::AnalyzeJobClass:
193 T = new tools::Clang(*this); break;
194 case Action::CompileJobClass:
195 T = new tools::gcc::Compile(*this); break;
196 case Action::AssembleJobClass:
197 T = new tools::gcc::Assemble(*this); break;
198 case Action::LinkJobClass:
199 T = new tools::gcc::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000200
201 // This is a bit ungeneric, but the only platform using a driver
202 // driver is Darwin.
203 case Action::LipoJobClass:
204 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000205 }
206 }
207
208 return *T;
209}
210
211bool Generic_GCC::IsMathErrnoDefault() const {
212 return true;
213}
214
215bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000216 // FIXME: Gross; we should probably have some separate target
217 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000218 return getArchName() == "x86_64";
219}
220
221const char *Generic_GCC::GetDefaultRelocationModel() const {
222 return "static";
223}
224
225const char *Generic_GCC::GetForcedPicModel() const {
226 return 0;
227}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000228
229DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args) const {
230 return new DerivedArgList(Args, true);
231}