blob: ac529cb528259e8bd148a33ce64deca45d3dbeba [file] [log] [blame]
Daniel Dunbar3ede8d02009-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 Dunbar1eb4e642009-03-03 05:55:11 +000010// This is the entry point to the clang driver; it is a thin wrapper
11// for functionality in the Driver clang library.
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000012//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Driver/Compilation.h"
16#include "clang/Driver/Driver.h"
Daniel Dunbar2c6f6f32009-03-04 08:33:23 +000017#include "clang/Driver/Option.h"
Daniel Dunbaraf20afb2010-02-25 03:23:43 +000018#include "clang/Frontend/DiagnosticOptions.h"
19#include "clang/Frontend/TextDiagnosticPrinter.h"
Daniel Dunbar2c6f6f32009-03-04 08:33:23 +000020
Daniel Dunbar510d7322009-03-18 02:11:26 +000021#include "llvm/ADT/SmallString.h"
Rafael Espindola8a1af322010-07-19 15:20:12 +000022#include "llvm/ADT/SmallVector.h"
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000023#include "llvm/ADT/OwningPtr.h"
Daniel Dunbardd98e2c2009-03-10 23:41:59 +000024#include "llvm/Config/config.h"
Rafael Espindola8a1af322010-07-19 15:20:12 +000025#include "llvm/Support/ErrorHandling.h"
Michael J. Spencerfbfd1802010-12-21 16:45:57 +000026#include "llvm/Support/FileSystem.h"
Daniel Dunbar8f25c792009-03-18 01:38:48 +000027#include "llvm/Support/ManagedStatic.h"
Rafael Espindola8a1af322010-07-19 15:20:12 +000028#include "llvm/Support/MemoryBuffer.h"
Daniel Dunbar8f25c792009-03-18 01:38:48 +000029#include "llvm/Support/PrettyStackTrace.h"
Daniel Dunbar0de9a7b2010-02-17 21:00:34 +000030#include "llvm/Support/Regex.h"
Chris Lattner30bc7e82010-03-30 05:39:52 +000031#include "llvm/Support/Timer.h"
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000032#include "llvm/Support/raw_ostream.h"
Michael J. Spencer03013fa2010-11-29 18:12:39 +000033#include "llvm/Support/Host.h"
34#include "llvm/Support/Path.h"
35#include "llvm/Support/Program.h"
36#include "llvm/Support/Signals.h"
Michael J. Spencer3a321e22010-12-09 17:36:38 +000037#include "llvm/Support/system_error.h"
Joerg Sonnenberger0ce89c62011-03-16 20:15:43 +000038#include "llvm/Target/TargetRegistry.h"
39#include "llvm/Target/TargetSelect.h"
Douglas Gregor43d013d2011-01-17 19:15:43 +000040#include <cctype>
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000041using namespace clang;
Daniel Dunbar1b3bb6e2009-03-04 20:49:20 +000042using namespace clang::driver;
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000043
Benjamin Krameraeed3da2010-10-30 17:32:40 +000044llvm::sys::Path GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
Rafael Espindola0f4c59c2009-12-04 19:31:58 +000045 if (!CanonicalPrefixes)
46 return llvm::sys::Path(Argv0);
47
Daniel Dunbar734932c2009-03-18 20:25:53 +000048 // This just needs to be some symbol in the binary; C++ doesn't
49 // allow taking the address of ::main however.
50 void *P = (void*) (intptr_t) GetExecutablePath;
51 return llvm::sys::Path::GetMainExecutable(Argv0, P);
52}
53
Daniel Dunbar237a31b2009-07-17 18:10:27 +000054static const char *SaveStringInSet(std::set<std::string> &SavedStrings,
Daniel Dunbar0de9a7b2010-02-17 21:00:34 +000055 llvm::StringRef S) {
Daniel Dunbarec9587d2009-04-17 01:54:00 +000056 return SavedStrings.insert(S).first->c_str();
57}
58
59/// ApplyQAOverride - Apply a list of edits to the input argument lists.
60///
61/// The input string is a space separate list of edits to perform,
62/// they are applied in order to the input argument lists. Edits
63/// should be one of the following forms:
64///
Daniel Dunbare3d60232009-07-16 21:32:51 +000065/// '#': Silence information about the changes to the command line arguments.
66///
Daniel Dunbarec9587d2009-04-17 01:54:00 +000067/// '^': Add FOO as a new argument at the beginning of the command line.
68///
69/// '+': Add FOO as a new argument at the end of the command line.
70///
Daniel Dunbar0de9a7b2010-02-17 21:00:34 +000071/// 's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
72/// line.
Daniel Dunbarec9587d2009-04-17 01:54:00 +000073///
74/// 'xOPTION': Removes all instances of the literal argument OPTION.
75///
76/// 'XOPTION': Removes all instances of the literal argument OPTION,
77/// and the following argument.
78///
79/// 'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
80/// at the end of the command line.
Daniel Dunbare3d60232009-07-16 21:32:51 +000081///
82/// \param OS - The stream to write edit information to.
83/// \param Args - The vector of command line arguments.
84/// \param Edit - The override command to perform.
85/// \param SavedStrings - Set to use for storing string representations.
Chris Lattner30bc7e82010-03-30 05:39:52 +000086static void ApplyOneQAOverride(llvm::raw_ostream &OS,
Daniel Dunbare5d69672010-07-20 02:47:40 +000087 llvm::SmallVectorImpl<const char*> &Args,
Chris Lattner30bc7e82010-03-30 05:39:52 +000088 llvm::StringRef Edit,
89 std::set<std::string> &SavedStrings) {
Daniel Dunbarec9587d2009-04-17 01:54:00 +000090 // This does not need to be efficient.
91
Daniel Dunbar237a31b2009-07-17 18:10:27 +000092 if (Edit[0] == '^') {
93 const char *Str =
Daniel Dunbar0de9a7b2010-02-17 21:00:34 +000094 SaveStringInSet(SavedStrings, Edit.substr(1));
Daniel Dunbar237a31b2009-07-17 18:10:27 +000095 OS << "### Adding argument " << Str << " at beginning\n";
96 Args.insert(Args.begin() + 1, Str);
97 } else if (Edit[0] == '+') {
98 const char *Str =
Daniel Dunbar0de9a7b2010-02-17 21:00:34 +000099 SaveStringInSet(SavedStrings, Edit.substr(1));
Daniel Dunbar237a31b2009-07-17 18:10:27 +0000100 OS << "### Adding argument " << Str << " at end\n";
101 Args.push_back(Str);
Daniel Dunbar0de9a7b2010-02-17 21:00:34 +0000102 } else if (Edit[0] == 's' && Edit[1] == '/' && Edit.endswith("/") &&
103 Edit.slice(2, Edit.size()-1).find('/') != llvm::StringRef::npos) {
104 llvm::StringRef MatchPattern = Edit.substr(2).split('/').first;
105 llvm::StringRef ReplPattern = Edit.substr(2).split('/').second;
106 ReplPattern = ReplPattern.slice(0, ReplPattern.size()-1);
107
108 for (unsigned i = 1, e = Args.size(); i != e; ++i) {
109 std::string Repl = llvm::Regex(MatchPattern).sub(ReplPattern, Args[i]);
110
111 if (Repl != Args[i]) {
112 OS << "### Replacing '" << Args[i] << "' with '" << Repl << "'\n";
113 Args[i] = SaveStringInSet(SavedStrings, Repl);
114 }
115 }
Daniel Dunbar237a31b2009-07-17 18:10:27 +0000116 } else if (Edit[0] == 'x' || Edit[0] == 'X') {
117 std::string Option = Edit.substr(1, std::string::npos);
118 for (unsigned i = 1; i < Args.size();) {
119 if (Option == Args[i]) {
120 OS << "### Deleting argument " << Args[i] << '\n';
121 Args.erase(Args.begin() + i);
122 if (Edit[0] == 'X') {
123 if (i < Args.size()) {
124 OS << "### Deleting argument " << Args[i] << '\n';
125 Args.erase(Args.begin() + i);
126 } else
127 OS << "### Invalid X edit, end of command line!\n";
128 }
129 } else
130 ++i;
131 }
132 } else if (Edit[0] == 'O') {
133 for (unsigned i = 1; i < Args.size();) {
134 const char *A = Args[i];
135 if (A[0] == '-' && A[1] == 'O' &&
136 (A[2] == '\0' ||
137 (A[3] == '\0' && (A[2] == 's' || A[2] == 'z' ||
138 ('0' <= A[2] && A[2] <= '9'))))) {
139 OS << "### Deleting argument " << Args[i] << '\n';
140 Args.erase(Args.begin() + i);
141 } else
142 ++i;
143 }
144 OS << "### Adding argument " << Edit << " at end\n";
Daniel Dunbar0de9a7b2010-02-17 21:00:34 +0000145 Args.push_back(SaveStringInSet(SavedStrings, '-' + Edit.str()));
Daniel Dunbar237a31b2009-07-17 18:10:27 +0000146 } else {
147 OS << "### Unrecognized edit: " << Edit << "\n";
148 }
Daniel Dunbarec9587d2009-04-17 01:54:00 +0000149}
150
151/// ApplyQAOverride - Apply a comma separate list of edits to the
152/// input argument lists. See ApplyOneQAOverride.
Daniel Dunbare5d69672010-07-20 02:47:40 +0000153static void ApplyQAOverride(llvm::SmallVectorImpl<const char*> &Args,
Chris Lattner30bc7e82010-03-30 05:39:52 +0000154 const char *OverrideStr,
155 std::set<std::string> &SavedStrings) {
Daniel Dunbare3d60232009-07-16 21:32:51 +0000156 llvm::raw_ostream *OS = &llvm::errs();
Daniel Dunbar237a31b2009-07-17 18:10:27 +0000157
Daniel Dunbare3d60232009-07-16 21:32:51 +0000158 if (OverrideStr[0] == '#') {
159 ++OverrideStr;
160 OS = &llvm::nulls();
161 }
162
163 *OS << "### QA_OVERRIDE_GCC3_OPTIONS: " << OverrideStr << "\n";
Daniel Dunbarec9587d2009-04-17 01:54:00 +0000164
165 // This does not need to be efficient.
166
167 const char *S = OverrideStr;
168 while (*S) {
169 const char *End = ::strchr(S, ' ');
170 if (!End)
171 End = S + strlen(S);
172 if (End != S)
Daniel Dunbare3d60232009-07-16 21:32:51 +0000173 ApplyOneQAOverride(*OS, Args, std::string(S, End), SavedStrings);
Daniel Dunbarec9587d2009-04-17 01:54:00 +0000174 S = End;
175 if (*S != '\0')
176 ++S;
177 }
178}
179
Daniel Dunbarc88aa792009-11-30 07:18:13 +0000180extern int cc1_main(const char **ArgBegin, const char **ArgEnd,
Daniel Dunbar545c2812009-11-29 20:58:32 +0000181 const char *Argv0, void *MainAddr);
Daniel Dunbar41b5b172010-05-20 17:49:16 +0000182extern int cc1as_main(const char **ArgBegin, const char **ArgEnd,
183 const char *Argv0, void *MainAddr);
Daniel Dunbar217acbf2009-11-19 07:37:51 +0000184
Rafael Espindola8a1af322010-07-19 15:20:12 +0000185static void ExpandArgsFromBuf(const char *Arg,
Daniel Dunbare5d69672010-07-20 02:47:40 +0000186 llvm::SmallVectorImpl<const char*> &ArgVector,
Rafael Espindola8a1af322010-07-19 15:20:12 +0000187 std::set<std::string> &SavedStrings) {
188 const char *FName = Arg + 1;
Michael J. Spencer4eeebc42010-12-16 03:28:14 +0000189 llvm::OwningPtr<llvm::MemoryBuffer> MemBuf;
190 if (llvm::MemoryBuffer::getFile(FName, MemBuf)) {
Rafael Espindola8a1af322010-07-19 15:20:12 +0000191 ArgVector.push_back(SaveStringInSet(SavedStrings, Arg));
192 return;
193 }
194
195 const char *Buf = MemBuf->getBufferStart();
196 char InQuote = ' ';
197 std::string CurArg;
198
199 for (const char *P = Buf; ; ++P) {
200 if (*P == '\0' || (isspace(*P) && InQuote == ' ')) {
201 if (!CurArg.empty()) {
202
203 if (CurArg[0] != '@') {
204 ArgVector.push_back(SaveStringInSet(SavedStrings, CurArg));
205 } else {
206 ExpandArgsFromBuf(CurArg.c_str(), ArgVector, SavedStrings);
207 }
208
209 CurArg = "";
210 }
211 if (*P == '\0')
212 break;
213 else
214 continue;
215 }
216
217 if (isspace(*P)) {
218 if (InQuote != ' ')
219 CurArg.push_back(*P);
220 continue;
221 }
222
223 if (*P == '"' || *P == '\'') {
224 if (InQuote == *P)
225 InQuote = ' ';
226 else if (InQuote == ' ')
227 InQuote = *P;
228 else
229 CurArg.push_back(*P);
230 continue;
231 }
232
233 if (*P == '\\') {
234 ++P;
235 if (*P != '\0')
236 CurArg.push_back(*P);
237 continue;
238 }
239 CurArg.push_back(*P);
240 }
Rafael Espindola8a1af322010-07-19 15:20:12 +0000241}
242
243static void ExpandArgv(int argc, const char **argv,
Daniel Dunbare5d69672010-07-20 02:47:40 +0000244 llvm::SmallVectorImpl<const char*> &ArgVector,
Rafael Espindola8a1af322010-07-19 15:20:12 +0000245 std::set<std::string> &SavedStrings) {
246 for (int i = 0; i < argc; ++i) {
247 const char *Arg = argv[i];
248 if (Arg[0] != '@') {
249 ArgVector.push_back(SaveStringInSet(SavedStrings, std::string(Arg)));
250 continue;
251 }
252
253 ExpandArgsFromBuf(Arg, ArgVector, SavedStrings);
254 }
255}
256
Joerg Sonnenberger0ce89c62011-03-16 20:15:43 +0000257static void ParseProgName(llvm::SmallVectorImpl<const char *> &ArgVector,
258 std::set<std::string> &SavedStrings,
259 Driver &TheDriver)
260{
261 // Try to infer frontend type and default target from the program name.
262
263 // suffixes[] contains the list of known driver suffixes.
264 // Suffixes are compared against the program name in order.
265 // If there is a match, the frontend type is updated as necessary (CPP/C++).
266 // If there is no match, a second round is done after stripping the last
267 // hyphen and everything following it. This allows using something like
268 // "clang++-2.9".
269
270 // If there is a match in either the first or second round,
271 // the function tries to identify a target as prefix. E.g.
272 // "x86_64-linux-clang" as interpreted as suffix "clang" with
273 // target prefix "x86_64-linux". If such a target prefix is found,
274 // is gets added via -ccc-host-triple as implicit first argument.
275 static const struct {
276 const char *Suffix;
277 bool IsCXX;
278 bool IsCPP;
279 } suffixes [] = {
280 { "clang", false, false },
281 { "clang++", true, false },
282 { "clang-c++", true, false },
283 { "clang-cc", false, false },
284 { "clang-cpp", false, true },
285 { "clang-g++", true, false },
286 { "clang-gcc", false, false },
287 { "cc", false, false },
288 { "cpp", false, true },
289 { "++", true, false },
290 };
291 std::string ProgName(llvm::sys::path::stem(ArgVector[0]));
292 llvm::StringRef ProgNameRef(ProgName);
293 llvm::StringRef Prefix;
294
295 for (int Components = 2; Components; --Components) {
296 bool FoundMatch = false;
297 size_t i;
298
299 for (i = 0; i < sizeof(suffixes) / sizeof(suffixes[0]); ++i) {
300 if (ProgNameRef.endswith(suffixes[i].Suffix)) {
301 FoundMatch = true;
302 if (suffixes[i].IsCXX)
303 TheDriver.CCCIsCXX = true;
304 if (suffixes[i].IsCPP)
305 TheDriver.CCCIsCPP = true;
306 break;
307 }
308 }
309
310 if (FoundMatch) {
311 llvm::StringRef::size_type LastComponent = ProgNameRef.rfind('-',
312 ProgNameRef.size() - strlen(suffixes[i].Suffix));
313 if (LastComponent != llvm::StringRef::npos)
314 Prefix = ProgNameRef.slice(0, LastComponent);
315 break;
316 }
317
318 llvm::StringRef::size_type LastComponent = ProgNameRef.rfind('-');
319 if (LastComponent == llvm::StringRef::npos)
320 break;
321 ProgNameRef = ProgNameRef.slice(0, LastComponent);
322 }
323
324 if (Prefix.empty())
325 return;
326
327 std::string IgnoredError;
328 if (llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError)) {
329 ArgVector.insert(&ArgVector[1],
330 SaveStringInSet(SavedStrings, Prefix));
331 ArgVector.insert(&ArgVector[1],
332 SaveStringInSet(SavedStrings, std::string("-ccc-host-triple")));
333 }
334}
335
Rafael Espindola8a1af322010-07-19 15:20:12 +0000336int main(int argc_, const char **argv_) {
Daniel Dunbar3ede8d02009-03-02 19:59:07 +0000337 llvm::sys::PrintStackTraceOnErrorSignal();
Rafael Espindola8a1af322010-07-19 15:20:12 +0000338 llvm::PrettyStackTraceProgram X(argc_, argv_);
339
340 std::set<std::string> SavedStrings;
Daniel Dunbare5d69672010-07-20 02:47:40 +0000341 llvm::SmallVector<const char*, 256> argv;
Rafael Espindola8a1af322010-07-19 15:20:12 +0000342
343 ExpandArgv(argc_, argv_, argv, SavedStrings);
Daniel Dunbar3ede8d02009-03-02 19:59:07 +0000344
Daniel Dunbar41b5b172010-05-20 17:49:16 +0000345 // Handle -cc1 integrated tools.
Rafael Espindola8a1af322010-07-19 15:20:12 +0000346 if (argv.size() > 1 && llvm::StringRef(argv[1]).startswith("-cc1")) {
Daniel Dunbar41b5b172010-05-20 17:49:16 +0000347 llvm::StringRef Tool = argv[1] + 4;
348
349 if (Tool == "")
Daniel Dunbare5d69672010-07-20 02:47:40 +0000350 return cc1_main(argv.data()+2, argv.data()+argv.size(), argv[0],
Daniel Dunbar41b5b172010-05-20 17:49:16 +0000351 (void*) (intptr_t) GetExecutablePath);
352 if (Tool == "as")
Daniel Dunbare5d69672010-07-20 02:47:40 +0000353 return cc1as_main(argv.data()+2, argv.data()+argv.size(), argv[0],
Daniel Dunbar41b5b172010-05-20 17:49:16 +0000354 (void*) (intptr_t) GetExecutablePath);
355
356 // Reject unknown tools.
357 llvm::errs() << "error: unknown integrated tool '" << Tool << "'\n";
358 return 1;
359 }
Daniel Dunbarc88aa792009-11-30 07:18:13 +0000360
Rafael Espindola0f4c59c2009-12-04 19:31:58 +0000361 bool CanonicalPrefixes = true;
Rafael Espindola8a1af322010-07-19 15:20:12 +0000362 for (int i = 1, size = argv.size(); i < size; ++i) {
Rafael Espindola0f4c59c2009-12-04 19:31:58 +0000363 if (llvm::StringRef(argv[i]) == "-no-canonical-prefixes") {
364 CanonicalPrefixes = false;
365 break;
366 }
367 }
368
369 llvm::sys::Path Path = GetExecutablePath(argv[0], CanonicalPrefixes);
370
Douglas Gregorbdbb0042010-08-18 22:29:43 +0000371 TextDiagnosticPrinter *DiagClient
372 = new TextDiagnosticPrinter(llvm::errs(), DiagnosticOptions());
Michael J. Spencerd5b08be2010-12-18 04:13:32 +0000373 DiagClient->setPrefix(llvm::sys::path::stem(Path.str()));
Argyrios Kyrtzidis33e4e702010-11-18 20:06:41 +0000374 llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
375 Diagnostic Diags(DiagID, DiagClient);
Daniel Dunbar510d7322009-03-18 02:11:26 +0000376
Daniel Dunbarf44c5852009-09-22 22:31:13 +0000377#ifdef CLANG_IS_PRODUCTION
Kovarththanan Rajaratnam240c7342010-03-08 18:33:04 +0000378 const bool IsProduction = true;
Daniel Dunbar5d93ed32010-04-01 18:21:41 +0000379# ifdef CLANGXX_IS_PRODUCTION
380 const bool CXXIsProduction = true;
381# else
382 const bool CXXIsProduction = false;
383# endif
Daniel Dunbarf44c5852009-09-22 22:31:13 +0000384#else
Kovarththanan Rajaratnam240c7342010-03-08 18:33:04 +0000385 const bool IsProduction = false;
Daniel Dunbar5d93ed32010-04-01 18:21:41 +0000386 const bool CXXIsProduction = false;
Daniel Dunbarf44c5852009-09-22 22:31:13 +0000387#endif
Daniel Dunbar0bbad512010-07-19 00:44:04 +0000388 Driver TheDriver(Path.str(), llvm::sys::getHostTriple(),
Daniel Dunbar5d93ed32010-04-01 18:21:41 +0000389 "a.out", IsProduction, CXXIsProduction,
390 Diags);
Daniel Dunbare5be6da2009-04-01 19:08:46 +0000391
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000392 // Attempt to find the original path used to invoke the driver, to determine
393 // the installed path. We do this manually, because we want to support that
394 // path being a symlink.
Michael J. Spencerfbfd1802010-12-21 16:45:57 +0000395 {
396 llvm::SmallString<128> InstalledPath(argv[0]);
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000397
Michael J. Spencerfbfd1802010-12-21 16:45:57 +0000398 // Do a PATH lookup, if there are no directory components.
399 if (llvm::sys::path::filename(InstalledPath) == InstalledPath) {
400 llvm::sys::Path Tmp = llvm::sys::Program::FindProgramByName(
401 llvm::sys::path::filename(InstalledPath.str()));
402 if (!Tmp.empty())
403 InstalledPath = Tmp.str();
404 }
405 llvm::sys::fs::make_absolute(InstalledPath);
406 InstalledPath = llvm::sys::path::parent_path(InstalledPath);
407 bool exists;
408 if (!llvm::sys::fs::exists(InstalledPath.str(), exists) && exists)
409 TheDriver.setInstalledDir(InstalledPath);
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000410 }
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000411
Joerg Sonnenberger0ce89c62011-03-16 20:15:43 +0000412 llvm::InitializeAllTargets();
413 ParseProgName(argv, SavedStrings, TheDriver);
Joerg Sonnenberger9ade4ae2011-03-06 23:31:01 +0000414
Daniel Dunbar4c00fcd2010-03-20 08:01:59 +0000415 // Handle CC_PRINT_OPTIONS and CC_PRINT_OPTIONS_FILE.
416 TheDriver.CCPrintOptions = !!::getenv("CC_PRINT_OPTIONS");
417 if (TheDriver.CCPrintOptions)
418 TheDriver.CCPrintOptionsFilename = ::getenv("CC_PRINT_OPTIONS_FILE");
419
Daniel Dunbar322c29f2011-02-02 21:11:35 +0000420 // Handle CC_PRINT_HEADERS and CC_PRINT_HEADERS_FILE.
421 TheDriver.CCPrintHeaders = !!::getenv("CC_PRINT_HEADERS");
422 if (TheDriver.CCPrintHeaders)
423 TheDriver.CCPrintHeadersFilename = ::getenv("CC_PRINT_HEADERS_FILE");
424
Daniel Dunbarec9587d2009-04-17 01:54:00 +0000425 // Handle QA_OVERRIDE_GCC3_OPTIONS and CCC_ADD_ARGS, used for editing a
426 // command line behind the scenes.
Daniel Dunbarec9587d2009-04-17 01:54:00 +0000427 if (const char *OverrideStr = ::getenv("QA_OVERRIDE_GCC3_OPTIONS")) {
428 // FIXME: Driver shouldn't take extra initial argument.
Rafael Espindola8a1af322010-07-19 15:20:12 +0000429 ApplyQAOverride(argv, OverrideStr, SavedStrings);
Daniel Dunbarec9587d2009-04-17 01:54:00 +0000430 } else if (const char *Cur = ::getenv("CCC_ADD_ARGS")) {
Daniel Dunbare5be6da2009-04-01 19:08:46 +0000431 // FIXME: Driver shouldn't take extra initial argument.
Rafael Espindola8a1af322010-07-19 15:20:12 +0000432 std::vector<const char*> ExtraArgs;
Daniel Dunbare5be6da2009-04-01 19:08:46 +0000433
434 for (;;) {
435 const char *Next = strchr(Cur, ',');
Daniel Dunbar237a31b2009-07-17 18:10:27 +0000436
Daniel Dunbare5be6da2009-04-01 19:08:46 +0000437 if (Next) {
Rafael Espindola8a1af322010-07-19 15:20:12 +0000438 ExtraArgs.push_back(SaveStringInSet(SavedStrings,
439 std::string(Cur, Next)));
Daniel Dunbare5be6da2009-04-01 19:08:46 +0000440 Cur = Next + 1;
441 } else {
Daniel Dunbarec9587d2009-04-17 01:54:00 +0000442 if (*Cur != '\0')
Rafael Espindola8a1af322010-07-19 15:20:12 +0000443 ExtraArgs.push_back(SaveStringInSet(SavedStrings, Cur));
Daniel Dunbare5be6da2009-04-01 19:08:46 +0000444 break;
445 }
446 }
447
Daniel Dunbare5d69672010-07-20 02:47:40 +0000448 argv.insert(&argv[1], ExtraArgs.begin(), ExtraArgs.end());
Rafael Espindola06e35d32010-07-18 22:03:55 +0000449 }
Daniel Dunbar3ede8d02009-03-02 19:59:07 +0000450
Daniel Dunbar5633c1e2010-08-01 22:29:47 +0000451 llvm::OwningPtr<Compilation> C(TheDriver.BuildCompilation(argv.size(),
452 &argv[0]));
Daniel Dunbaraf96def2009-03-21 00:40:53 +0000453 int Res = 0;
454 if (C.get())
Daniel Dunbarc88a88f2009-07-01 20:03:04 +0000455 Res = TheDriver.ExecuteCompilation(*C);
Chris Lattner30bc7e82010-03-30 05:39:52 +0000456
457 // If any timers were active but haven't been destroyed yet, print their
458 // results now. This happens in -disable-free mode.
459 llvm::TimerGroup::printAll(llvm::errs());
460
Daniel Dunbar8f25c792009-03-18 01:38:48 +0000461 llvm::llvm_shutdown();
462
Daniel Dunbaraf96def2009-03-21 00:40:53 +0000463 return Res;
Daniel Dunbar3ede8d02009-03-02 19:59:07 +0000464}