blob: d4e8e93e2aa65fb2c5e4fe3dd024d65f5751680d [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
Daniel Dunbar82fa7c52009-03-24 04:07:10 +000077 Path = getHost().getDriver().Dir;
78 Path += "/../libexec";
79 getProgramPaths().push_back(Path);
80
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000081 getProgramPaths().push_back(getHost().getDriver().Dir);
82}
83
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000084Darwin_X86::~Darwin_X86() {
85 // Free tool implementations.
86 for (llvm::DenseMap<unsigned, Tool*>::iterator
87 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
88 delete it->second;
89}
90
91Tool &Darwin_X86::SelectTool(const Compilation &C,
92 const JobAction &JA) const {
93 Action::ActionClass Key;
94 if (ShouldUseClangCompiler(C, JA))
95 Key = Action::AnalyzeJobClass;
96 else
97 Key = JA.getKind();
98
99 Tool *&T = Tools[Key];
100 if (!T) {
101 switch (Key) {
102 case Action::InputClass:
103 case Action::BindArchClass:
104 assert(0 && "Invalid tool kind.");
105 case Action::PreprocessJobClass:
106 T = new tools::gcc::Preprocess(*this); break;
107 case Action::PrecompileJobClass:
108 T = new tools::gcc::Precompile(*this); break;
109 case Action::AnalyzeJobClass:
110 T = new tools::Clang(*this); break;
111 case Action::CompileJobClass:
112 T = new tools::gcc::Compile(*this); break;
113 case Action::AssembleJobClass:
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000114 T = new tools::darwin::Assemble(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000115 case Action::LinkJobClass:
116 T = new tools::gcc::Link(*this); break;
117 case Action::LipoJobClass:
118 T = new tools::darwin::Lipo(*this); break;
119 }
120 }
121
122 return *T;
123}
124
125ArgList *Darwin_X86::TranslateArgs(ArgList &Args) const {
126 // FIXME: Implement!
127 return &Args;
128}
129
130bool Darwin_X86::IsMathErrnoDefault() const {
131 return false;
132}
133
134bool Darwin_X86::IsUnwindTablesDefault() const {
135 // FIXME: Gross; we should probably have some separate target
136 // definition, possibly even reusing the one in clang.
137 return getArchName() == "x86_64";
138}
139
140const char *Darwin_X86::GetDefaultRelocationModel() const {
141 return "pic";
142}
143
144const char *Darwin_X86::GetForcedPicModel() const {
145 if (getArchName() == "x86_64")
146 return "pic";
147 return 0;
148}
149
Daniel Dunbar39176082009-03-20 00:20:03 +0000150/// Generic_GCC - A tool chain using the 'gcc' command to perform
151/// all subcommands; this relies on gcc translating the majority of
152/// command line options.
153
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000154Generic_GCC::Generic_GCC(const HostInfo &Host, const char *Arch,
155 const char *Platform, const char *OS)
156 : ToolChain(Host, Arch, Platform, OS)
157{
Daniel Dunbar82fa7c52009-03-24 04:07:10 +0000158 std::string Path(getHost().getDriver().Dir);
159 Path += "/../libexec";
160 getProgramPaths().push_back(Path);
161
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000162 getProgramPaths().push_back(getHost().getDriver().Dir);
163}
164
Daniel Dunbar39176082009-03-20 00:20:03 +0000165Generic_GCC::~Generic_GCC() {
166 // Free tool implementations.
167 for (llvm::DenseMap<unsigned, Tool*>::iterator
168 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
169 delete it->second;
170}
171
172Tool &Generic_GCC::SelectTool(const Compilation &C,
173 const JobAction &JA) const {
174 Action::ActionClass Key;
175 if (ShouldUseClangCompiler(C, JA))
176 Key = Action::AnalyzeJobClass;
177 else
178 Key = JA.getKind();
179
180 Tool *&T = Tools[Key];
181 if (!T) {
182 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000183 case Action::InputClass:
184 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000185 assert(0 && "Invalid tool kind.");
186 case Action::PreprocessJobClass:
187 T = new tools::gcc::Preprocess(*this); break;
188 case Action::PrecompileJobClass:
189 T = new tools::gcc::Precompile(*this); break;
190 case Action::AnalyzeJobClass:
191 T = new tools::Clang(*this); break;
192 case Action::CompileJobClass:
193 T = new tools::gcc::Compile(*this); break;
194 case Action::AssembleJobClass:
195 T = new tools::gcc::Assemble(*this); break;
196 case Action::LinkJobClass:
197 T = new tools::gcc::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000198
199 // This is a bit ungeneric, but the only platform using a driver
200 // driver is Darwin.
201 case Action::LipoJobClass:
202 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000203 }
204 }
205
206 return *T;
207}
208
209bool Generic_GCC::IsMathErrnoDefault() const {
210 return true;
211}
212
213bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000214 // FIXME: Gross; we should probably have some separate target
215 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000216 return getArchName() == "x86_64";
217}
218
219const char *Generic_GCC::GetDefaultRelocationModel() const {
220 return "static";
221}
222
223const char *Generic_GCC::GetForcedPicModel() const {
224 return 0;
225}