blob: 54704d48276c47a596489a7ef157fef51673bc9d [file] [log] [blame]
Daniel Dunbar63c4da92009-03-02 19:59:07 +00001//===--- Driver.cpp - Clang GCC Compatible Driver -----------------------*-===//
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
Daniel Dunbar63c4da92009-03-02 19:59:07 +000010#include "clang/Driver/Driver.h"
Daniel Dunbar63c4da92009-03-02 19:59:07 +000011
Daniel Dunbardb62cc32009-03-12 07:58:46 +000012#include "clang/Driver/Action.h"
Daniel Dunbard6f0e372009-03-04 20:49:20 +000013#include "clang/Driver/Arg.h"
14#include "clang/Driver/ArgList.h"
15#include "clang/Driver/Compilation.h"
Daniel Dunbar93468492009-03-12 08:55:43 +000016#include "clang/Driver/DriverDiagnostic.h"
Daniel Dunbard25acaa2009-03-10 23:41:59 +000017#include "clang/Driver/HostInfo.h"
Daniel Dunbar7ce6add2009-03-16 06:56:51 +000018#include "clang/Driver/Job.h"
Daniel Dunbar7dc2a042009-03-05 06:38:47 +000019#include "clang/Driver/Option.h"
Daniel Dunbard6f0e372009-03-04 20:49:20 +000020#include "clang/Driver/Options.h"
Daniel Dunbar7ce6add2009-03-16 06:56:51 +000021#include "clang/Driver/Tool.h"
22#include "clang/Driver/ToolChain.h"
Daniel Dunbardb62cc32009-03-12 07:58:46 +000023#include "clang/Driver/Types.h"
Daniel Dunbar7dc2a042009-03-05 06:38:47 +000024
Douglas Gregorb7064742009-04-27 22:23:34 +000025#include "clang/Basic/Version.h"
26
Daniel Dunbarb1873cd2009-03-13 20:33:35 +000027#include "llvm/ADT/StringSet.h"
Daniel Dunbar16e04ff2009-03-18 01:38:48 +000028#include "llvm/Support/PrettyStackTrace.h"
Daniel Dunbar7dc2a042009-03-05 06:38:47 +000029#include "llvm/Support/raw_ostream.h"
Daniel Dunbardb62cc32009-03-12 07:58:46 +000030#include "llvm/System/Path.h"
Daniel Dunbarcb84b9a2009-03-18 21:34:08 +000031#include "llvm/System/Program.h"
Daniel Dunbar494646b2009-03-13 12:19:02 +000032
Daniel Dunbar7ce6add2009-03-16 06:56:51 +000033#include "InputInfo.h"
34
Daniel Dunbar494646b2009-03-13 12:19:02 +000035#include <map>
36
Daniel Dunbard6f0e372009-03-04 20:49:20 +000037using namespace clang::driver;
Chris Lattnerc272d262009-03-26 05:56:24 +000038using namespace clang;
Daniel Dunbard6f0e372009-03-04 20:49:20 +000039
Daniel Dunbard25acaa2009-03-10 23:41:59 +000040Driver::Driver(const char *_Name, const char *_Dir,
Daniel Dunbar93468492009-03-12 08:55:43 +000041 const char *_DefaultHostTriple,
Daniel Dunbar7ce6add2009-03-16 06:56:51 +000042 const char *_DefaultImageName,
Daniel Dunbar93468492009-03-12 08:55:43 +000043 Diagnostic &_Diags)
44 : Opts(new OptTable()), Diags(_Diags),
Daniel Dunbard25acaa2009-03-10 23:41:59 +000045 Name(_Name), Dir(_Dir), DefaultHostTriple(_DefaultHostTriple),
Daniel Dunbar7ce6add2009-03-16 06:56:51 +000046 DefaultImageName(_DefaultImageName),
Daniel Dunbard25acaa2009-03-10 23:41:59 +000047 Host(0),
Daniel Dunbar07c9a1d2009-03-17 22:47:06 +000048 CCCIsCXX(false), CCCEcho(false), CCCPrintBindings(false),
Daniel Dunbar126da5e2009-04-01 23:34:41 +000049 CCCGenericGCCName("gcc"), CCCUseClang(true), CCCUseClangCXX(false),
Douglas Gregorf93696d2009-04-28 22:44:02 +000050 CCCUseClangCPP(true), CCCUsePCH(true),
Daniel Dunbar5a5ec5c2009-03-13 00:17:48 +000051 SuppressMissingInputWarning(false)
Daniel Dunbarb282ced2009-03-10 20:52:46 +000052{
Daniel Dunbar0ea85f72009-03-24 19:02:31 +000053 // Only use clang on i386 and x86_64 by default.
54 CCCClangArchs.insert("i386");
55 CCCClangArchs.insert("x86_64");
Daniel Dunbar63c4da92009-03-02 19:59:07 +000056}
57
58Driver::~Driver() {
Daniel Dunbard6f0e372009-03-04 20:49:20 +000059 delete Opts;
Daniel Dunbar2f8b37e2009-03-18 01:09:40 +000060 delete Host;
Daniel Dunbar63c4da92009-03-02 19:59:07 +000061}
62
Daniel Dunbara16e4fe2009-03-25 04:13:45 +000063InputArgList *Driver::ParseArgStrings(const char **ArgBegin,
64 const char **ArgEnd) {
Daniel Dunbar16e04ff2009-03-18 01:38:48 +000065 llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
Daniel Dunbara16e4fe2009-03-25 04:13:45 +000066 InputArgList *Args = new InputArgList(ArgBegin, ArgEnd);
Daniel Dunbar7dc2a042009-03-05 06:38:47 +000067
Daniel Dunbar85cb3592009-03-13 11:38:42 +000068 // FIXME: Handle '@' args (or at least error on them).
69
Daniel Dunbar7dc2a042009-03-05 06:38:47 +000070 unsigned Index = 0, End = ArgEnd - ArgBegin;
71 while (Index < End) {
Daniel Dunbarb043ebd2009-03-13 01:01:44 +000072 // gcc's handling of empty arguments doesn't make
73 // sense, but this is not a common use case. :)
74 //
75 // We just ignore them here (note that other things may
76 // still take them as arguments).
77 if (Args->getArgString(Index)[0] == '\0') {
78 ++Index;
79 continue;
80 }
81
Daniel Dunbar7dc2a042009-03-05 06:38:47 +000082 unsigned Prev = Index;
Daniel Dunbarfb88ce02009-03-22 23:26:43 +000083 Arg *A = getOpts().ParseOneArg(*Args, Index);
84 assert(Index > Prev && "Parser failed to consume argument.");
Daniel Dunbardb62cc32009-03-12 07:58:46 +000085
Daniel Dunbarfb88ce02009-03-22 23:26:43 +000086 // Check for missing argument error.
87 if (!A) {
88 assert(Index >= End && "Unexpected parser error.");
89 Diag(clang::diag::err_drv_missing_argument)
90 << Args->getArgString(Prev)
91 << (Index - Prev - 1);
92 break;
Daniel Dunbardb62cc32009-03-12 07:58:46 +000093 }
Daniel Dunbar7dc2a042009-03-05 06:38:47 +000094
Daniel Dunbarfb88ce02009-03-22 23:26:43 +000095 if (A->getOption().isUnsupported()) {
96 Diag(clang::diag::err_drv_unsupported_opt) << A->getAsString(*Args);
97 continue;
98 }
99 Args->append(A);
Daniel Dunbar7dc2a042009-03-05 06:38:47 +0000100 }
101
102 return Args;
103}
104
Daniel Dunbar63c4da92009-03-02 19:59:07 +0000105Compilation *Driver::BuildCompilation(int argc, const char **argv) {
Daniel Dunbar16e04ff2009-03-18 01:38:48 +0000106 llvm::PrettyStackTraceString CrashInfo("Compilation construction");
107
Daniel Dunbarcc006892009-03-13 00:51:18 +0000108 // FIXME: Handle environment options which effect driver behavior,
109 // somewhere (client?). GCC_EXEC_PREFIX, COMPILER_PATH,
110 // LIBRARY_PATH, LPATH, CC_PRINT_OPTIONS, QA_OVERRIDE_GCC3_OPTIONS.
111
112 // FIXME: What are we going to do with -V and -b?
113
Daniel Dunbarb282ced2009-03-10 20:52:46 +0000114 // FIXME: This stuff needs to go into the Compilation, not the
115 // driver.
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000116 bool CCCPrintOptions = false, CCCPrintActions = false;
Daniel Dunbar7dc2a042009-03-05 06:38:47 +0000117
Daniel Dunbarb282ced2009-03-10 20:52:46 +0000118 const char **Start = argv + 1, **End = argv + argc;
Daniel Dunbard25acaa2009-03-10 23:41:59 +0000119 const char *HostTriple = DefaultHostTriple.c_str();
Daniel Dunbarb282ced2009-03-10 20:52:46 +0000120
121 // Read -ccc args.
122 //
123 // FIXME: We need to figure out where this behavior should
124 // live. Most of it should be outside in the client; the parts that
125 // aren't should have proper options, either by introducing new ones
126 // or by overloading gcc ones like -V or -b.
127 for (; Start != End && memcmp(*Start, "-ccc-", 5) == 0; ++Start) {
128 const char *Opt = *Start + 5;
129
130 if (!strcmp(Opt, "print-options")) {
131 CCCPrintOptions = true;
132 } else if (!strcmp(Opt, "print-phases")) {
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000133 CCCPrintActions = true;
Daniel Dunbar07c9a1d2009-03-17 22:47:06 +0000134 } else if (!strcmp(Opt, "print-bindings")) {
135 CCCPrintBindings = true;
Daniel Dunbarb282ced2009-03-10 20:52:46 +0000136 } else if (!strcmp(Opt, "cxx")) {
137 CCCIsCXX = true;
138 } else if (!strcmp(Opt, "echo")) {
139 CCCEcho = true;
140
Daniel Dunbar126da5e2009-04-01 23:34:41 +0000141 } else if (!strcmp(Opt, "gcc-name")) {
142 assert(Start+1 < End && "FIXME: -ccc- argument handling.");
143 CCCGenericGCCName = *++Start;
144
Daniel Dunbar0ea85f72009-03-24 19:02:31 +0000145 } else if (!strcmp(Opt, "clang-cxx")) {
146 CCCUseClangCXX = true;
Douglas Gregor95734502009-04-18 00:34:01 +0000147 } else if (!strcmp(Opt, "pch-is-pch")) {
148 CCCUsePCH = true;
149 } else if (!strcmp(Opt, "pch-is-pth")) {
150 CCCUsePCH = false;
Daniel Dunbarb282ced2009-03-10 20:52:46 +0000151 } else if (!strcmp(Opt, "no-clang")) {
Daniel Dunbar0ea85f72009-03-24 19:02:31 +0000152 CCCUseClang = false;
Daniel Dunbarb282ced2009-03-10 20:52:46 +0000153 } else if (!strcmp(Opt, "no-clang-cpp")) {
Daniel Dunbar0ea85f72009-03-24 19:02:31 +0000154 CCCUseClangCPP = false;
Daniel Dunbarb282ced2009-03-10 20:52:46 +0000155 } else if (!strcmp(Opt, "clang-archs")) {
156 assert(Start+1 < End && "FIXME: -ccc- argument handling.");
157 const char *Cur = *++Start;
158
Daniel Dunbar0ea85f72009-03-24 19:02:31 +0000159 CCCClangArchs.clear();
Daniel Dunbarb282ced2009-03-10 20:52:46 +0000160 for (;;) {
161 const char *Next = strchr(Cur, ',');
162
163 if (Next) {
Daniel Dunbar0ea85f72009-03-24 19:02:31 +0000164 if (Cur != Next)
165 CCCClangArchs.insert(std::string(Cur, Next));
Daniel Dunbarb282ced2009-03-10 20:52:46 +0000166 Cur = Next + 1;
167 } else {
Daniel Dunbar0ea85f72009-03-24 19:02:31 +0000168 if (*Cur != '\0')
169 CCCClangArchs.insert(std::string(Cur));
Daniel Dunbarb282ced2009-03-10 20:52:46 +0000170 break;
171 }
172 }
173
Daniel Dunbard25acaa2009-03-10 23:41:59 +0000174 } else if (!strcmp(Opt, "host-triple")) {
Daniel Dunbarb282ced2009-03-10 20:52:46 +0000175 assert(Start+1 < End && "FIXME: -ccc- argument handling.");
Daniel Dunbard25acaa2009-03-10 23:41:59 +0000176 HostTriple = *++Start;
Daniel Dunbarb282ced2009-03-10 20:52:46 +0000177
178 } else {
179 // FIXME: Error handling.
180 llvm::errs() << "invalid option: " << *Start << "\n";
181 exit(1);
182 }
183 }
Daniel Dunbard25acaa2009-03-10 23:41:59 +0000184
Daniel Dunbara16e4fe2009-03-25 04:13:45 +0000185 InputArgList *Args = ParseArgStrings(Start, End);
Daniel Dunbarb282ced2009-03-10 20:52:46 +0000186
Daniel Dunbar08966ca2009-03-17 20:45:45 +0000187 Host = GetHostInfo(HostTriple);
Daniel Dunbarcc006892009-03-13 00:51:18 +0000188
Daniel Dunbar9d625e12009-03-16 06:42:30 +0000189 // The compilation takes ownership of Args.
Daniel Dunbar31a76e32009-03-18 22:16:03 +0000190 Compilation *C = new Compilation(*this, *Host->getToolChain(*Args), Args);
Daniel Dunbar73f7b8c2009-03-18 02:55:38 +0000191
192 // FIXME: This behavior shouldn't be here.
193 if (CCCPrintOptions) {
194 PrintOptions(C->getArgs());
195 return C;
196 }
197
198 if (!HandleImmediateArgs(*C))
199 return C;
200
201 // Construct the list of abstract actions to perform for this
202 // compilation. We avoid passing a Compilation here simply to
203 // enforce the abstraction that pipelining is not host or toolchain
204 // dependent (other than the driver driver test).
205 if (Host->useDriverDriver())
206 BuildUniversalActions(C->getArgs(), C->getActions());
207 else
208 BuildActions(C->getArgs(), C->getActions());
209
210 if (CCCPrintActions) {
Daniel Dunbar2b856ce2009-03-18 03:13:20 +0000211 PrintActions(*C);
Daniel Dunbar73f7b8c2009-03-18 02:55:38 +0000212 return C;
213 }
214
215 BuildJobs(*C);
Daniel Dunbarc413f822009-03-15 01:38:15 +0000216
217 return C;
Daniel Dunbarb282ced2009-03-10 20:52:46 +0000218}
219
Daniel Dunbara790d372009-03-12 18:24:49 +0000220void Driver::PrintOptions(const ArgList &Args) const {
Daniel Dunbar7dc2a042009-03-05 06:38:47 +0000221 unsigned i = 0;
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000222 for (ArgList::const_iterator it = Args.begin(), ie = Args.end();
Daniel Dunbar7dc2a042009-03-05 06:38:47 +0000223 it != ie; ++it, ++i) {
224 Arg *A = *it;
225 llvm::errs() << "Option " << i << " - "
226 << "Name: \"" << A->getOption().getName() << "\", "
227 << "Values: {";
228 for (unsigned j = 0; j < A->getNumValues(); ++j) {
229 if (j)
230 llvm::errs() << ", ";
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000231 llvm::errs() << '"' << A->getValue(Args, j) << '"';
Daniel Dunbar7dc2a042009-03-05 06:38:47 +0000232 }
233 llvm::errs() << "}\n";
Daniel Dunbar7dc2a042009-03-05 06:38:47 +0000234 }
Daniel Dunbar63c4da92009-03-02 19:59:07 +0000235}
Daniel Dunbard25acaa2009-03-10 23:41:59 +0000236
Daniel Dunbare627b682009-03-31 21:38:17 +0000237static std::string getOptionHelpName(const OptTable &Opts, options::ID Id) {
238 std::string Name = Opts.getOptionName(Id);
239
240 // Add metavar, if used.
241 switch (Opts.getOptionKind(Id)) {
242 case Option::GroupClass: case Option::InputClass: case Option::UnknownClass:
243 assert(0 && "Invalid option with help text.");
244
245 case Option::MultiArgClass: case Option::JoinedAndSeparateClass:
246 assert(0 && "Cannot print metavar for this kind of option.");
247
248 case Option::FlagClass:
249 break;
250
251 case Option::SeparateClass: case Option::JoinedOrSeparateClass:
252 Name += ' ';
253 // FALLTHROUGH
254 case Option::JoinedClass: case Option::CommaJoinedClass:
255 Name += Opts.getOptionMetaVar(Id);
256 break;
257 }
258
259 return Name;
260}
261
Daniel Dunbara5f09bc2009-04-15 16:34:29 +0000262void Driver::PrintHelp(bool ShowHidden) const {
Daniel Dunbare627b682009-03-31 21:38:17 +0000263 llvm::raw_ostream &OS = llvm::outs();
264
265 OS << "OVERVIEW: clang \"gcc-compatible\" driver\n";
266 OS << '\n';
267 OS << "USAGE: " << Name << " [options] <input files>\n";
268 OS << '\n';
269 OS << "OPTIONS:\n";
270
271 // Render help text into (option, help) pairs.
272 std::vector< std::pair<std::string, const char*> > OptionHelp;
273
274 for (unsigned i = options::OPT_INPUT, e = options::LastOption; i != e; ++i) {
275 options::ID Id = (options::ID) i;
276 if (const char *Text = getOpts().getOptionHelpText(Id))
277 OptionHelp.push_back(std::make_pair(getOptionHelpName(getOpts(), Id),
278 Text));
279 }
280
Daniel Dunbara5f09bc2009-04-15 16:34:29 +0000281 if (ShowHidden) {
282 OptionHelp.push_back(std::make_pair("\nDRIVER OPTIONS:",""));
283 OptionHelp.push_back(std::make_pair("-ccc-cxx",
284 "Act as a C++ driver"));
285 OptionHelp.push_back(std::make_pair("-ccc-gcc-name",
286 "Name for native GCC compiler"));
287 OptionHelp.push_back(std::make_pair("-ccc-clang-cxx",
288 "Use the clang compiler for C++"));
289 OptionHelp.push_back(std::make_pair("-ccc-no-clang",
290 "Never use the clang compiler"));
291 OptionHelp.push_back(std::make_pair("-ccc-no-clang-cpp",
292 "Never use the clang preprocessor"));
293 OptionHelp.push_back(std::make_pair("-ccc-clang-archs",
294 "Comma separate list of architectures "
295 "to use the clang compiler for"));
Douglas Gregor95734502009-04-18 00:34:01 +0000296 OptionHelp.push_back(std::make_pair("-ccc-pch-is-pch",
297 "Use lazy PCH for precompiled headers"));
298 OptionHelp.push_back(std::make_pair("-ccc-pch-is-pth",
299 "Use pretokenized headers for precompiled headers"));
Daniel Dunbara5f09bc2009-04-15 16:34:29 +0000300
301 OptionHelp.push_back(std::make_pair("\nDEBUG/DEVELOPMENT OPTIONS:",""));
302 OptionHelp.push_back(std::make_pair("-ccc-host-triple",
303 "Simulate running on the given target"));
304 OptionHelp.push_back(std::make_pair("-ccc-print-options",
305 "Dump parsed command line arguments"));
306 OptionHelp.push_back(std::make_pair("-ccc-print-phases",
307 "Dump list of actions to perform"));
308 OptionHelp.push_back(std::make_pair("-ccc-print-bindings",
309 "Show bindings of tools to actions"));
310 OptionHelp.push_back(std::make_pair("CCC_ADD_ARGS",
311 "(ENVIRONMENT VARIABLE) Comma separated list of "
312 "arguments to prepend to the command line"));
313 }
314
Daniel Dunbare627b682009-03-31 21:38:17 +0000315 // Find the maximum option length.
316 unsigned OptionFieldWidth = 0;
317 for (unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
Daniel Dunbara5f09bc2009-04-15 16:34:29 +0000318 // Skip titles.
319 if (!OptionHelp[i].second)
320 continue;
321
Daniel Dunbare627b682009-03-31 21:38:17 +0000322 // Limit the amount of padding we are willing to give up for
323 // alignment.
324 unsigned Length = OptionHelp[i].first.size();
325 if (Length <= 23)
326 OptionFieldWidth = std::max(OptionFieldWidth, Length);
327 }
328
329 for (unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
330 const std::string &Option = OptionHelp[i].first;
331 OS << " " << Option;
332 for (int j = Option.length(), e = OptionFieldWidth; j < e; ++j)
333 OS << ' ';
334 OS << ' ' << OptionHelp[i].second << '\n';
335 }
336
337 OS.flush();
338}
339
Daniel Dunbar0ded7de2009-03-26 16:09:13 +0000340void Driver::PrintVersion(const Compilation &C) const {
Mike Stump74d94472009-03-18 14:00:02 +0000341 static char buf[] = "$URL$";
342 char *zap = strstr(buf, "/lib/Driver");
343 if (zap)
344 *zap = 0;
345 zap = strstr(buf, "/clang/tools/clang");
346 if (zap)
347 *zap = 0;
Mike Stumpbc927292009-03-18 15:19:35 +0000348 const char *vers = buf+6;
Mike Stump3fc58f02009-03-18 18:45:55 +0000349 // FIXME: Add cmake support and remove #ifdef
350#ifdef SVN_REVISION
351 const char *revision = SVN_REVISION;
352#else
353 const char *revision = "";
354#endif
Daniel Dunbarcc006892009-03-13 00:51:18 +0000355 // FIXME: The following handlers should use a callback mechanism, we
356 // don't know what the client would like to do.
Daniel Dunbar9a553c42009-04-04 05:17:38 +0000357
Douglas Gregorb7064742009-04-27 22:23:34 +0000358 llvm::errs() << "clang version " CLANG_VERSION_STRING " ("
359 << vers << " " << revision << ")" << "\n";
Daniel Dunbar0ded7de2009-03-26 16:09:13 +0000360
361 const ToolChain &TC = C.getDefaultToolChain();
Daniel Dunbar049b7242009-03-30 06:36:42 +0000362 llvm::errs() << "Target: " << TC.getTripleString() << '\n';
Daniel Dunbarcc006892009-03-13 00:51:18 +0000363}
364
Daniel Dunbar73f7b8c2009-03-18 02:55:38 +0000365bool Driver::HandleImmediateArgs(const Compilation &C) {
Daniel Dunbarcc006892009-03-13 00:51:18 +0000366 // The order these options are handled in in gcc is all over the
367 // place, but we don't expect inconsistencies w.r.t. that to matter
368 // in practice.
Daniel Dunbare627b682009-03-31 21:38:17 +0000369
Daniel Dunbar9a553c42009-04-04 05:17:38 +0000370 if (C.getArgs().hasArg(options::OPT_dumpversion)) {
Douglas Gregorb7064742009-04-27 22:23:34 +0000371 llvm::outs() << CLANG_VERSION_STRING "\n";
Daniel Dunbar9a553c42009-04-04 05:17:38 +0000372 return false;
373 }
374
Daniel Dunbara5f09bc2009-04-15 16:34:29 +0000375 if (C.getArgs().hasArg(options::OPT__help) ||
376 C.getArgs().hasArg(options::OPT__help_hidden)) {
377 PrintHelp(C.getArgs().hasArg(options::OPT__help_hidden));
Daniel Dunbare627b682009-03-31 21:38:17 +0000378 return false;
379 }
380
Daniel Dunbar3b7c84c2009-04-02 15:05:41 +0000381 if (C.getArgs().hasArg(options::OPT__version)) {
382 PrintVersion(C);
383 return false;
384 }
385
Daniel Dunbar73f7b8c2009-03-18 02:55:38 +0000386 if (C.getArgs().hasArg(options::OPT_v) ||
387 C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
Daniel Dunbar0ded7de2009-03-26 16:09:13 +0000388 PrintVersion(C);
Daniel Dunbarcc006892009-03-13 00:51:18 +0000389 SuppressMissingInputWarning = true;
390 }
391
Daniel Dunbar73f7b8c2009-03-18 02:55:38 +0000392 const ToolChain &TC = C.getDefaultToolChain();
Daniel Dunbar91b9e202009-03-20 04:37:21 +0000393 if (C.getArgs().hasArg(options::OPT_print_search_dirs)) {
394 llvm::outs() << "programs: =";
395 for (ToolChain::path_list::const_iterator it = TC.getProgramPaths().begin(),
396 ie = TC.getProgramPaths().end(); it != ie; ++it) {
397 if (it != TC.getProgramPaths().begin())
398 llvm::outs() << ':';
399 llvm::outs() << *it;
400 }
401 llvm::outs() << "\n";
402 llvm::outs() << "libraries: =";
403 for (ToolChain::path_list::const_iterator it = TC.getFilePaths().begin(),
404 ie = TC.getFilePaths().end(); it != ie; ++it) {
405 if (it != TC.getFilePaths().begin())
406 llvm::outs() << ':';
407 llvm::outs() << *it;
408 }
409 llvm::outs() << "\n";
Daniel Dunbare627b682009-03-31 21:38:17 +0000410 return false;
Daniel Dunbar91b9e202009-03-20 04:37:21 +0000411 }
412
Daniel Dunbarcc006892009-03-13 00:51:18 +0000413 // FIXME: The following handlers should use a callback mechanism, we
414 // don't know what the client would like to do.
Daniel Dunbar73f7b8c2009-03-18 02:55:38 +0000415 if (Arg *A = C.getArgs().getLastArg(options::OPT_print_file_name_EQ)) {
416 llvm::outs() << GetFilePath(A->getValue(C.getArgs()), TC).toString()
417 << "\n";
Daniel Dunbarcc006892009-03-13 00:51:18 +0000418 return false;
419 }
420
Daniel Dunbar73f7b8c2009-03-18 02:55:38 +0000421 if (Arg *A = C.getArgs().getLastArg(options::OPT_print_prog_name_EQ)) {
422 llvm::outs() << GetProgramPath(A->getValue(C.getArgs()), TC).toString()
423 << "\n";
Daniel Dunbarcc006892009-03-13 00:51:18 +0000424 return false;
425 }
426
Daniel Dunbar73f7b8c2009-03-18 02:55:38 +0000427 if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
Daniel Dunbaref68dd32009-03-27 14:26:33 +0000428 llvm::outs() << GetFilePath("libgcc.a", TC).toString() << "\n";
Daniel Dunbarcc006892009-03-13 00:51:18 +0000429 return false;
430 }
431
Daniel Dunbar329aa992009-06-16 23:25:22 +0000432 if (C.getArgs().hasArg(options::OPT_print_multi_lib)) {
433 // FIXME: We need tool chain support for this.
434 llvm::outs() << ".;\n";
435
436 switch (C.getDefaultToolChain().getTriple().getArch()) {
437 default:
438 break;
439
440 case llvm::Triple::x86_64:
441 llvm::outs() << "x86_64;@m64" << "\n";
442 break;
443
444 case llvm::Triple::ppc64:
445 llvm::outs() << "ppc64;@m64" << "\n";
446 break;
447 }
448 return false;
449 }
450
451 // FIXME: What is the difference between print-multi-directory and
452 // print-multi-os-directory?
453 if (C.getArgs().hasArg(options::OPT_print_multi_directory) ||
454 C.getArgs().hasArg(options::OPT_print_multi_os_directory)) {
455 switch (C.getDefaultToolChain().getTriple().getArch()) {
456 default:
457 case llvm::Triple::x86:
458 case llvm::Triple::ppc:
459 llvm::outs() << "." << "\n";
460 break;
461
462 case llvm::Triple::x86_64:
463 llvm::outs() << "x86_64" << "\n";
464 break;
465
466 case llvm::Triple::ppc64:
467 llvm::outs() << "ppc64" << "\n";
468 break;
469 }
470 return false;
471 }
472
Daniel Dunbarcc006892009-03-13 00:51:18 +0000473 return true;
474}
475
Daniel Dunbar2b856ce2009-03-18 03:13:20 +0000476static unsigned PrintActions1(const Compilation &C,
Daniel Dunbar494646b2009-03-13 12:19:02 +0000477 Action *A,
478 std::map<Action*, unsigned> &Ids) {
479 if (Ids.count(A))
480 return Ids[A];
481
482 std::string str;
483 llvm::raw_string_ostream os(str);
484
485 os << Action::getClassName(A->getKind()) << ", ";
486 if (InputAction *IA = dyn_cast<InputAction>(A)) {
Daniel Dunbar2b856ce2009-03-18 03:13:20 +0000487 os << "\"" << IA->getInputArg().getValue(C.getArgs()) << "\"";
Daniel Dunbar494646b2009-03-13 12:19:02 +0000488 } else if (BindArchAction *BIA = dyn_cast<BindArchAction>(A)) {
Daniel Dunbar2b856ce2009-03-18 03:13:20 +0000489 os << '"' << (BIA->getArchName() ? BIA->getArchName() :
490 C.getDefaultToolChain().getArchName()) << '"'
491 << ", {" << PrintActions1(C, *BIA->begin(), Ids) << "}";
Daniel Dunbar494646b2009-03-13 12:19:02 +0000492 } else {
493 os << "{";
494 for (Action::iterator it = A->begin(), ie = A->end(); it != ie;) {
Daniel Dunbar2b856ce2009-03-18 03:13:20 +0000495 os << PrintActions1(C, *it, Ids);
Daniel Dunbar494646b2009-03-13 12:19:02 +0000496 ++it;
497 if (it != ie)
498 os << ", ";
499 }
500 os << "}";
501 }
502
503 unsigned Id = Ids.size();
504 Ids[A] = Id;
Daniel Dunbar9dc28b82009-03-13 17:20:20 +0000505 llvm::errs() << Id << ": " << os.str() << ", "
Daniel Dunbar494646b2009-03-13 12:19:02 +0000506 << types::getTypeName(A->getType()) << "\n";
507
508 return Id;
509}
510
Daniel Dunbar2b856ce2009-03-18 03:13:20 +0000511void Driver::PrintActions(const Compilation &C) const {
Daniel Dunbar494646b2009-03-13 12:19:02 +0000512 std::map<Action*, unsigned> Ids;
Daniel Dunbar2b856ce2009-03-18 03:13:20 +0000513 for (ActionList::const_iterator it = C.getActions().begin(),
514 ie = C.getActions().end(); it != ie; ++it)
515 PrintActions1(C, *it, Ids);
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000516}
517
Daniel Dunbar73f7b8c2009-03-18 02:55:38 +0000518void Driver::BuildUniversalActions(const ArgList &Args,
519 ActionList &Actions) const {
Daniel Dunbar16e04ff2009-03-18 01:38:48 +0000520 llvm::PrettyStackTraceString CrashInfo("Building actions for universal build");
Daniel Dunbarb1873cd2009-03-13 20:33:35 +0000521 // Collect the list of architectures. Duplicates are allowed, but
522 // should only be handled once (in the order seen).
523 llvm::StringSet<> ArchNames;
524 llvm::SmallVector<const char *, 4> Archs;
Daniel Dunbarfba157b2009-03-12 18:40:18 +0000525 for (ArgList::const_iterator it = Args.begin(), ie = Args.end();
526 it != ie; ++it) {
527 Arg *A = *it;
528
529 if (A->getOption().getId() == options::OPT_arch) {
Daniel Dunbarb1873cd2009-03-13 20:33:35 +0000530 const char *Name = A->getValue(Args);
531
Daniel Dunbarfba157b2009-03-12 18:40:18 +0000532 // FIXME: We need to handle canonicalization of the specified
533 // arch?
534
Daniel Dunbara345a442009-03-19 07:55:12 +0000535 A->claim();
Daniel Dunbarb1873cd2009-03-13 20:33:35 +0000536 if (ArchNames.insert(Name))
537 Archs.push_back(Name);
Daniel Dunbarfba157b2009-03-12 18:40:18 +0000538 }
539 }
540
Daniel Dunbar2b856ce2009-03-18 03:13:20 +0000541 // When there is no explicit arch for this platform, make sure we
542 // still bind the architecture (to the default) so that -Xarch_ is
543 // handled correctly.
544 if (!Archs.size())
545 Archs.push_back(0);
Daniel Dunbarfba157b2009-03-12 18:40:18 +0000546
547 // FIXME: We killed off some others but these aren't yet detected in
548 // a functional manner. If we added information to jobs about which
549 // "auxiliary" files they wrote then we could detect the conflict
550 // these cause downstream.
551 if (Archs.size() > 1) {
552 // No recovery needed, the point of this is just to prevent
553 // overwriting the same files.
Daniel Dunbarfba157b2009-03-12 18:40:18 +0000554 if (const Arg *A = Args.getLastArg(options::OPT_save_temps))
555 Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs)
Daniel Dunbar73225932009-03-20 06:14:23 +0000556 << A->getAsString(Args);
Daniel Dunbarfba157b2009-03-12 18:40:18 +0000557 }
558
559 ActionList SingleActions;
560 BuildActions(Args, SingleActions);
561
562 // Add in arch binding and lipo (if necessary) for every top level
563 // action.
564 for (unsigned i = 0, e = SingleActions.size(); i != e; ++i) {
565 Action *Act = SingleActions[i];
566
567 // Make sure we can lipo this kind of output. If not (and it is an
568 // actual output) then we disallow, since we can't create an
569 // output file with the right name without overwriting it. We
570 // could remove this oddity by just changing the output names to
571 // include the arch, which would also fix
572 // -save-temps. Compatibility wins for now.
573
Daniel Dunbardd863aa2009-03-13 17:46:02 +0000574 if (Archs.size() > 1 && !types::canLipoType(Act->getType()))
Daniel Dunbarfba157b2009-03-12 18:40:18 +0000575 Diag(clang::diag::err_drv_invalid_output_with_multiple_archs)
576 << types::getTypeName(Act->getType());
577
578 ActionList Inputs;
Daniel Dunbara345a442009-03-19 07:55:12 +0000579 for (unsigned i = 0, e = Archs.size(); i != e; ++i)
Daniel Dunbarb1873cd2009-03-13 20:33:35 +0000580 Inputs.push_back(new BindArchAction(Act, Archs[i]));
Daniel Dunbarfba157b2009-03-12 18:40:18 +0000581
582 // Lipo if necessary, We do it this way because we need to set the
583 // arch flag so that -Xarch_ gets overwritten.
584 if (Inputs.size() == 1 || Act->getType() == types::TY_Nothing)
585 Actions.append(Inputs.begin(), Inputs.end());
586 else
587 Actions.push_back(new LipoJobAction(Inputs, Act->getType()));
588 }
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000589}
590
Daniel Dunbar73f7b8c2009-03-18 02:55:38 +0000591void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const {
Daniel Dunbar16e04ff2009-03-18 01:38:48 +0000592 llvm::PrettyStackTraceString CrashInfo("Building compilation actions");
Daniel Dunbar207a56d2009-03-12 23:55:14 +0000593 // Start by constructing the list of inputs and their types.
594
Daniel Dunbar5cb75d62009-03-13 17:57:10 +0000595 // Track the current user specified (-x) input. We also explicitly
596 // track the argument used to set the type; we only want to claim
597 // the type when we actually use it, so we warn about unused -x
598 // arguments.
599 types::ID InputType = types::TY_Nothing;
600 Arg *InputTypeArg = 0;
601
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000602 llvm::SmallVector<std::pair<types::ID, const Arg*>, 16> Inputs;
603 for (ArgList::const_iterator it = Args.begin(), ie = Args.end();
604 it != ie; ++it) {
605 Arg *A = *it;
606
607 if (isa<InputOption>(A->getOption())) {
608 const char *Value = A->getValue(Args);
609 types::ID Ty = types::TY_INVALID;
610
611 // Infer the input type if necessary.
Daniel Dunbar5cb75d62009-03-13 17:57:10 +0000612 if (InputType == types::TY_Nothing) {
613 // If there was an explicit arg for this, claim it.
614 if (InputTypeArg)
615 InputTypeArg->claim();
616
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000617 // stdin must be handled specially.
618 if (memcmp(Value, "-", 2) == 0) {
619 // If running with -E, treat as a C input (this changes the
620 // builtin macros, for example). This may be overridden by
621 // -ObjC below.
622 //
623 // Otherwise emit an error but still use a valid type to
624 // avoid spurious errors (e.g., no inputs).
Daniel Dunbare9c70fa2009-03-15 00:48:16 +0000625 if (!Args.hasArg(options::OPT_E, false))
Daniel Dunbard724e332009-03-12 09:13:48 +0000626 Diag(clang::diag::err_drv_unknown_stdin_type);
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000627 Ty = types::TY_C;
628 } else {
629 // Otherwise lookup by extension, and fallback to ObjectType
Daniel Dunbar7b6dfbd2009-03-20 23:39:23 +0000630 // if not found. We use a host hook here because Darwin at
631 // least has its own idea of what .s is.
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000632 if (const char *Ext = strrchr(Value, '.'))
Daniel Dunbar7b6dfbd2009-03-20 23:39:23 +0000633 Ty = Host->lookupTypeForExtension(Ext + 1);
634
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000635 if (Ty == types::TY_INVALID)
636 Ty = types::TY_Object;
637 }
638
Daniel Dunbar84266db2009-05-18 21:47:54 +0000639 // -ObjC and -ObjC++ override the default language, but only for "source
640 // files". We just treat everything that isn't a linker input as a
641 // source file.
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000642 //
Daniel Dunbar84266db2009-05-18 21:47:54 +0000643 // FIXME: Clean this up if we move the phase sequence into the type.
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000644 if (Ty != types::TY_Object) {
645 if (Args.hasArg(options::OPT_ObjC))
646 Ty = types::TY_ObjC;
647 else if (Args.hasArg(options::OPT_ObjCXX))
648 Ty = types::TY_ObjCXX;
649 }
650 } else {
651 assert(InputTypeArg && "InputType set w/o InputTypeArg");
652 InputTypeArg->claim();
653 Ty = InputType;
654 }
655
656 // Check that the file exists. It isn't clear this is worth
657 // doing, since the tool presumably does this anyway, and this
658 // just adds an extra stat to the equation, but this is gcc
659 // compatible.
660 if (memcmp(Value, "-", 2) != 0 && !llvm::sys::Path(Value).exists())
Daniel Dunbard724e332009-03-12 09:13:48 +0000661 Diag(clang::diag::err_drv_no_such_file) << A->getValue(Args);
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000662 else
663 Inputs.push_back(std::make_pair(Ty, A));
664
665 } else if (A->getOption().isLinkerInput()) {
666 // Just treat as object type, we could make a special type for
667 // this if necessary.
668 Inputs.push_back(std::make_pair(types::TY_Object, A));
669
670 } else if (A->getOption().getId() == options::OPT_x) {
671 InputTypeArg = A;
672 InputType = types::lookupTypeForTypeSpecifier(A->getValue(Args));
673
674 // Follow gcc behavior and treat as linker input for invalid -x
675 // options. Its not clear why we shouldn't just revert to
676 // unknown; but this isn't very important, we might as well be
677 // bug comatible.
678 if (!InputType) {
Daniel Dunbard724e332009-03-12 09:13:48 +0000679 Diag(clang::diag::err_drv_unknown_language) << A->getValue(Args);
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000680 InputType = types::TY_Object;
681 }
682 }
683 }
684
Daniel Dunbar5a5ec5c2009-03-13 00:17:48 +0000685 if (!SuppressMissingInputWarning && Inputs.empty()) {
Daniel Dunbar207a56d2009-03-12 23:55:14 +0000686 Diag(clang::diag::err_drv_no_input_files);
687 return;
688 }
689
690 // Determine which compilation mode we are in. We look for options
691 // which affect the phase, starting with the earliest phases, and
692 // record which option we used to determine the final phase.
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000693 Arg *FinalPhaseArg = 0;
694 phases::ID FinalPhase;
Daniel Dunbar207a56d2009-03-12 23:55:14 +0000695
696 // -{E,M,MM} only run the preprocessor.
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000697 if ((FinalPhaseArg = Args.getLastArg(options::OPT_E)) ||
698 (FinalPhaseArg = Args.getLastArg(options::OPT_M)) ||
699 (FinalPhaseArg = Args.getLastArg(options::OPT_MM))) {
700 FinalPhase = phases::Preprocess;
Daniel Dunbar207a56d2009-03-12 23:55:14 +0000701
Daniel Dunbare9c70fa2009-03-15 00:48:16 +0000702 // -{fsyntax-only,-analyze,emit-llvm,S} only run up to the compiler.
703 } else if ((FinalPhaseArg = Args.getLastArg(options::OPT_fsyntax_only)) ||
Daniel Dunbar6e3de3d2009-05-06 02:12:32 +0000704 (FinalPhaseArg = Args.getLastArg(options::OPT__analyze,
705 options::OPT__analyze_auto)) ||
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000706 (FinalPhaseArg = Args.getLastArg(options::OPT_S))) {
707 FinalPhase = phases::Compile;
Daniel Dunbar207a56d2009-03-12 23:55:14 +0000708
709 // -c only runs up to the assembler.
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000710 } else if ((FinalPhaseArg = Args.getLastArg(options::OPT_c))) {
711 FinalPhase = phases::Assemble;
Daniel Dunbar207a56d2009-03-12 23:55:14 +0000712
713 // Otherwise do everything.
714 } else
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000715 FinalPhase = phases::Link;
Daniel Dunbar207a56d2009-03-12 23:55:14 +0000716
Daniel Dunbar207a56d2009-03-12 23:55:14 +0000717 // Reject -Z* at the top level, these options should never have been
718 // exposed by gcc.
Daniel Dunbar55e34e32009-03-26 16:12:09 +0000719 if (Arg *A = Args.getLastArg(options::OPT_Z_Joined))
Daniel Dunbar73225932009-03-20 06:14:23 +0000720 Diag(clang::diag::err_drv_use_of_Z_option) << A->getAsString(Args);
Daniel Dunbar207a56d2009-03-12 23:55:14 +0000721
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000722 // Construct the actions to perform.
723 ActionList LinkerInputs;
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000724 for (unsigned i = 0, e = Inputs.size(); i != e; ++i) {
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000725 types::ID InputType = Inputs[i].first;
726 const Arg *InputArg = Inputs[i].second;
727
728 unsigned NumSteps = types::getNumCompilationPhases(InputType);
729 assert(NumSteps && "Invalid number of steps!");
730
731 // If the first step comes after the final phase we are doing as
732 // part of this compilation, warn the user about it.
733 phases::ID InitialPhase = types::getCompilationPhase(InputType, 0);
734 if (InitialPhase > FinalPhase) {
Daniel Dunbar923e7032009-03-19 07:57:08 +0000735 // Claim here to avoid the more general unused warning.
736 InputArg->claim();
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000737 Diag(clang::diag::warn_drv_input_file_unused)
Daniel Dunbar73225932009-03-20 06:14:23 +0000738 << InputArg->getAsString(Args)
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000739 << getPhaseName(InitialPhase)
740 << FinalPhaseArg->getOption().getName();
741 continue;
742 }
743
744 // Build the pipeline for this file.
745 Action *Current = new InputAction(*InputArg, InputType);
746 for (unsigned i = 0; i != NumSteps; ++i) {
747 phases::ID Phase = types::getCompilationPhase(InputType, i);
748
749 // We are done if this step is past what the user requested.
750 if (Phase > FinalPhase)
751 break;
752
753 // Queue linker inputs.
754 if (Phase == phases::Link) {
755 assert(i + 1 == NumSteps && "linking must be final compilation step.");
756 LinkerInputs.push_back(Current);
757 Current = 0;
758 break;
759 }
760
Daniel Dunbardec14452009-03-24 20:17:30 +0000761 // Some types skip the assembler phase (e.g., llvm-bc), but we
762 // can't encode this in the steps because the intermediate type
763 // depends on arguments. Just special case here.
764 if (Phase == phases::Assemble && Current->getType() != types::TY_PP_Asm)
765 continue;
766
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000767 // Otherwise construct the appropriate action.
768 Current = ConstructPhaseAction(Args, Phase, Current);
769 if (Current->getType() == types::TY_Nothing)
770 break;
771 }
772
773 // If we ended with something, add to the output list.
774 if (Current)
775 Actions.push_back(Current);
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000776 }
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000777
778 // Add a link action if necessary.
779 if (!LinkerInputs.empty())
780 Actions.push_back(new LinkJobAction(LinkerInputs, types::TY_Image));
781}
782
783Action *Driver::ConstructPhaseAction(const ArgList &Args, phases::ID Phase,
784 Action *Input) const {
Daniel Dunbar16e04ff2009-03-18 01:38:48 +0000785 llvm::PrettyStackTraceString CrashInfo("Constructing phase actions");
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000786 // Build the appropriate action.
787 switch (Phase) {
788 case phases::Link: assert(0 && "link action invalid here.");
789 case phases::Preprocess: {
Daniel Dunbar049b7242009-03-30 06:36:42 +0000790 types::ID OutputTy;
791 // -{M, MM} alter the output type.
792 if (Args.hasArg(options::OPT_M) || Args.hasArg(options::OPT_MM)) {
793 OutputTy = types::TY_Dependencies;
794 } else {
795 OutputTy = types::getPreprocessedType(Input->getType());
796 assert(OutputTy != types::TY_INVALID &&
797 "Cannot preprocess this input type!");
798 }
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000799 return new PreprocessJobAction(Input, OutputTy);
800 }
801 case phases::Precompile:
802 return new PrecompileJobAction(Input, types::TY_PCH);
803 case phases::Compile: {
804 if (Args.hasArg(options::OPT_fsyntax_only)) {
805 return new CompileJobAction(Input, types::TY_Nothing);
Daniel Dunbar6e3de3d2009-05-06 02:12:32 +0000806 } else if (Args.hasArg(options::OPT__analyze, options::OPT__analyze_auto)) {
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000807 return new AnalyzeJobAction(Input, types::TY_Plist);
Daniel Dunbardec14452009-03-24 20:17:30 +0000808 } else if (Args.hasArg(options::OPT_emit_llvm) ||
809 Args.hasArg(options::OPT_flto) ||
810 Args.hasArg(options::OPT_O4)) {
Daniel Dunbar85cb3592009-03-13 11:38:42 +0000811 types::ID Output =
812 Args.hasArg(options::OPT_S) ? types::TY_LLVMAsm : types::TY_LLVMBC;
813 return new CompileJobAction(Input, Output);
814 } else {
815 return new CompileJobAction(Input, types::TY_PP_Asm);
816 }
817 }
818 case phases::Assemble:
819 return new AssembleJobAction(Input, types::TY_Object);
820 }
821
822 assert(0 && "invalid phase in ConstructPhaseAction");
823 return 0;
Daniel Dunbardb62cc32009-03-12 07:58:46 +0000824}
825
Daniel Dunbar73f7b8c2009-03-18 02:55:38 +0000826void Driver::BuildJobs(Compilation &C) const {
Daniel Dunbar16e04ff2009-03-18 01:38:48 +0000827 llvm::PrettyStackTraceString CrashInfo("Building compilation jobs");
Daniel Dunbar7ce6add2009-03-16 06:56:51 +0000828 bool SaveTemps = C.getArgs().hasArg(options::OPT_save_temps);
829 bool UsePipes = C.getArgs().hasArg(options::OPT_pipe);
Daniel Dunbarbac6b642009-03-18 23:18:19 +0000830
831 // FIXME: Pipes are forcibly disabled until we support executing
832 // them.
833 if (!CCCPrintBindings)
834 UsePipes = false;
Daniel Dunbar7ce6add2009-03-16 06:56:51 +0000835
836 // -save-temps inhibits pipes.
837 if (SaveTemps && UsePipes) {
838 Diag(clang::diag::warn_drv_pipe_ignored_with_save_temps);
839 UsePipes = true;
840 }
841
842 Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
843
844 // It is an error to provide a -o option if we are making multiple
845 // output files.
846 if (FinalOutput) {
847 unsigned NumOutputs = 0;
Daniel Dunbar73f7b8c2009-03-18 02:55:38 +0000848 for (ActionList::const_iterator it = C.getActions().begin(),
849 ie = C.getActions().end(); it != ie; ++it)
Daniel Dunbar7ce6add2009-03-16 06:56:51 +0000850 if ((*it)->getType() != types::TY_Nothing)
851 ++NumOutputs;
852
853 if (NumOutputs > 1) {
854 Diag(clang::diag::err_drv_output_argument_with_multiple_files);
855 FinalOutput = 0;
856 }
857 }
858
Daniel Dunbar73f7b8c2009-03-18 02:55:38 +0000859 for (ActionList::const_iterator it = C.getActions().begin(),
860 ie = C.getActions().end(); it != ie; ++it) {
Daniel Dunbar7ce6add2009-03-16 06:56:51 +0000861 Action *A = *it;
862
863 // If we are linking an image for multiple archs then the linker
864 // wants -arch_multiple and -final_output <final image
865 // name>. Unfortunately, this doesn't fit in cleanly because we
866 // have to pass this information down.
867 //
868 // FIXME: This is a hack; find a cleaner way to integrate this
869 // into the process.
870 const char *LinkingOutput = 0;
Daniel Dunbar55e34e32009-03-26 16:12:09 +0000871 if (isa<LipoJobAction>(A)) {
Daniel Dunbar7ce6add2009-03-16 06:56:51 +0000872 if (FinalOutput)
873 LinkingOutput = FinalOutput->getValue(C.getArgs());
874 else
875 LinkingOutput = DefaultImageName.c_str();
876 }
877
878 InputInfo II;
Daniel Dunbar2b856ce2009-03-18 03:13:20 +0000879 BuildJobsForAction(C, A, &C.getDefaultToolChain(),
Daniel Dunbar7ce6add2009-03-16 06:56:51 +0000880 /*CanAcceptPipe*/ true,
881 /*AtTopLevel*/ true,
882 /*LinkingOutput*/ LinkingOutput,
883 II);
884 }
Daniel Dunbar9d625e12009-03-16 06:42:30 +0000885
Daniel Dunbar025de202009-04-03 22:09:23 +0000886 // If the user passed -Qunused-arguments or there were errors, don't
887 // warn about any unused arguments.
Daniel Dunbar1cfd8912009-04-07 19:04:18 +0000888 if (Diags.getNumErrors() ||
889 C.getArgs().hasArg(options::OPT_Qunused_arguments))
Daniel Dunbar46c70822009-03-18 18:03:46 +0000890 return;
891
Daniel Dunbar1e6f9ff2009-03-29 22:24:54 +0000892 // Claim -### here.
893 (void) C.getArgs().hasArg(options::OPT__HASH_HASH_HASH);
894
Daniel Dunbar9d625e12009-03-16 06:42:30 +0000895 for (ArgList::const_iterator it = C.getArgs().begin(), ie = C.getArgs().end();
896 it != ie; ++it) {
897 Arg *A = *it;
Daniel Dunbar46c70822009-03-18 18:03:46 +0000898
Daniel Dunbar9d625e12009-03-16 06:42:30 +0000899 // FIXME: It would be nice to be able to send the argument to the
900 // Diagnostic, so that extra values, position, and so on could be
901 // printed.
Daniel Dunbar6c6e3f72009-04-04 00:52:26 +0000902 if (!A->isClaimed()) {
Daniel Dunbar1cfd8912009-04-07 19:04:18 +0000903 if (A->getOption().hasNoArgumentUnused())
904 continue;
905
Daniel Dunbar6c6e3f72009-04-04 00:52:26 +0000906 // Suppress the warning automatically if this is just a flag,
907 // and it is an instance of an argument we already claimed.
908 const Option &Opt = A->getOption();
909 if (isa<FlagOption>(Opt)) {
910 bool DuplicateClaimed = false;
911
912 // FIXME: Use iterator.
913 for (ArgList::const_iterator it = C.getArgs().begin(),
914 ie = C.getArgs().end(); it != ie; ++it) {
915 if ((*it)->isClaimed() && (*it)->getOption().matches(Opt.getId())) {
916 DuplicateClaimed = true;
917 break;
918 }
919 }
920
921 if (DuplicateClaimed)
922 continue;
923 }
924
Daniel Dunbar9d625e12009-03-16 06:42:30 +0000925 Diag(clang::diag::warn_drv_unused_argument)
Daniel Dunbar73225932009-03-20 06:14:23 +0000926 << A->getAsString(C.getArgs());
Daniel Dunbar6c6e3f72009-04-04 00:52:26 +0000927 }
Daniel Dunbar9d625e12009-03-16 06:42:30 +0000928 }
Daniel Dunbar47d762e2009-03-13 22:12:33 +0000929}
930
Daniel Dunbar7ce6add2009-03-16 06:56:51 +0000931void Driver::BuildJobsForAction(Compilation &C,
932 const Action *A,
933 const ToolChain *TC,
934 bool CanAcceptPipe,
935 bool AtTopLevel,
936 const char *LinkingOutput,
937 InputInfo &Result) const {
Daniel Dunbar16e04ff2009-03-18 01:38:48 +0000938 llvm::PrettyStackTraceString CrashInfo("Building compilation jobs for action");
Daniel Dunbarbac6b642009-03-18 23:18:19 +0000939
940 bool UsePipes = C.getArgs().hasArg(options::OPT_pipe);
941 // FIXME: Pipes are forcibly disabled until we support executing
942 // them.
943 if (!CCCPrintBindings)
944 UsePipes = false;
945
Daniel Dunbar7ce6add2009-03-16 06:56:51 +0000946 if (const InputAction *IA = dyn_cast<InputAction>(A)) {
Daniel Dunbarc3be67b2009-03-19 07:29:38 +0000947 // FIXME: It would be nice to not claim this here; maybe the old
948 // scheme of just using Args was better?
949 const Arg &Input = IA->getInputArg();
950 Input.claim();
951 if (isa<PositionalArg>(Input)) {
952 const char *Name = Input.getValue(C.getArgs());
953 Result = InputInfo(Name, A->getType(), Name);
954 } else
955 Result = InputInfo(&Input, A->getType(), "");
Daniel Dunbar7ce6add2009-03-16 06:56:51 +0000956 return;
957 }
958
959 if (const BindArchAction *BAA = dyn_cast<BindArchAction>(A)) {
960 const char *ArchName = BAA->getArchName();
Daniel Dunbar08303652009-05-22 02:53:45 +0000961 std::string Arch;
962 if (!ArchName) {
963 Arch = C.getDefaultToolChain().getArchName();
964 ArchName = Arch.c_str();
965 }
Daniel Dunbar7ce6add2009-03-16 06:56:51 +0000966 BuildJobsForAction(C,
967 *BAA->begin(),
968 Host->getToolChain(C.getArgs(), ArchName),
969 CanAcceptPipe,
970 AtTopLevel,
971 LinkingOutput,
972 Result);
973 return;
974 }
975
976 const JobAction *JA = cast<JobAction>(A);
977 const Tool &T = TC->SelectTool(C, *JA);
978
979 // See if we should use an integrated preprocessor. We do so when we
980 // have exactly one input, since this is the only use case we care
981 // about (irrelevant since we don't support combine yet).
982 bool UseIntegratedCPP = false;
983 const ActionList *Inputs = &A->getInputs();
984 if (Inputs->size() == 1 && isa<PreprocessJobAction>(*Inputs->begin())) {
985 if (!C.getArgs().hasArg(options::OPT_no_integrated_cpp) &&
986 !C.getArgs().hasArg(options::OPT_traditional_cpp) &&
987 !C.getArgs().hasArg(options::OPT_save_temps) &&
988 T.hasIntegratedCPP()) {
989 UseIntegratedCPP = true;
990 Inputs = &(*Inputs)[0]->getInputs();
991 }
992 }
993
994 // Only use pipes when there is exactly one input.
995 bool TryToUsePipeInput = Inputs->size() == 1 && T.acceptsPipedInput();
Daniel Dunbar00fd3792009-03-18 06:00:36 +0000996 InputInfoList InputInfos;
Daniel Dunbar7ce6add2009-03-16 06:56:51 +0000997 for (ActionList::const_iterator it = Inputs->begin(), ie = Inputs->end();
998 it != ie; ++it) {
999 InputInfo II;
1000 BuildJobsForAction(C, *it, TC, TryToUsePipeInput,
1001 /*AtTopLevel*/false,
1002 LinkingOutput,
1003 II);
1004 InputInfos.push_back(II);
1005 }
1006
1007 // Determine if we should output to a pipe.
1008 bool OutputToPipe = false;
1009 if (CanAcceptPipe && T.canPipeOutput()) {
1010 // Some actions default to writing to a pipe if they are the top
1011 // level phase and there was no user override.
1012 //
1013 // FIXME: Is there a better way to handle this?
1014 if (AtTopLevel) {
1015 if (isa<PreprocessJobAction>(A) && !C.getArgs().hasArg(options::OPT_o))
1016 OutputToPipe = true;
Daniel Dunbarbac6b642009-03-18 23:18:19 +00001017 } else if (UsePipes)
Daniel Dunbar7ce6add2009-03-16 06:56:51 +00001018 OutputToPipe = true;
1019 }
1020
1021 // Figure out where to put the job (pipes).
1022 Job *Dest = &C.getJobs();
1023 if (InputInfos[0].isPipe()) {
Daniel Dunbar01fb26a2009-03-17 17:53:55 +00001024 assert(TryToUsePipeInput && "Unrequested pipe!");
Daniel Dunbar7ce6add2009-03-16 06:56:51 +00001025 assert(InputInfos.size() == 1 && "Unexpected pipe with multiple inputs.");
1026 Dest = &InputInfos[0].getPipe();
1027 }
1028
1029 // Always use the first input as the base input.
1030 const char *BaseInput = InputInfos[0].getBaseInput();
Daniel Dunbar01fb26a2009-03-17 17:53:55 +00001031
1032 // Determine the place to write output to (nothing, pipe, or
1033 // filename) and where to put the new job.
Daniel Dunbar01fb26a2009-03-17 17:53:55 +00001034 if (JA->getType() == types::TY_Nothing) {
Daniel Dunbar07c9a1d2009-03-17 22:47:06 +00001035 Result = InputInfo(A->getType(), BaseInput);
Daniel Dunbar01fb26a2009-03-17 17:53:55 +00001036 } else if (OutputToPipe) {
1037 // Append to current piped job or create a new one as appropriate.
Daniel Dunbar07c9a1d2009-03-17 22:47:06 +00001038 PipedJob *PJ = dyn_cast<PipedJob>(Dest);
1039 if (!PJ) {
1040 PJ = new PipedJob();
Daniel Dunbar8eeb5a32009-03-20 00:11:04 +00001041 // FIXME: Temporary hack so that -ccc-print-bindings work until
1042 // we have pipe support. Please remove later.
1043 if (!CCCPrintBindings)
1044 cast<JobList>(Dest)->addJob(PJ);
Daniel Dunbar933ac452009-03-18 07:06:02 +00001045 Dest = PJ;
Daniel Dunbar01fb26a2009-03-17 17:53:55 +00001046 }
Daniel Dunbar07c9a1d2009-03-17 22:47:06 +00001047 Result = InputInfo(PJ, A->getType(), BaseInput);
Daniel Dunbar01fb26a2009-03-17 17:53:55 +00001048 } else {
Daniel Dunbar07c9a1d2009-03-17 22:47:06 +00001049 Result = InputInfo(GetNamedOutputPath(C, *JA, BaseInput, AtTopLevel),
1050 A->getType(), BaseInput);
Daniel Dunbar01fb26a2009-03-17 17:53:55 +00001051 }
1052
Daniel Dunbar07c9a1d2009-03-17 22:47:06 +00001053 if (CCCPrintBindings) {
Daniel Dunbar049b7242009-03-30 06:36:42 +00001054 llvm::errs() << "# \"" << T.getToolChain().getTripleString() << '"'
1055 << " - \"" << T.getName() << "\", inputs: [";
Daniel Dunbar07c9a1d2009-03-17 22:47:06 +00001056 for (unsigned i = 0, e = InputInfos.size(); i != e; ++i) {
1057 llvm::errs() << InputInfos[i].getAsString();
1058 if (i + 1 != e)
1059 llvm::errs() << ", ";
1060 }
1061 llvm::errs() << "], output: " << Result.getAsString() << "\n";
1062 } else {
Daniel Dunbara16e4fe2009-03-25 04:13:45 +00001063 T.ConstructJob(C, *JA, *Dest, Result, InputInfos,
1064 C.getArgsForToolChain(TC), LinkingOutput);
Daniel Dunbar07c9a1d2009-03-17 22:47:06 +00001065 }
Daniel Dunbar7ce6add2009-03-16 06:56:51 +00001066}
1067
Daniel Dunbar01fb26a2009-03-17 17:53:55 +00001068const char *Driver::GetNamedOutputPath(Compilation &C,
1069 const JobAction &JA,
1070 const char *BaseInput,
1071 bool AtTopLevel) const {
Daniel Dunbar16e04ff2009-03-18 01:38:48 +00001072 llvm::PrettyStackTraceString CrashInfo("Computing output path");
Daniel Dunbar01fb26a2009-03-17 17:53:55 +00001073 // Output to a user requested destination?
1074 if (AtTopLevel) {
1075 if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
1076 return C.addResultFile(FinalOutput->getValue(C.getArgs()));
1077 }
1078
1079 // Output to a temporary file?
1080 if (!AtTopLevel && !C.getArgs().hasArg(options::OPT_save_temps)) {
Daniel Dunbarb6ddc952009-03-18 19:34:39 +00001081 std::string TmpName =
1082 GetTemporaryPath(types::getTypeTempSuffix(JA.getType()));
1083 return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()));
Daniel Dunbar01fb26a2009-03-17 17:53:55 +00001084 }
1085
1086 llvm::sys::Path BasePath(BaseInput);
Daniel Dunbarfb5e3332009-03-18 02:00:31 +00001087 std::string BaseName(BasePath.getLast());
Daniel Dunbar01fb26a2009-03-17 17:53:55 +00001088
1089 // Determine what the derived output name should be.
1090 const char *NamedOutput;
1091 if (JA.getType() == types::TY_Image) {
1092 NamedOutput = DefaultImageName.c_str();
1093 } else {
1094 const char *Suffix = types::getTypeTempSuffix(JA.getType());
1095 assert(Suffix && "All types used for output should have a suffix.");
1096
1097 std::string::size_type End = std::string::npos;
1098 if (!types::appendSuffixForType(JA.getType()))
1099 End = BaseName.rfind('.');
1100 std::string Suffixed(BaseName.substr(0, End));
1101 Suffixed += '.';
1102 Suffixed += Suffix;
1103 NamedOutput = C.getArgs().MakeArgString(Suffixed.c_str());
1104 }
1105
1106 // As an annoying special case, PCH generation doesn't strip the
1107 // pathname.
1108 if (JA.getType() == types::TY_PCH) {
1109 BasePath.eraseComponent();
Daniel Dunbar58a51262009-03-18 09:58:30 +00001110 if (BasePath.isEmpty())
1111 BasePath = NamedOutput;
1112 else
1113 BasePath.appendComponent(NamedOutput);
Daniel Dunbar01fb26a2009-03-17 17:53:55 +00001114 return C.addResultFile(C.getArgs().MakeArgString(BasePath.c_str()));
1115 } else {
1116 return C.addResultFile(NamedOutput);
1117 }
1118}
1119
Daniel Dunbare1cef7d2009-03-16 05:25:36 +00001120llvm::sys::Path Driver::GetFilePath(const char *Name,
Daniel Dunbar73f7b8c2009-03-18 02:55:38 +00001121 const ToolChain &TC) const {
Daniel Dunbarcc7600c2009-03-18 20:26:19 +00001122 const ToolChain::path_list &List = TC.getFilePaths();
1123 for (ToolChain::path_list::const_iterator
1124 it = List.begin(), ie = List.end(); it != ie; ++it) {
1125 llvm::sys::Path P(*it);
1126 P.appendComponent(Name);
1127 if (P.exists())
1128 return P;
1129 }
1130
Daniel Dunbarcc006892009-03-13 00:51:18 +00001131 return llvm::sys::Path(Name);
1132}
1133
Daniel Dunbare1cef7d2009-03-16 05:25:36 +00001134llvm::sys::Path Driver::GetProgramPath(const char *Name,
Mike Stump32b1bbe2009-03-27 00:40:20 +00001135 const ToolChain &TC,
1136 bool WantFile) const {
Daniel Dunbarcc7600c2009-03-18 20:26:19 +00001137 const ToolChain::path_list &List = TC.getProgramPaths();
1138 for (ToolChain::path_list::const_iterator
1139 it = List.begin(), ie = List.end(); it != ie; ++it) {
1140 llvm::sys::Path P(*it);
1141 P.appendComponent(Name);
Mike Stump32b1bbe2009-03-27 00:40:20 +00001142 if (WantFile ? P.exists() : P.canExecute())
Daniel Dunbarcc7600c2009-03-18 20:26:19 +00001143 return P;
1144 }
1145
Daniel Dunbar49a35de2009-03-23 16:15:50 +00001146 // If all else failed, search the path.
1147 llvm::sys::Path P(llvm::sys::Program::FindProgramByName(Name));
Daniel Dunbarcb84b9a2009-03-18 21:34:08 +00001148 if (!P.empty())
1149 return P;
1150
Daniel Dunbarcc006892009-03-13 00:51:18 +00001151 return llvm::sys::Path(Name);
1152}
1153
Daniel Dunbarb6ddc952009-03-18 19:34:39 +00001154std::string Driver::GetTemporaryPath(const char *Suffix) const {
1155 // FIXME: This is lame; sys::Path should provide this function (in
1156 // particular, it should know how to find the temporary files dir).
1157 std::string Error;
Daniel Dunbar02e396a2009-04-20 20:28:21 +00001158 const char *TmpDir = ::getenv("TMPDIR");
1159 if (!TmpDir)
1160 TmpDir = ::getenv("TEMP");
1161 if (!TmpDir)
Daniel Dunbara77aa002009-04-21 00:25:10 +00001162 TmpDir = ::getenv("TMP");
1163 if (!TmpDir)
Daniel Dunbar02e396a2009-04-20 20:28:21 +00001164 TmpDir = "/tmp";
1165 llvm::sys::Path P(TmpDir);
Daniel Dunbar121f2512009-04-20 17:32:49 +00001166 P.appendComponent("cc");
Daniel Dunbarb6ddc952009-03-18 19:34:39 +00001167 if (P.makeUnique(false, &Error)) {
1168 Diag(clang::diag::err_drv_unable_to_make_temp) << Error;
1169 return "";
1170 }
1171
Daniel Dunbar9083abe2009-03-18 23:08:52 +00001172 // FIXME: Grumble, makeUnique sometimes leaves the file around!?
1173 // PR3837.
1174 P.eraseFromDisk(false, 0);
1175
Daniel Dunbarb6ddc952009-03-18 19:34:39 +00001176 P.appendSuffix(Suffix);
1177 return P.toString();
1178}
1179
Daniel Dunbar08303652009-05-22 02:53:45 +00001180const HostInfo *Driver::GetHostInfo(const char *TripleStr) const {
Daniel Dunbar16e04ff2009-03-18 01:38:48 +00001181 llvm::PrettyStackTraceString CrashInfo("Constructing host");
Daniel Dunbar08303652009-05-22 02:53:45 +00001182 llvm::Triple Triple(TripleStr);
Daniel Dunbard25acaa2009-03-10 23:41:59 +00001183
Daniel Dunbar7424b8a2009-03-17 19:00:50 +00001184 // Normalize Arch a bit.
1185 //
Daniel Dunbar08303652009-05-22 02:53:45 +00001186 // FIXME: We shouldn't need to do this once everything goes through the triple
1187 // interface.
1188 if (Triple.getArchName() == "i686")
1189 Triple.setArchName("i386");
1190 else if (Triple.getArchName() == "amd64")
1191 Triple.setArchName("x86_64");
1192 else if (Triple.getArchName() == "ppc" ||
1193 Triple.getArchName() == "Power Macintosh")
1194 Triple.setArchName("powerpc");
1195 else if (Triple.getArchName() == "ppc64")
1196 Triple.setArchName("powerpc64");
Daniel Dunbar46363f52009-05-02 18:28:39 +00001197
Daniel Dunbar08303652009-05-22 02:53:45 +00001198 switch (Triple.getOS()) {
1199 case llvm::Triple::Darwin:
1200 return createDarwinHostInfo(*this, Triple);
1201 case llvm::Triple::DragonFly:
1202 return createDragonFlyHostInfo(*this, Triple);
1203 case llvm::Triple::FreeBSD:
1204 return createFreeBSDHostInfo(*this, Triple);
Eli Friedman8cac4352009-05-26 07:52:18 +00001205 case llvm::Triple::Linux:
1206 return createLinuxHostInfo(*this, Triple);
Daniel Dunbar08303652009-05-22 02:53:45 +00001207 default:
1208 return createUnknownHostInfo(*this, Triple);
1209 }
Daniel Dunbard25acaa2009-03-10 23:41:59 +00001210}
Daniel Dunbar1a9c8ca2009-03-24 18:57:02 +00001211
1212bool Driver::ShouldUseClangCompiler(const Compilation &C, const JobAction &JA,
Daniel Dunbarb7daa2d2009-04-01 20:33:11 +00001213 const std::string &ArchNameStr) const {
1214 // FIXME: Remove this hack.
1215 const char *ArchName = ArchNameStr.c_str();
1216 if (ArchNameStr == "powerpc")
1217 ArchName = "ppc";
1218 else if (ArchNameStr == "powerpc64")
1219 ArchName = "ppc64";
1220
Daniel Dunbar1a9c8ca2009-03-24 18:57:02 +00001221 // Check if user requested no clang, or clang doesn't understand
1222 // this type (we only handle single inputs for now).
Daniel Dunbar0ea85f72009-03-24 19:02:31 +00001223 if (!CCCUseClang || JA.size() != 1 ||
Daniel Dunbar1a9c8ca2009-03-24 18:57:02 +00001224 !types::isAcceptedByClang((*JA.begin())->getType()))
1225 return false;
1226
Daniel Dunbar0ea85f72009-03-24 19:02:31 +00001227 // Otherwise make sure this is an action clang understands.
Daniel Dunbar1a9c8ca2009-03-24 18:57:02 +00001228 if (isa<PreprocessJobAction>(JA)) {
Daniel Dunbarb1ae14d2009-03-24 19:14:56 +00001229 if (!CCCUseClangCPP) {
1230 Diag(clang::diag::warn_drv_not_using_clang_cpp);
Daniel Dunbar1a9c8ca2009-03-24 18:57:02 +00001231 return false;
Daniel Dunbarb1ae14d2009-03-24 19:14:56 +00001232 }
Daniel Dunbar1a9c8ca2009-03-24 18:57:02 +00001233 } else if (!isa<PrecompileJobAction>(JA) && !isa<CompileJobAction>(JA))
1234 return false;
1235
Daniel Dunbar0ea85f72009-03-24 19:02:31 +00001236 // Use clang for C++?
Daniel Dunbarb1ae14d2009-03-24 19:14:56 +00001237 if (!CCCUseClangCXX && types::isCXX((*JA.begin())->getType())) {
1238 Diag(clang::diag::warn_drv_not_using_clang_cxx);
Daniel Dunbar1a9c8ca2009-03-24 18:57:02 +00001239 return false;
Daniel Dunbarb1ae14d2009-03-24 19:14:56 +00001240 }
Daniel Dunbar1a9c8ca2009-03-24 18:57:02 +00001241
Daniel Dunbar5a34ca82009-04-16 23:10:13 +00001242 // Always use clang for precompiling, regardless of archs. PTH is
1243 // platform independent, and this allows the use of the static
1244 // analyzer on platforms we don't have full IRgen support for.
1245 if (isa<PrecompileJobAction>(JA))
1246 return true;
1247
Daniel Dunbar1a9c8ca2009-03-24 18:57:02 +00001248 // Finally, don't use clang if this isn't one of the user specified
1249 // archs to build.
Daniel Dunbarb1ae14d2009-03-24 19:14:56 +00001250 if (!CCCClangArchs.empty() && !CCCClangArchs.count(ArchName)) {
1251 Diag(clang::diag::warn_drv_not_using_clang_arch) << ArchName;
Daniel Dunbar1a9c8ca2009-03-24 18:57:02 +00001252 return false;
Daniel Dunbarb1ae14d2009-03-24 19:14:56 +00001253 }
Daniel Dunbar1a9c8ca2009-03-24 18:57:02 +00001254
1255 return true;
1256}
Daniel Dunbar9cdd4d42009-03-26 15:58:36 +00001257
1258/// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and
1259/// return the grouped values as integers. Numbers which are not
1260/// provided are set to 0.
1261///
1262/// \return True if the entire string was parsed (9.2), or all groups
1263/// were parsed (10.3.5extrastuff).
1264bool Driver::GetReleaseVersion(const char *Str, unsigned &Major,
1265 unsigned &Minor, unsigned &Micro,
1266 bool &HadExtra) {
1267 HadExtra = false;
1268
1269 Major = Minor = Micro = 0;
1270 if (*Str == '\0')
1271 return true;
1272
1273 char *End;
1274 Major = (unsigned) strtol(Str, &End, 10);
1275 if (*Str != '\0' && *End == '\0')
1276 return true;
1277 if (*End != '.')
1278 return false;
1279
1280 Str = End+1;
1281 Minor = (unsigned) strtol(Str, &End, 10);
1282 if (*Str != '\0' && *End == '\0')
1283 return true;
1284 if (*End != '.')
1285 return false;
1286
1287 Str = End+1;
1288 Micro = (unsigned) strtol(Str, &End, 10);
1289 if (*Str != '\0' && *End == '\0')
1290 return true;
1291 if (Str == End)
1292 return false;
1293 HadExtra = true;
1294 return true;
1295}