blob: eac72ee65a74020b7a07589c5625ffbb977675d6 [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 Dunbarc50b00d2009-03-23 16:15:50 +000012#include "clang/Driver/Driver.h"
13#include "clang/Driver/HostInfo.h"
14
15#include "llvm/ADT/StringExtras.h"
16#include "llvm/System/Path.h"
17
Daniel Dunbar39176082009-03-20 00:20:03 +000018using namespace clang::driver;
19using namespace clang::driver::toolchains;
20
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000021/// Darwin_X86 - Darwin tool chain for i386 and x86_64.
22
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000023Darwin_X86::Darwin_X86(const HostInfo &Host, const char *Arch,
24 const char *Platform, const char *OS,
25 const unsigned (&_DarwinVersion)[3],
26 const unsigned (&_GCCVersion)[3])
27 : ToolChain(Host, Arch, Platform, OS)
28{
29 DarwinVersion[0] = _DarwinVersion[0];
30 DarwinVersion[1] = _DarwinVersion[1];
31 DarwinVersion[2] = _DarwinVersion[2];
32 GCCVersion[0] = _GCCVersion[0];
33 GCCVersion[1] = _GCCVersion[1];
34 GCCVersion[2] = _GCCVersion[2];
35
36 ToolChainDir = "i686-apple-darwin";
37 ToolChainDir += llvm::utostr(DarwinVersion[0]);
38 ToolChainDir += "/";
39 ToolChainDir += llvm::utostr(GCCVersion[0]);
40 ToolChainDir += '.';
41 ToolChainDir += llvm::utostr(GCCVersion[1]);
42 ToolChainDir += '.';
43 ToolChainDir += llvm::utostr(GCCVersion[2]);
44
45 std::string Path;
46 if (getArchName() == "x86_64") {
47 Path = getHost().getDriver().Dir;
48 Path += "/../lib/gcc/";
49 Path += getToolChainDir();
50 Path += "/x86_64";
51 getFilePaths().push_back(Path);
52
53 Path = "/usr/lib/gcc/";
54 Path += getToolChainDir();
55 Path += "/x86_64";
56 getFilePaths().push_back(Path);
57 }
58
59 Path = getHost().getDriver().Dir;
60 Path += "/../lib/gcc/";
61 Path += getToolChainDir();
62 getFilePaths().push_back(Path);
63
64 Path = "/usr/lib/gcc/";
65 Path += getToolChainDir();
66 getFilePaths().push_back(Path);
67
68 Path = getHost().getDriver().Dir;
69 Path += "/../libexec/gcc/";
70 Path += getToolChainDir();
71 getProgramPaths().push_back(Path);
72
73 Path = "/usr/libexec/gcc/";
74 Path += getToolChainDir();
75 getProgramPaths().push_back(Path);
76
77 getProgramPaths().push_back(getHost().getDriver().Dir);
78}
79
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000080Darwin_X86::~Darwin_X86() {
81 // Free tool implementations.
82 for (llvm::DenseMap<unsigned, Tool*>::iterator
83 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
84 delete it->second;
85}
86
87Tool &Darwin_X86::SelectTool(const Compilation &C,
88 const JobAction &JA) const {
89 Action::ActionClass Key;
90 if (ShouldUseClangCompiler(C, JA))
91 Key = Action::AnalyzeJobClass;
92 else
93 Key = JA.getKind();
94
95 Tool *&T = Tools[Key];
96 if (!T) {
97 switch (Key) {
98 case Action::InputClass:
99 case Action::BindArchClass:
100 assert(0 && "Invalid tool kind.");
101 case Action::PreprocessJobClass:
102 T = new tools::gcc::Preprocess(*this); break;
103 case Action::PrecompileJobClass:
104 T = new tools::gcc::Precompile(*this); break;
105 case Action::AnalyzeJobClass:
106 T = new tools::Clang(*this); break;
107 case Action::CompileJobClass:
108 T = new tools::gcc::Compile(*this); break;
109 case Action::AssembleJobClass:
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000110 T = new tools::darwin::Assemble(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000111 case Action::LinkJobClass:
112 T = new tools::gcc::Link(*this); break;
113 case Action::LipoJobClass:
114 T = new tools::darwin::Lipo(*this); break;
115 }
116 }
117
118 return *T;
119}
120
121ArgList *Darwin_X86::TranslateArgs(ArgList &Args) const {
122 // FIXME: Implement!
123 return &Args;
124}
125
126bool Darwin_X86::IsMathErrnoDefault() const {
127 return false;
128}
129
130bool Darwin_X86::IsUnwindTablesDefault() const {
131 // FIXME: Gross; we should probably have some separate target
132 // definition, possibly even reusing the one in clang.
133 return getArchName() == "x86_64";
134}
135
136const char *Darwin_X86::GetDefaultRelocationModel() const {
137 return "pic";
138}
139
140const char *Darwin_X86::GetForcedPicModel() const {
141 if (getArchName() == "x86_64")
142 return "pic";
143 return 0;
144}
145
Daniel Dunbar39176082009-03-20 00:20:03 +0000146/// Generic_GCC - A tool chain using the 'gcc' command to perform
147/// all subcommands; this relies on gcc translating the majority of
148/// command line options.
149
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000150Generic_GCC::Generic_GCC(const HostInfo &Host, const char *Arch,
151 const char *Platform, const char *OS)
152 : ToolChain(Host, Arch, Platform, OS)
153{
154 getProgramPaths().push_back(getHost().getDriver().Dir);
155}
156
Daniel Dunbar39176082009-03-20 00:20:03 +0000157Generic_GCC::~Generic_GCC() {
158 // Free tool implementations.
159 for (llvm::DenseMap<unsigned, Tool*>::iterator
160 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
161 delete it->second;
162}
163
164Tool &Generic_GCC::SelectTool(const Compilation &C,
165 const JobAction &JA) const {
166 Action::ActionClass Key;
167 if (ShouldUseClangCompiler(C, JA))
168 Key = Action::AnalyzeJobClass;
169 else
170 Key = JA.getKind();
171
172 Tool *&T = Tools[Key];
173 if (!T) {
174 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000175 case Action::InputClass:
176 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000177 assert(0 && "Invalid tool kind.");
178 case Action::PreprocessJobClass:
179 T = new tools::gcc::Preprocess(*this); break;
180 case Action::PrecompileJobClass:
181 T = new tools::gcc::Precompile(*this); break;
182 case Action::AnalyzeJobClass:
183 T = new tools::Clang(*this); break;
184 case Action::CompileJobClass:
185 T = new tools::gcc::Compile(*this); break;
186 case Action::AssembleJobClass:
187 T = new tools::gcc::Assemble(*this); break;
188 case Action::LinkJobClass:
189 T = new tools::gcc::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000190
191 // This is a bit ungeneric, but the only platform using a driver
192 // driver is Darwin.
193 case Action::LipoJobClass:
194 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000195 }
196 }
197
198 return *T;
199}
200
201bool Generic_GCC::IsMathErrnoDefault() const {
202 return true;
203}
204
205bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000206 // FIXME: Gross; we should probably have some separate target
207 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000208 return getArchName() == "x86_64";
209}
210
211const char *Generic_GCC::GetDefaultRelocationModel() const {
212 return "static";
213}
214
215const char *Generic_GCC::GetForcedPicModel() const {
216 return 0;
217}