blob: 01ef28ff38e18507ca9582d927962703d3a24107 [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- clang.cpp - C-Language Front-end ---------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner959e5be2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner4b009652007-07-25 00:24:17 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This utility may be invoked in the following manner:
11// clang --help - Output help info.
12// clang [options] - Read from stdin.
13// clang [options] file - Read from "file".
14// clang [options] file1 file2 - Read these files.
15//
16//===----------------------------------------------------------------------===//
17//
18// TODO: Options to support:
19//
20// -ffatal-errors
21// -ftabstop=width
22//
23//===----------------------------------------------------------------------===//
24
25#include "clang.h"
Chris Lattnereb8c9632007-10-07 06:04:32 +000026#include "ASTConsumers.h"
Chris Lattner4b009652007-07-25 00:24:17 +000027#include "TextDiagnosticBuffer.h"
28#include "TextDiagnosticPrinter.h"
Ted Kremenekac881932007-12-18 21:34:28 +000029#include "clang/AST/TranslationUnit.h"
Chris Lattnerf5e9db02008-02-06 02:01:47 +000030#include "clang/CodeGen/ModuleBuilder.h"
Chris Lattner0bed6ec2008-02-06 00:23:21 +000031#include "clang/Sema/ParseAST.h"
Chris Lattner1cc01712007-09-15 22:56:56 +000032#include "clang/AST/ASTConsumer.h"
Chris Lattner4b009652007-07-25 00:24:17 +000033#include "clang/Parse/Parser.h"
34#include "clang/Lex/HeaderSearch.h"
35#include "clang/Basic/FileManager.h"
36#include "clang/Basic/SourceManager.h"
37#include "clang/Basic/TargetInfo.h"
Chris Lattner8d72ee02008-02-06 01:42:25 +000038#include "llvm/Module.h"
Chris Lattnerac139d22007-12-15 23:20:07 +000039#include "llvm/ADT/SmallPtrSet.h"
Chris Lattner8d72ee02008-02-06 01:42:25 +000040#include "llvm/Bitcode/ReaderWriter.h"
Chris Lattner4b009652007-07-25 00:24:17 +000041#include "llvm/Support/CommandLine.h"
42#include "llvm/Support/MemoryBuffer.h"
43#include "llvm/System/Signals.h"
Ted Kremenek40499482007-12-03 22:06:55 +000044#include "llvm/Config/config.h"
Ted Kremenek0c7cd7a2007-12-20 19:47:16 +000045#include "llvm/ADT/OwningPtr.h"
Chris Lattner4b009652007-07-25 00:24:17 +000046#include <memory>
Chris Lattner8d72ee02008-02-06 01:42:25 +000047#include <fstream>
Chris Lattner4b009652007-07-25 00:24:17 +000048using namespace clang;
49
50//===----------------------------------------------------------------------===//
51// Global options.
52//===----------------------------------------------------------------------===//
53
54static llvm::cl::opt<bool>
55Verbose("v", llvm::cl::desc("Enable verbose output"));
56static llvm::cl::opt<bool>
Nate Begeman6acbedd2007-12-30 01:38:50 +000057Stats("print-stats",
58 llvm::cl::desc("Print performance metrics and statistics"));
Chris Lattner4b009652007-07-25 00:24:17 +000059
60enum ProgActions {
Chris Lattnerb429ae42007-10-11 00:43:27 +000061 RewriteTest, // Rewriter testing stuff.
Chris Lattner4b009652007-07-25 00:24:17 +000062 EmitLLVM, // Emit a .ll file.
Seo Sanghyeon550a1eb2007-12-24 01:52:34 +000063 EmitBC, // Emit a .bc file.
Ted Kremenek397de012007-12-13 00:37:31 +000064 SerializeAST, // Emit a .ast file.
Chris Lattner4045a8a2007-10-11 00:18:28 +000065 ASTPrint, // Parse ASTs and print them.
66 ASTDump, // Parse ASTs and dump them.
67 ASTView, // Parse ASTs and view them in Graphviz.
Ted Kremenek97f75312007-08-21 21:42:03 +000068 ParseCFGDump, // Parse ASTS. Build CFGs. Print CFGs.
Ted Kremeneke805c4a2007-09-06 23:00:42 +000069 ParseCFGView, // Parse ASTS. Build CFGs. View CFGs.
Ted Kremenekaa04c512007-09-06 00:17:54 +000070 AnalysisLiveVariables, // Print results of live-variable analysis.
Ted Kremenekd2500ab2008-01-16 18:18:48 +000071 AnalysisGRConstants, // Perform graph-reachability constant prop.
Ted Kremeneke805c4a2007-09-06 23:00:42 +000072 WarnDeadStores, // Run DeadStores checker on parsed ASTs.
Ted Kremenek0841c702007-09-25 18:37:20 +000073 WarnDeadStoresCheck, // Check diagnostics for "DeadStores".
Ted Kremenek0a03ce62007-09-17 20:49:30 +000074 WarnUninitVals, // Run UnitializedVariables checker.
Ted Kremenek221bb8d2007-10-16 23:37:27 +000075 TestSerialization, // Run experimental serialization code.
Chris Lattner4b009652007-07-25 00:24:17 +000076 ParsePrintCallbacks, // Parse and print each callback.
77 ParseSyntaxOnly, // Parse and perform semantic analysis.
78 ParseNoop, // Parse with noop callbacks.
79 RunPreprocessorOnly, // Just lex, no output.
80 PrintPreprocessedInput, // -E mode.
81 DumpTokens // Token dump mode.
82};
83
84static llvm::cl::opt<ProgActions>
85ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
86 llvm::cl::init(ParseSyntaxOnly),
87 llvm::cl::values(
88 clEnumValN(RunPreprocessorOnly, "Eonly",
89 "Just run preprocessor, no output (for timings)"),
90 clEnumValN(PrintPreprocessedInput, "E",
91 "Run preprocessor, emit preprocessed file"),
92 clEnumValN(DumpTokens, "dumptokens",
93 "Run preprocessor, dump internal rep of tokens"),
94 clEnumValN(ParseNoop, "parse-noop",
95 "Run parser with noop callbacks (for timings)"),
96 clEnumValN(ParseSyntaxOnly, "fsyntax-only",
97 "Run parser and perform semantic analysis"),
98 clEnumValN(ParsePrintCallbacks, "parse-print-callbacks",
99 "Run parser and print each callback invoked"),
Chris Lattner4045a8a2007-10-11 00:18:28 +0000100 clEnumValN(ASTPrint, "ast-print",
101 "Build ASTs and then pretty-print them"),
102 clEnumValN(ASTDump, "ast-dump",
103 "Build ASTs and then debug dump them"),
Chris Lattner664dd082007-10-11 00:37:43 +0000104 clEnumValN(ASTView, "ast-view",
Chris Lattner4045a8a2007-10-11 00:18:28 +0000105 "Build ASTs and view them with GraphViz."),
Ted Kremenek97f75312007-08-21 21:42:03 +0000106 clEnumValN(ParseCFGDump, "dump-cfg",
Ted Kremenekb3bb91b2007-08-29 21:56:09 +0000107 "Run parser, then build and print CFGs."),
108 clEnumValN(ParseCFGView, "view-cfg",
Ted Kremenekaa04c512007-09-06 00:17:54 +0000109 "Run parser, then build and view CFGs with Graphviz."),
110 clEnumValN(AnalysisLiveVariables, "dump-live-variables",
Ted Kremenek05334682007-09-06 21:26:58 +0000111 "Print results of live variable analysis."),
Ted Kremenek945fb562007-09-25 18:05:45 +0000112 clEnumValN(WarnDeadStores, "warn-dead-stores",
Ted Kremeneke805c4a2007-09-06 23:00:42 +0000113 "Flag warnings of stores to dead variables."),
Ted Kremenek945fb562007-09-25 18:05:45 +0000114 clEnumValN(WarnUninitVals, "warn-uninit-values",
Ted Kremenek0a03ce62007-09-17 20:49:30 +0000115 "Flag warnings of uses of unitialized variables."),
Ted Kremenek70ecf402008-01-16 18:21:49 +0000116 clEnumValN(AnalysisGRConstants, "grconstants",
Chris Lattner2528b5e2008-01-10 01:41:55 +0000117 "Perform path-sensitive constant propagation."),
Ted Kremenek221bb8d2007-10-16 23:37:27 +0000118 clEnumValN(TestSerialization, "test-pickling",
119 "Run prototype serializtion code."),
Chris Lattner4b009652007-07-25 00:24:17 +0000120 clEnumValN(EmitLLVM, "emit-llvm",
Ted Kremenek05334682007-09-06 21:26:58 +0000121 "Build ASTs then convert to LLVM, emit .ll file"),
Seo Sanghyeon550a1eb2007-12-24 01:52:34 +0000122 clEnumValN(EmitBC, "emit-llvm-bc",
123 "Build ASTs then convert to LLVM, emit .bc file"),
Ted Kremenekd01eae62007-12-19 19:47:59 +0000124 clEnumValN(SerializeAST, "serialize",
Ted Kremenek397de012007-12-13 00:37:31 +0000125 "Build ASTs and emit .ast file"),
Chris Lattnerb429ae42007-10-11 00:43:27 +0000126 clEnumValN(RewriteTest, "rewrite-test",
127 "Playground for the code rewriter"),
Chris Lattner4b009652007-07-25 00:24:17 +0000128 clEnumValEnd));
129
Ted Kremenekd01eae62007-12-19 19:47:59 +0000130
131static llvm::cl::opt<std::string>
132OutputFile("o",
Ted Kremenek09b3f0d2007-12-19 19:50:41 +0000133 llvm::cl::value_desc("path"),
Ted Kremenekd01eae62007-12-19 19:47:59 +0000134 llvm::cl::desc("Specify output file (for --serialize, this is a directory)"));
135
Ted Kremenek10389cf2007-09-26 19:42:19 +0000136static llvm::cl::opt<bool>
137VerifyDiagnostics("verify",
138 llvm::cl::desc("Verify emitted diagnostics and warnings."));
139
Chris Lattner4b009652007-07-25 00:24:17 +0000140//===----------------------------------------------------------------------===//
141// Language Options
142//===----------------------------------------------------------------------===//
143
144enum LangKind {
145 langkind_unspecified,
146 langkind_c,
147 langkind_c_cpp,
148 langkind_cxx,
149 langkind_cxx_cpp,
150 langkind_objc,
151 langkind_objc_cpp,
152 langkind_objcxx,
153 langkind_objcxx_cpp
154};
155
156/* TODO: GCC also accepts:
157 c-header c++-header objective-c-header objective-c++-header
158 assembler assembler-with-cpp
159 ada, f77*, ratfor (!), f95, java, treelang
160 */
161static llvm::cl::opt<LangKind>
162BaseLang("x", llvm::cl::desc("Base language to compile"),
163 llvm::cl::init(langkind_unspecified),
164 llvm::cl::values(clEnumValN(langkind_c, "c", "C"),
165 clEnumValN(langkind_cxx, "c++", "C++"),
166 clEnumValN(langkind_objc, "objective-c", "Objective C"),
167 clEnumValN(langkind_objcxx,"objective-c++","Objective C++"),
168 clEnumValN(langkind_c_cpp, "c-cpp-output",
169 "Preprocessed C"),
170 clEnumValN(langkind_cxx_cpp, "c++-cpp-output",
171 "Preprocessed C++"),
172 clEnumValN(langkind_objc_cpp, "objective-c-cpp-output",
173 "Preprocessed Objective C"),
174 clEnumValN(langkind_objcxx_cpp,"objective-c++-cpp-output",
175 "Preprocessed Objective C++"),
176 clEnumValEnd));
177
178static llvm::cl::opt<bool>
179LangObjC("ObjC", llvm::cl::desc("Set base language to Objective-C"),
180 llvm::cl::Hidden);
181static llvm::cl::opt<bool>
182LangObjCXX("ObjC++", llvm::cl::desc("Set base language to Objective-C++"),
183 llvm::cl::Hidden);
184
Ted Kremenek11ad8952007-12-05 23:49:08 +0000185/// InitializeBaseLanguage - Handle the -x foo options.
186static void InitializeBaseLanguage() {
187 if (LangObjC)
188 BaseLang = langkind_objc;
189 else if (LangObjCXX)
190 BaseLang = langkind_objcxx;
191}
192
193static LangKind GetLanguage(const std::string &Filename) {
194 if (BaseLang != langkind_unspecified)
195 return BaseLang;
196
197 std::string::size_type DotPos = Filename.rfind('.');
198
199 if (DotPos == std::string::npos) {
200 BaseLang = langkind_c; // Default to C if no extension.
Chris Lattner4eac0502008-01-04 19:12:28 +0000201 return langkind_c;
Chris Lattner4b009652007-07-25 00:24:17 +0000202 }
203
Ted Kremenek11ad8952007-12-05 23:49:08 +0000204 std::string Ext = std::string(Filename.begin()+DotPos+1, Filename.end());
205 // C header: .h
206 // C++ header: .hh or .H;
207 // assembler no preprocessing: .s
208 // assembler: .S
209 if (Ext == "c")
210 return langkind_c;
211 else if (Ext == "i")
212 return langkind_c_cpp;
213 else if (Ext == "ii")
214 return langkind_cxx_cpp;
215 else if (Ext == "m")
216 return langkind_objc;
217 else if (Ext == "mi")
218 return langkind_objc_cpp;
219 else if (Ext == "mm" || Ext == "M")
220 return langkind_objcxx;
221 else if (Ext == "mii")
222 return langkind_objcxx_cpp;
223 else if (Ext == "C" || Ext == "cc" || Ext == "cpp" || Ext == "CPP" ||
224 Ext == "c++" || Ext == "cp" || Ext == "cxx")
225 return langkind_cxx;
226 else
227 return langkind_c;
228}
229
230
231static void InitializeLangOptions(LangOptions &Options, LangKind LK) {
Chris Lattner4b009652007-07-25 00:24:17 +0000232 // FIXME: implement -fpreprocessed mode.
233 bool NoPreprocess = false;
234
Ted Kremenek11ad8952007-12-05 23:49:08 +0000235 switch (LK) {
Chris Lattner4b009652007-07-25 00:24:17 +0000236 default: assert(0 && "Unknown language kind!");
237 case langkind_c_cpp:
238 NoPreprocess = true;
239 // FALLTHROUGH
240 case langkind_c:
241 break;
242 case langkind_cxx_cpp:
243 NoPreprocess = true;
244 // FALLTHROUGH
245 case langkind_cxx:
246 Options.CPlusPlus = 1;
247 break;
248 case langkind_objc_cpp:
249 NoPreprocess = true;
250 // FALLTHROUGH
251 case langkind_objc:
252 Options.ObjC1 = Options.ObjC2 = 1;
253 break;
254 case langkind_objcxx_cpp:
255 NoPreprocess = true;
256 // FALLTHROUGH
257 case langkind_objcxx:
258 Options.ObjC1 = Options.ObjC2 = 1;
259 Options.CPlusPlus = 1;
260 break;
261 }
262}
263
264/// LangStds - Language standards we support.
265enum LangStds {
266 lang_unspecified,
267 lang_c89, lang_c94, lang_c99,
268 lang_gnu89, lang_gnu99,
269 lang_cxx98, lang_gnucxx98,
270 lang_cxx0x, lang_gnucxx0x
271};
272
273static llvm::cl::opt<LangStds>
274LangStd("std", llvm::cl::desc("Language standard to compile for"),
275 llvm::cl::init(lang_unspecified),
276 llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
277 clEnumValN(lang_c89, "c90", "ISO C 1990"),
278 clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
279 clEnumValN(lang_c94, "iso9899:199409",
280 "ISO C 1990 with amendment 1"),
281 clEnumValN(lang_c99, "c99", "ISO C 1999"),
282// clEnumValN(lang_c99, "c9x", "ISO C 1999"),
283 clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
284// clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
285 clEnumValN(lang_gnu89, "gnu89",
286 "ISO C 1990 with GNU extensions (default for C)"),
287 clEnumValN(lang_gnu99, "gnu99",
288 "ISO C 1999 with GNU extensions"),
289 clEnumValN(lang_gnu99, "gnu9x",
290 "ISO C 1999 with GNU extensions"),
291 clEnumValN(lang_cxx98, "c++98",
292 "ISO C++ 1998 with amendments"),
293 clEnumValN(lang_gnucxx98, "gnu++98",
294 "ISO C++ 1998 with amendments and GNU "
295 "extensions (default for C++)"),
296 clEnumValN(lang_cxx0x, "c++0x",
297 "Upcoming ISO C++ 200x with amendments"),
298 clEnumValN(lang_gnucxx0x, "gnu++0x",
299 "Upcoming ISO C++ 200x with amendments and GNU "
300 "extensions (default for C++)"),
301 clEnumValEnd));
302
303static llvm::cl::opt<bool>
304NoOperatorNames("fno-operator-names",
305 llvm::cl::desc("Do not treat C++ operator name keywords as "
306 "synonyms for operators"));
307
Anders Carlsson55bfe0d2007-10-15 02:50:23 +0000308static llvm::cl::opt<bool>
309PascalStrings("fpascal-strings",
310 llvm::cl::desc("Recognize and construct Pascal-style "
311 "string literals"));
Chris Lattnerdb6be562007-11-28 05:34:05 +0000312
313static llvm::cl::opt<bool>
314WritableStrings("fwritable-strings",
315 llvm::cl::desc("Store string literals as writable data."));
Anders Carlssone87cd982007-11-30 04:21:22 +0000316
317static llvm::cl::opt<bool>
318LaxVectorConversions("flax-vector-conversions",
319 llvm::cl::desc("Allow implicit conversions between vectors"
320 " with a different number of elements or "
321 "different element types."));
Chris Lattner4b009652007-07-25 00:24:17 +0000322// FIXME: add:
323// -ansi
324// -trigraphs
325// -fdollars-in-identifiers
Anders Carlsson55bfe0d2007-10-15 02:50:23 +0000326// -fpascal-strings
Ted Kremenek11ad8952007-12-05 23:49:08 +0000327static void InitializeLanguageStandard(LangOptions &Options, LangKind LK) {
Chris Lattner4b009652007-07-25 00:24:17 +0000328 if (LangStd == lang_unspecified) {
329 // Based on the base language, pick one.
Ted Kremenek11ad8952007-12-05 23:49:08 +0000330 switch (LK) {
Chris Lattner4b009652007-07-25 00:24:17 +0000331 default: assert(0 && "Unknown base language");
332 case langkind_c:
333 case langkind_c_cpp:
334 case langkind_objc:
335 case langkind_objc_cpp:
336 LangStd = lang_gnu99;
337 break;
338 case langkind_cxx:
339 case langkind_cxx_cpp:
340 case langkind_objcxx:
341 case langkind_objcxx_cpp:
342 LangStd = lang_gnucxx98;
343 break;
344 }
345 }
346
347 switch (LangStd) {
348 default: assert(0 && "Unknown language standard!");
349
350 // Fall through from newer standards to older ones. This isn't really right.
351 // FIXME: Enable specifically the right features based on the language stds.
352 case lang_gnucxx0x:
353 case lang_cxx0x:
354 Options.CPlusPlus0x = 1;
355 // FALL THROUGH
356 case lang_gnucxx98:
357 case lang_cxx98:
358 Options.CPlusPlus = 1;
359 Options.CXXOperatorNames = !NoOperatorNames;
Nate Begemanca893342007-11-15 07:30:50 +0000360 Options.Boolean = 1;
Chris Lattner4b009652007-07-25 00:24:17 +0000361 // FALL THROUGH.
362 case lang_gnu99:
363 case lang_c99:
364 Options.Digraphs = 1;
365 Options.C99 = 1;
366 Options.HexFloats = 1;
367 // FALL THROUGH.
368 case lang_gnu89:
369 Options.BCPLComment = 1; // Only for C99/C++.
370 // FALL THROUGH.
371 case lang_c94:
372 case lang_c89:
373 break;
374 }
375
376 Options.Trigraphs = 1; // -trigraphs or -ansi
377 Options.DollarIdents = 1; // FIXME: Really a target property.
Anders Carlsson55bfe0d2007-10-15 02:50:23 +0000378 Options.PascalStrings = PascalStrings;
Chris Lattnerdb6be562007-11-28 05:34:05 +0000379 Options.WritableStrings = WritableStrings;
Anders Carlssone87cd982007-11-30 04:21:22 +0000380 Options.LaxVectorConversions = LaxVectorConversions;
Chris Lattner4b009652007-07-25 00:24:17 +0000381}
382
383//===----------------------------------------------------------------------===//
384// Our DiagnosticClient implementation
385//===----------------------------------------------------------------------===//
386
387// FIXME: Werror should take a list of things, -Werror=foo,bar
388static llvm::cl::opt<bool>
389WarningsAsErrors("Werror", llvm::cl::desc("Treat all warnings as errors"));
390
391static llvm::cl::opt<bool>
392WarnOnExtensions("pedantic", llvm::cl::init(false),
393 llvm::cl::desc("Issue a warning on uses of GCC extensions"));
394
395static llvm::cl::opt<bool>
396ErrorOnExtensions("pedantic-errors",
397 llvm::cl::desc("Issue an error on uses of GCC extensions"));
398
399static llvm::cl::opt<bool>
400WarnUnusedMacros("Wunused_macros",
401 llvm::cl::desc("Warn for unused macros in the main translation unit"));
402
Ted Kremenek24f59fb2007-11-13 18:37:02 +0000403static llvm::cl::opt<bool>
404WarnFloatEqual("Wfloat-equal",
405 llvm::cl::desc("Warn about equality comparisons of floating point values."));
406
Ted Kremenek4b57bc72007-12-17 17:50:07 +0000407static llvm::cl::opt<bool>
408WarnNoFormatNonLiteral("Wno-format-nonliteral",
409 llvm::cl::desc("Do not warn about non-literal format strings."));
410
Chris Lattnera616ee32008-01-23 17:19:46 +0000411static llvm::cl::opt<bool>
412WarnUndefMacros("Wundef",
413 llvm::cl::desc("Warn on use of undefined macros in #if's"));
414
415
Chris Lattner4b009652007-07-25 00:24:17 +0000416/// InitializeDiagnostics - Initialize the diagnostic object, based on the
417/// current command line option settings.
418static void InitializeDiagnostics(Diagnostic &Diags) {
419 Diags.setWarningsAsErrors(WarningsAsErrors);
420 Diags.setWarnOnExtensions(WarnOnExtensions);
421 Diags.setErrorOnExtensions(ErrorOnExtensions);
422
423 // Silence the "macro is not used" warning unless requested.
424 if (!WarnUnusedMacros)
425 Diags.setDiagnosticMapping(diag::pp_macro_not_used, diag::MAP_IGNORE);
Ted Kremenek24f59fb2007-11-13 18:37:02 +0000426
427 // Silence "floating point comparison" warnings unless requested.
428 if (!WarnFloatEqual)
429 Diags.setDiagnosticMapping(diag::warn_floatingpoint_eq, diag::MAP_IGNORE);
Ted Kremenek4b57bc72007-12-17 17:50:07 +0000430
431 // Silence "format string is not a string literal" warnings if requested
432 if (WarnNoFormatNonLiteral)
Ted Kremenekf0a6ae02007-12-17 17:50:39 +0000433 Diags.setDiagnosticMapping(diag::warn_printf_not_string_constant,
434 diag::MAP_IGNORE);
Chris Lattnera616ee32008-01-23 17:19:46 +0000435 if (!WarnUndefMacros)
436 Diags.setDiagnosticMapping(diag::warn_pp_undef_identifier,diag::MAP_IGNORE);
Chris Lattner4b009652007-07-25 00:24:17 +0000437}
438
439//===----------------------------------------------------------------------===//
Ted Kremenek40499482007-12-03 22:06:55 +0000440// Target Triple Processing.
441//===----------------------------------------------------------------------===//
442
443static llvm::cl::opt<std::string>
444TargetTriple("triple",
445 llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)."));
446
447static llvm::cl::list<std::string>
448Archs("arch",
449 llvm::cl::desc("Specify target architecture (e.g. i686)."));
450
451namespace {
452 class TripleProcessor {
453 llvm::StringMap<char> TriplesProcessed;
454 std::vector<std::string>& triples;
455 public:
456 TripleProcessor(std::vector<std::string>& t) : triples(t) {}
457
458 void addTriple(const std::string& t) {
459 if (TriplesProcessed.find(t.c_str(),t.c_str()+t.size()) ==
460 TriplesProcessed.end()) {
461 triples.push_back(t);
462 TriplesProcessed.GetOrCreateValue(t.c_str(),t.c_str()+t.size());
463 }
464 }
465 };
466}
467
468static void CreateTargetTriples(std::vector<std::string>& triples) {
Ted Kremenek40499482007-12-03 22:06:55 +0000469 // Initialize base triple. If a -triple option has been specified, use
470 // that triple. Otherwise, default to the host triple.
Chris Lattner210c0cc2007-12-12 05:01:48 +0000471 std::string Triple = TargetTriple;
472 if (Triple.empty()) Triple = LLVM_HOSTTRIPLE;
Ted Kremenek40499482007-12-03 22:06:55 +0000473
474 // Decompose the base triple into "arch" and suffix.
Chris Lattner210c0cc2007-12-12 05:01:48 +0000475 std::string::size_type firstDash = Triple.find("-");
Ted Kremenek40499482007-12-03 22:06:55 +0000476
Ted Kremenek0a8ce9d2007-12-03 22:11:31 +0000477 if (firstDash == std::string::npos) {
478 fprintf(stderr,
479 "Malformed target triple: \"%s\" ('-' could not be found).\n",
Chris Lattner210c0cc2007-12-12 05:01:48 +0000480 Triple.c_str());
481 exit(1);
Ted Kremenek0a8ce9d2007-12-03 22:11:31 +0000482 }
Ted Kremenek40499482007-12-03 22:06:55 +0000483
Chris Lattner210c0cc2007-12-12 05:01:48 +0000484 std::string suffix(Triple, firstDash+1);
Ted Kremenek0a8ce9d2007-12-03 22:11:31 +0000485
486 if (suffix.empty()) {
Chris Lattner210c0cc2007-12-12 05:01:48 +0000487 fprintf(stderr, "Malformed target triple: \"%s\" (no vendor or OS).\n",
488 Triple.c_str());
489 exit(1);
Ted Kremenek0a8ce9d2007-12-03 22:11:31 +0000490 }
Ted Kremenek40499482007-12-03 22:06:55 +0000491
492 // Create triple cacher.
493 TripleProcessor tp(triples);
494
495 // Add the primary triple to our set of triples if we are using the
496 // host-triple with no archs or using a specified target triple.
497 if (!TargetTriple.getValue().empty() || Archs.empty())
Chris Lattner210c0cc2007-12-12 05:01:48 +0000498 tp.addTriple(Triple);
Ted Kremenek40499482007-12-03 22:06:55 +0000499
500 for (unsigned i = 0, e = Archs.size(); i !=e; ++i)
501 tp.addTriple(Archs[i] + "-" + suffix);
502}
503
504//===----------------------------------------------------------------------===//
Chris Lattner4b009652007-07-25 00:24:17 +0000505// Preprocessor Initialization
506//===----------------------------------------------------------------------===//
507
508// FIXME: Preprocessor builtins to support.
509// -A... - Play with #assertions
510// -undef - Undefine all predefined macros
511
512static llvm::cl::list<std::string>
513D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
514 llvm::cl::desc("Predefine the specified macro"));
515static llvm::cl::list<std::string>
516U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
517 llvm::cl::desc("Undefine the specified macro"));
518
Chris Lattner008da782008-01-10 01:53:41 +0000519static llvm::cl::list<std::string>
520ImplicitIncludes("include", llvm::cl::value_desc("file"),
521 llvm::cl::desc("Include file before parsing"));
522
523
Chris Lattner4b009652007-07-25 00:24:17 +0000524// Append a #define line to Buf for Macro. Macro should be of the form XXX,
525// in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
526// "#define XXX Y z W". To get a #define with no value, use "XXX=".
527static void DefineBuiltinMacro(std::vector<char> &Buf, const char *Macro,
528 const char *Command = "#define ") {
529 Buf.insert(Buf.end(), Command, Command+strlen(Command));
530 if (const char *Equal = strchr(Macro, '=')) {
531 // Turn the = into ' '.
532 Buf.insert(Buf.end(), Macro, Equal);
533 Buf.push_back(' ');
534 Buf.insert(Buf.end(), Equal+1, Equal+strlen(Equal));
535 } else {
536 // Push "macroname 1".
537 Buf.insert(Buf.end(), Macro, Macro+strlen(Macro));
538 Buf.push_back(' ');
539 Buf.push_back('1');
540 }
541 Buf.push_back('\n');
542}
543
Chris Lattner008da782008-01-10 01:53:41 +0000544/// AddImplicitInclude - Add an implicit #include of the specified file to the
545/// predefines buffer.
546static void AddImplicitInclude(std::vector<char> &Buf, const std::string &File){
547 const char *Inc = "#include \"";
548 Buf.insert(Buf.end(), Inc, Inc+strlen(Inc));
549 Buf.insert(Buf.end(), File.begin(), File.end());
550 Buf.push_back('"');
551 Buf.push_back('\n');
552}
553
Chris Lattner4b009652007-07-25 00:24:17 +0000554
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000555/// InitializePreprocessor - Initialize the preprocessor getting it and the
556/// environment ready to process a single file. This returns the file ID for the
557/// input file. If a failure happens, it returns 0.
558///
559static unsigned InitializePreprocessor(Preprocessor &PP,
560 const std::string &InFile,
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000561 std::vector<char> &PredefineBuffer) {
Chris Lattner4b009652007-07-25 00:24:17 +0000562
Chris Lattner968982d2007-12-15 20:48:40 +0000563 FileManager &FileMgr = PP.getFileManager();
Chris Lattner4b009652007-07-25 00:24:17 +0000564
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000565 // Figure out where to get and map in the main file.
Chris Lattner968982d2007-12-15 20:48:40 +0000566 SourceManager &SourceMgr = PP.getSourceManager();
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000567 if (InFile != "-") {
568 const FileEntry *File = FileMgr.getFile(InFile);
Ted Kremenek6d1d3ac2007-12-19 23:48:45 +0000569 if (File) SourceMgr.createMainFileID(File, SourceLocation());
570 if (SourceMgr.getMainFileID() == 0) {
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000571 fprintf(stderr, "Error reading '%s'!\n",InFile.c_str());
572 return 0;
573 }
574 } else {
575 llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
Ted Kremenek6d1d3ac2007-12-19 23:48:45 +0000576 if (SB) SourceMgr.createMainFileIDForMemBuffer(SB);
577 if (SourceMgr.getMainFileID() == 0) {
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000578 fprintf(stderr, "Error reading standard input! Empty?\n");
579 return 0;
580 }
Chris Lattner4b009652007-07-25 00:24:17 +0000581 }
582
Chris Lattner4b009652007-07-25 00:24:17 +0000583 // Add macros from the command line.
584 // FIXME: Should traverse the #define/#undef lists in parallel.
585 for (unsigned i = 0, e = D_macros.size(); i != e; ++i)
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000586 DefineBuiltinMacro(PredefineBuffer, D_macros[i].c_str());
Chris Lattner4b009652007-07-25 00:24:17 +0000587 for (unsigned i = 0, e = U_macros.size(); i != e; ++i)
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000588 DefineBuiltinMacro(PredefineBuffer, U_macros[i].c_str(), "#undef ");
589
Chris Lattner008da782008-01-10 01:53:41 +0000590 // FIXME: Read any files specified by -imacros.
591
592 // Add implicit #includes from -include.
593 for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
594 AddImplicitInclude(PredefineBuffer, ImplicitIncludes[i]);
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000595
596 // Null terminate PredefinedBuffer and add it.
597 PredefineBuffer.push_back(0);
598 PP.setPredefines(&PredefineBuffer[0]);
599
600 // Once we've read this, we're done.
Ted Kremenek6d1d3ac2007-12-19 23:48:45 +0000601 return SourceMgr.getMainFileID();
Chris Lattner4b009652007-07-25 00:24:17 +0000602}
603
604//===----------------------------------------------------------------------===//
605// Preprocessor include path information.
606//===----------------------------------------------------------------------===//
607
608// This tool exports a large number of command line options to control how the
609// preprocessor searches for header files. At root, however, the Preprocessor
610// object takes a very simple interface: a list of directories to search for
611//
612// FIXME: -nostdinc,-nostdinc++
Chris Lattnerae3dcc02007-08-26 17:47:35 +0000613// FIXME: -imultilib
Chris Lattner4b009652007-07-25 00:24:17 +0000614//
Chris Lattner008da782008-01-10 01:53:41 +0000615// FIXME: -imacros
Chris Lattner4b009652007-07-25 00:24:17 +0000616
617static llvm::cl::opt<bool>
618nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories"));
619
620// Various command line options. These four add directories to each chain.
621static llvm::cl::list<std::string>
622F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
623 llvm::cl::desc("Add directory to framework include search path"));
624static llvm::cl::list<std::string>
625I_dirs("I", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
626 llvm::cl::desc("Add directory to include search path"));
627static llvm::cl::list<std::string>
628idirafter_dirs("idirafter", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
629 llvm::cl::desc("Add directory to AFTER include search path"));
630static llvm::cl::list<std::string>
631iquote_dirs("iquote", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
632 llvm::cl::desc("Add directory to QUOTE include search path"));
633static llvm::cl::list<std::string>
634isystem_dirs("isystem", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
635 llvm::cl::desc("Add directory to SYSTEM include search path"));
636
637// These handle -iprefix/-iwithprefix/-iwithprefixbefore.
638static llvm::cl::list<std::string>
639iprefix_vals("iprefix", llvm::cl::value_desc("prefix"), llvm::cl::Prefix,
640 llvm::cl::desc("Set the -iwithprefix/-iwithprefixbefore prefix"));
641static llvm::cl::list<std::string>
642iwithprefix_vals("iwithprefix", llvm::cl::value_desc("dir"), llvm::cl::Prefix,
643 llvm::cl::desc("Set directory to SYSTEM include search path with prefix"));
644static llvm::cl::list<std::string>
645iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"),
646 llvm::cl::Prefix,
647 llvm::cl::desc("Set directory to include search path with prefix"));
648
Chris Lattnerae3dcc02007-08-26 17:47:35 +0000649static llvm::cl::opt<std::string>
650isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"),
651 llvm::cl::desc("Set the system root directory (usually /)"));
652
Chris Lattner4b009652007-07-25 00:24:17 +0000653// Finally, implement the code that groks the options above.
654enum IncludeDirGroup {
655 Quoted = 0,
656 Angled,
657 System,
658 After
659};
660
661static std::vector<DirectoryLookup> IncludeGroup[4];
662
663/// AddPath - Add the specified path to the specified group list.
664///
665static void AddPath(const std::string &Path, IncludeDirGroup Group,
666 bool isCXXAware, bool isUserSupplied,
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000667 bool isFramework, HeaderSearch &HS) {
Chris Lattnerc8d80bb2007-12-09 00:39:55 +0000668 assert(!Path.empty() && "can't handle empty path here");
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000669 FileManager &FM = HS.getFileMgr();
Chris Lattnerc8d80bb2007-12-09 00:39:55 +0000670
Chris Lattner2a4e2ad2007-12-17 05:59:27 +0000671 // Compute the actual path, taking into consideration -isysroot.
672 llvm::SmallString<256> MappedPath;
Chris Lattnerae3dcc02007-08-26 17:47:35 +0000673
Chris Lattner2a4e2ad2007-12-17 05:59:27 +0000674 // Handle isysroot.
675 if (Group == System) {
Chris Lattner2a2702a2007-12-17 06:51:34 +0000676 // FIXME: Portability. This should be a sys::Path interface, this doesn't
677 // handle things like C:\ right, nor win32 \\network\device\blah.
Chris Lattner2a4e2ad2007-12-17 05:59:27 +0000678 if (isysroot.size() != 1 || isysroot[0] != '/') // Add isysroot if present.
679 MappedPath.append(isysroot.begin(), isysroot.end());
680 if (Path[0] != '/') // If in the system group, add a /.
681 MappedPath.push_back('/');
Chris Lattner4b009652007-07-25 00:24:17 +0000682 }
683
Chris Lattner2a4e2ad2007-12-17 05:59:27 +0000684 MappedPath.append(Path.begin(), Path.end());
685
686 // Compute the DirectoryLookup type.
Chris Lattner4b009652007-07-25 00:24:17 +0000687 DirectoryLookup::DirType Type;
688 if (Group == Quoted || Group == Angled)
689 Type = DirectoryLookup::NormalHeaderDir;
690 else if (isCXXAware)
691 Type = DirectoryLookup::SystemHeaderDir;
692 else
693 Type = DirectoryLookup::ExternCSystemHeaderDir;
694
Chris Lattner2a4e2ad2007-12-17 05:59:27 +0000695
696 // If the directory exists, add it.
697 if (const DirectoryEntry *DE = FM.getDirectory(&MappedPath[0],
698 &MappedPath[0]+
699 MappedPath.size())) {
700 IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied,
701 isFramework));
702 return;
703 }
704
Chris Lattnerb7426782007-12-17 07:52:39 +0000705 // Check to see if this is an apple-style headermap (which are not allowed to
706 // be frameworks).
707 if (!isFramework) {
708 if (const FileEntry *FE = FM.getFile(&MappedPath[0],
709 &MappedPath[0]+MappedPath.size())) {
Chris Lattner9af36d32007-12-17 18:34:53 +0000710 if (const HeaderMap *HM = HS.CreateHeaderMap(FE)) {
711 // It is a headermap, add it to the search path.
Chris Lattnerb7426782007-12-17 07:52:39 +0000712 IncludeGroup[Group].push_back(DirectoryLookup(HM, Type,isUserSupplied));
713 return;
714 }
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000715 }
716 }
717
Chris Lattner2a4e2ad2007-12-17 05:59:27 +0000718 if (Verbose)
719 fprintf(stderr, "ignoring nonexistent directory \"%s\"\n", Path.c_str());
Chris Lattner4b009652007-07-25 00:24:17 +0000720}
721
722/// RemoveDuplicates - If there are duplicate directory entries in the specified
723/// search list, remove the later (dead) ones.
724static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList) {
Chris Lattnerac139d22007-12-15 23:20:07 +0000725 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
Chris Lattnerb7426782007-12-17 07:52:39 +0000726 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
Chris Lattnercf33e932007-12-17 06:44:29 +0000727 llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
Chris Lattner4b009652007-07-25 00:24:17 +0000728 for (unsigned i = 0; i != SearchList.size(); ++i) {
Chris Lattnercf33e932007-12-17 06:44:29 +0000729 if (SearchList[i].isNormalDir()) {
730 // If this isn't the first time we've seen this dir, remove it.
731 if (SeenDirs.insert(SearchList[i].getDir()))
732 continue;
733
Chris Lattner4b009652007-07-25 00:24:17 +0000734 if (Verbose)
735 fprintf(stderr, "ignoring duplicate directory \"%s\"\n",
736 SearchList[i].getDir()->getName());
Chris Lattnerb7426782007-12-17 07:52:39 +0000737 } else if (SearchList[i].isFramework()) {
738 // If this isn't the first time we've seen this framework dir, remove it.
739 if (SeenFrameworkDirs.insert(SearchList[i].getFrameworkDir()))
740 continue;
741
742 if (Verbose)
743 fprintf(stderr, "ignoring duplicate framework \"%s\"\n",
744 SearchList[i].getFrameworkDir()->getName());
745
Chris Lattnercf33e932007-12-17 06:44:29 +0000746 } else {
747 assert(SearchList[i].isHeaderMap() && "Not a headermap or normal dir?");
748 // If this isn't the first time we've seen this headermap, remove it.
749 if (SeenHeaderMaps.insert(SearchList[i].getHeaderMap()))
750 continue;
751
752 if (Verbose)
753 fprintf(stderr, "ignoring duplicate directory \"%s\"\n",
754 SearchList[i].getDir()->getName());
Chris Lattner4b009652007-07-25 00:24:17 +0000755 }
Chris Lattnercf33e932007-12-17 06:44:29 +0000756
757 // This is reached if the current entry is a duplicate.
758 SearchList.erase(SearchList.begin()+i);
759 --i;
Chris Lattner4b009652007-07-25 00:24:17 +0000760 }
761}
762
763/// InitializeIncludePaths - Process the -I options and set them in the
764/// HeaderSearch object.
765static void InitializeIncludePaths(HeaderSearch &Headers, FileManager &FM,
Chris Lattner45a56e02007-12-05 23:24:17 +0000766 const LangOptions &Lang) {
Chris Lattner4b009652007-07-25 00:24:17 +0000767 // Handle -F... options.
768 for (unsigned i = 0, e = F_dirs.size(); i != e; ++i)
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000769 AddPath(F_dirs[i], Angled, false, true, true, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000770
771 // Handle -I... options.
Chris Lattner45a56e02007-12-05 23:24:17 +0000772 for (unsigned i = 0, e = I_dirs.size(); i != e; ++i)
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000773 AddPath(I_dirs[i], Angled, false, true, false, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000774
775 // Handle -idirafter... options.
776 for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i)
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000777 AddPath(idirafter_dirs[i], After, false, true, false, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000778
779 // Handle -iquote... options.
780 for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i)
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000781 AddPath(iquote_dirs[i], Quoted, false, true, false, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000782
783 // Handle -isystem... options.
784 for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i)
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000785 AddPath(isystem_dirs[i], System, false, true, false, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000786
787 // Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in
788 // parallel, processing the values in order of occurance to get the right
789 // prefixes.
790 {
791 std::string Prefix = ""; // FIXME: this isn't the correct default prefix.
792 unsigned iprefix_idx = 0;
793 unsigned iwithprefix_idx = 0;
794 unsigned iwithprefixbefore_idx = 0;
795 bool iprefix_done = iprefix_vals.empty();
796 bool iwithprefix_done = iwithprefix_vals.empty();
797 bool iwithprefixbefore_done = iwithprefixbefore_vals.empty();
798 while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) {
799 if (!iprefix_done &&
800 (iwithprefix_done ||
801 iprefix_vals.getPosition(iprefix_idx) <
802 iwithprefix_vals.getPosition(iwithprefix_idx)) &&
803 (iwithprefixbefore_done ||
804 iprefix_vals.getPosition(iprefix_idx) <
805 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
806 Prefix = iprefix_vals[iprefix_idx];
807 ++iprefix_idx;
808 iprefix_done = iprefix_idx == iprefix_vals.size();
809 } else if (!iwithprefix_done &&
810 (iwithprefixbefore_done ||
811 iwithprefix_vals.getPosition(iwithprefix_idx) <
812 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
813 AddPath(Prefix+iwithprefix_vals[iwithprefix_idx],
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000814 System, false, false, false, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000815 ++iwithprefix_idx;
816 iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size();
817 } else {
818 AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx],
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000819 Angled, false, false, false, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000820 ++iwithprefixbefore_idx;
821 iwithprefixbefore_done =
822 iwithprefixbefore_idx == iwithprefixbefore_vals.size();
823 }
824 }
825 }
826
827 // FIXME: Add contents of the CPATH, C_INCLUDE_PATH, CPLUS_INCLUDE_PATH,
828 // OBJC_INCLUDE_PATH, OBJCPLUS_INCLUDE_PATH environment variables.
829
830 // FIXME: temporary hack: hard-coded paths.
831 // FIXME: get these from the target?
832 if (!nostdinc) {
833 if (Lang.CPlusPlus) {
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000834 AddPath("/usr/include/c++/4.0.0", System, true, false, false, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000835 AddPath("/usr/include/c++/4.0.0/i686-apple-darwin8", System, true, false,
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000836 false, Headers);
837 AddPath("/usr/include/c++/4.0.0/backward", System, true, false, false,
838 Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000839 }
840
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000841 AddPath("/usr/local/include", System, false, false, false, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000842 // leopard
843 AddPath("/usr/lib/gcc/i686-apple-darwin9/4.0.1/include", System,
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000844 false, false, false, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000845 AddPath("/usr/lib/gcc/powerpc-apple-darwin9/4.0.1/include",
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000846 System, false, false, false, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000847 AddPath("/usr/lib/gcc/powerpc-apple-darwin9/"
848 "4.0.1/../../../../powerpc-apple-darwin0/include",
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000849 System, false, false, false, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000850
851 // tiger
852 AddPath("/usr/lib/gcc/i686-apple-darwin8/4.0.1/include", System,
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000853 false, false, false, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000854 AddPath("/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/include",
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000855 System, false, false, false, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000856 AddPath("/usr/lib/gcc/powerpc-apple-darwin8/"
857 "4.0.1/../../../../powerpc-apple-darwin8/include",
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000858 System, false, false, false, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000859
Lauro Ramos Venanciod0515f22008-01-21 23:08:35 +0000860 // Ubuntu 7.10 - Gutsy Gibbon
861 AddPath("/usr/lib/gcc/i486-linux-gnu/4.1.3/include", System,
862 false, false, false, Headers);
863
Chris Lattnerc2043bf2007-12-17 06:36:45 +0000864 AddPath("/usr/include", System, false, false, false, Headers);
865 AddPath("/System/Library/Frameworks", System, true, false, true, Headers);
866 AddPath("/Library/Frameworks", System, true, false, true, Headers);
Chris Lattner4b009652007-07-25 00:24:17 +0000867 }
868
869 // Now that we have collected all of the include paths, merge them all
870 // together and tell the preprocessor about them.
871
872 // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
873 std::vector<DirectoryLookup> SearchList;
874 SearchList = IncludeGroup[Angled];
875 SearchList.insert(SearchList.end(), IncludeGroup[System].begin(),
876 IncludeGroup[System].end());
877 SearchList.insert(SearchList.end(), IncludeGroup[After].begin(),
878 IncludeGroup[After].end());
879 RemoveDuplicates(SearchList);
880 RemoveDuplicates(IncludeGroup[Quoted]);
881
882 // Prepend QUOTED list on the search list.
883 SearchList.insert(SearchList.begin(), IncludeGroup[Quoted].begin(),
884 IncludeGroup[Quoted].end());
885
886
887 bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
888 Headers.SetSearchPaths(SearchList, IncludeGroup[Quoted].size(),
889 DontSearchCurDir);
890
891 // If verbose, print the list of directories that will be searched.
892 if (Verbose) {
893 fprintf(stderr, "#include \"...\" search starts here:\n");
894 unsigned QuotedIdx = IncludeGroup[Quoted].size();
895 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
896 if (i == QuotedIdx)
897 fprintf(stderr, "#include <...> search starts here:\n");
Chris Lattner1df68f92007-12-17 17:57:27 +0000898 const char *Name = SearchList[i].getName();
899 const char *Suffix;
Chris Lattner0f64f652007-12-17 17:42:26 +0000900 if (SearchList[i].isNormalDir())
Chris Lattner1df68f92007-12-17 17:57:27 +0000901 Suffix = "";
Chris Lattner0f64f652007-12-17 17:42:26 +0000902 else if (SearchList[i].isFramework())
Chris Lattner1df68f92007-12-17 17:57:27 +0000903 Suffix = " (framework directory)";
Chris Lattner0f64f652007-12-17 17:42:26 +0000904 else {
905 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
Chris Lattner1df68f92007-12-17 17:57:27 +0000906 Suffix = " (headermap)";
Chris Lattner0f64f652007-12-17 17:42:26 +0000907 }
Chris Lattner1df68f92007-12-17 17:57:27 +0000908 fprintf(stderr, " %s%s\n", Name, Suffix);
Chris Lattner4b009652007-07-25 00:24:17 +0000909 }
Chris Lattnerac553842007-12-15 23:11:06 +0000910 fprintf(stderr, "End of search list.\n");
Chris Lattner4b009652007-07-25 00:24:17 +0000911 }
912}
913
914
Chris Lattner4b009652007-07-25 00:24:17 +0000915//===----------------------------------------------------------------------===//
916// Basic Parser driver
917//===----------------------------------------------------------------------===//
918
Ted Kremenek17861c52007-12-19 22:51:13 +0000919static void ParseFile(Preprocessor &PP, MinimalAction *PA){
Chris Lattner4b009652007-07-25 00:24:17 +0000920 Parser P(PP, *PA);
Ted Kremenek17861c52007-12-19 22:51:13 +0000921 PP.EnterMainSourceFile();
Chris Lattner4b009652007-07-25 00:24:17 +0000922
923 // Parsing the specified input file.
924 P.ParseTranslationUnit();
925 delete PA;
926}
927
928//===----------------------------------------------------------------------===//
929// Main driver
930//===----------------------------------------------------------------------===//
931
Ted Kremeneka36aaef2007-12-05 18:27:04 +0000932/// CreateASTConsumer - Create the ASTConsumer for the corresponding program
933/// action. These consumers can operate on both ASTs that are freshly
934/// parsed from source files as well as those deserialized from Bitcode.
Ted Kremenekd890f6a2007-12-19 22:24:34 +0000935static ASTConsumer* CreateASTConsumer(const std::string& InFile,
Ted Kremenek397de012007-12-13 00:37:31 +0000936 Diagnostic& Diag, FileManager& FileMgr,
Chris Lattner8d72ee02008-02-06 01:42:25 +0000937 const LangOptions& LangOpts,
938 llvm::Module *&DestModule) {
Ted Kremeneka36aaef2007-12-05 18:27:04 +0000939 switch (ProgAction) {
940 default:
941 return NULL;
942
943 case ASTPrint:
944 return CreateASTPrinter();
945
946 case ASTDump:
947 return CreateASTDumper();
948
949 case ASTView:
950 return CreateASTViewer();
951
952 case ParseCFGDump:
953 case ParseCFGView:
954 return CreateCFGDumper(ProgAction == ParseCFGView);
955
956 case AnalysisLiveVariables:
957 return CreateLiveVarAnalyzer();
958
959 case WarnDeadStores:
960 return CreateDeadStoreChecker(Diag);
961
962 case WarnUninitVals:
963 return CreateUnitValsChecker(Diag);
964
Ted Kremenekd2500ab2008-01-16 18:18:48 +0000965 case AnalysisGRConstants:
966 return CreateGRConstants();
Ted Kremenek3b451132008-01-08 18:04:06 +0000967
Ted Kremeneka36aaef2007-12-05 18:27:04 +0000968 case TestSerialization:
Ted Kremenekd890f6a2007-12-19 22:24:34 +0000969 return CreateSerializationTest(Diag, FileMgr, LangOpts);
Ted Kremeneka36aaef2007-12-05 18:27:04 +0000970
971 case EmitLLVM:
Seo Sanghyeon550a1eb2007-12-24 01:52:34 +0000972 case EmitBC:
Chris Lattner8d72ee02008-02-06 01:42:25 +0000973 DestModule = new llvm::Module(InFile);
974 return CreateLLVMCodeGen(Diag, LangOpts, DestModule);
Seo Sanghyeon550a1eb2007-12-24 01:52:34 +0000975
Ted Kremenekbde30332007-12-19 17:25:59 +0000976 case SerializeAST:
Ted Kremenek397de012007-12-13 00:37:31 +0000977 // FIXME: Allow user to tailor where the file is written.
Ted Kremenek6d1d3ac2007-12-19 23:48:45 +0000978 return CreateASTSerializer(InFile, OutputFile, Diag, LangOpts);
Ted Kremenek397de012007-12-13 00:37:31 +0000979
Ted Kremeneka36aaef2007-12-05 18:27:04 +0000980 case RewriteTest:
Fariborz Jahanian8d2080c2008-01-18 01:15:54 +0000981 return CreateCodeRewriterTest(InFile, Diag);
Ted Kremeneka36aaef2007-12-05 18:27:04 +0000982 }
983}
984
Chris Lattner4b009652007-07-25 00:24:17 +0000985/// ProcessInputFile - Process a single input file with the specified state.
986///
Ted Kremenek0fd6e492007-12-19 22:32:34 +0000987static void ProcessInputFile(Preprocessor &PP, const std::string &InFile,
Chris Lattner968982d2007-12-15 20:48:40 +0000988 TextDiagnostics &OurDiagnosticClient) {
Ted Kremenek6856c632007-09-26 18:39:29 +0000989
990 ASTConsumer* Consumer = NULL;
Chris Lattner4b009652007-07-25 00:24:17 +0000991 bool ClearSourceMgr = false;
Chris Lattner8d72ee02008-02-06 01:42:25 +0000992 llvm::Module *CodeGenModule = 0;
Ted Kremenek6856c632007-09-26 18:39:29 +0000993
Chris Lattner4b009652007-07-25 00:24:17 +0000994 switch (ProgAction) {
995 default:
Ted Kremenekd890f6a2007-12-19 22:24:34 +0000996 Consumer = CreateASTConsumer(InFile,
997 PP.getDiagnostics(),
Chris Lattner968982d2007-12-15 20:48:40 +0000998 PP.getFileManager(),
Chris Lattner8d72ee02008-02-06 01:42:25 +0000999 PP.getLangOptions(),
1000 CodeGenModule);
Ted Kremeneka36aaef2007-12-05 18:27:04 +00001001
1002 if (!Consumer) {
1003 fprintf(stderr, "Unexpected program action!\n");
1004 return;
1005 }
Ted Kremenekd890f6a2007-12-19 22:24:34 +00001006
Ted Kremeneka36aaef2007-12-05 18:27:04 +00001007 break;
1008
Chris Lattner4b009652007-07-25 00:24:17 +00001009 case DumpTokens: { // Token dump mode.
1010 Token Tok;
1011 // Start parsing the specified input file.
Ted Kremenek17861c52007-12-19 22:51:13 +00001012 PP.EnterMainSourceFile();
Chris Lattner4b009652007-07-25 00:24:17 +00001013 do {
1014 PP.Lex(Tok);
1015 PP.DumpToken(Tok, true);
1016 fprintf(stderr, "\n");
Chris Lattner3b494152007-10-09 18:03:42 +00001017 } while (Tok.isNot(tok::eof));
Chris Lattner4b009652007-07-25 00:24:17 +00001018 ClearSourceMgr = true;
1019 break;
1020 }
1021 case RunPreprocessorOnly: { // Just lex as fast as we can, no output.
1022 Token Tok;
1023 // Start parsing the specified input file.
Ted Kremenek17861c52007-12-19 22:51:13 +00001024 PP.EnterMainSourceFile();
Chris Lattner4b009652007-07-25 00:24:17 +00001025 do {
1026 PP.Lex(Tok);
Chris Lattner3b494152007-10-09 18:03:42 +00001027 } while (Tok.isNot(tok::eof));
Chris Lattner4b009652007-07-25 00:24:17 +00001028 ClearSourceMgr = true;
1029 break;
1030 }
1031
1032 case PrintPreprocessedInput: // -E mode.
Chris Lattnerefd02a32008-01-27 23:55:11 +00001033 DoPrintPreprocessedInput(PP, OutputFile);
Chris Lattner4b009652007-07-25 00:24:17 +00001034 ClearSourceMgr = true;
1035 break;
1036
1037 case ParseNoop: // -parse-noop
Ted Kremenek17861c52007-12-19 22:51:13 +00001038 ParseFile(PP, new MinimalAction(PP.getIdentifierTable()));
Chris Lattner4b009652007-07-25 00:24:17 +00001039 ClearSourceMgr = true;
1040 break;
1041
1042 case ParsePrintCallbacks:
Ted Kremenek17861c52007-12-19 22:51:13 +00001043 ParseFile(PP, CreatePrintParserActionsAction(PP.getIdentifierTable()));
Chris Lattner4b009652007-07-25 00:24:17 +00001044 ClearSourceMgr = true;
1045 break;
Ted Kremenek0841c702007-09-25 18:37:20 +00001046
Ted Kremenek6856c632007-09-26 18:39:29 +00001047 case ParseSyntaxOnly: // -fsyntax-only
Ted Kremenek6856c632007-09-26 18:39:29 +00001048 Consumer = new ASTConsumer();
Ted Kremenek0a03ce62007-09-17 20:49:30 +00001049 break;
Chris Lattner129758d2007-09-16 19:46:59 +00001050 }
Ted Kremenek6856c632007-09-26 18:39:29 +00001051
1052 if (Consumer) {
Ted Kremenek56b70862007-09-26 20:14:22 +00001053 if (VerifyDiagnostics)
Ted Kremenek17861c52007-12-19 22:51:13 +00001054 exit(CheckASTConsumer(PP, Consumer));
Chris Lattner8593cbf2007-11-03 06:24:16 +00001055
1056 // This deletes Consumer.
Ted Kremenek17861c52007-12-19 22:51:13 +00001057 ParseAST(PP, Consumer, Stats);
Chris Lattner4b009652007-07-25 00:24:17 +00001058 }
Chris Lattner8d72ee02008-02-06 01:42:25 +00001059
1060 // If running the code generator, finish up now.
1061 if (CodeGenModule) {
1062 std::ostream *Out;
1063 if (OutputFile == "-") {
1064 Out = llvm::cout.stream();
1065 } else if (!OutputFile.empty()) {
1066 Out = new std::ofstream(OutputFile.c_str(),
1067 std::ios_base::binary|std::ios_base::out);
1068 } else if (InFile == "-") {
1069 Out = llvm::cout.stream();
1070 } else {
1071 llvm::sys::Path Path(InFile);
1072 Path.eraseSuffix();
1073 if (ProgAction == EmitLLVM)
1074 Path.appendSuffix("ll");
1075 else if (ProgAction == EmitBC)
1076 Path.appendSuffix("bc");
1077 else
1078 assert(0 && "Unknown action");
1079 Out = new std::ofstream(Path.toString().c_str(),
1080 std::ios_base::binary|std::ios_base::out);
1081 }
1082
1083 if (ProgAction == EmitLLVM) {
1084 CodeGenModule->print(*Out);
1085 } else {
1086 assert(ProgAction == EmitBC);
1087 llvm::WriteBitcodeToFile(CodeGenModule, *Out);
1088 }
1089
1090 if (Out != llvm::cout.stream())
1091 delete Out;
1092 delete CodeGenModule;
1093 }
Chris Lattner4b009652007-07-25 00:24:17 +00001094
1095 if (Stats) {
Ted Kremenekd890f6a2007-12-19 22:24:34 +00001096 fprintf(stderr, "\nSTATISTICS FOR '%s':\n", InFile.c_str());
Chris Lattner4b009652007-07-25 00:24:17 +00001097 PP.PrintStats();
1098 PP.getIdentifierTable().PrintStats();
Chris Lattner968982d2007-12-15 20:48:40 +00001099 PP.getHeaderSearchInfo().PrintStats();
Chris Lattner4b009652007-07-25 00:24:17 +00001100 if (ClearSourceMgr)
Chris Lattner968982d2007-12-15 20:48:40 +00001101 PP.getSourceManager().PrintStats();
Chris Lattner4b009652007-07-25 00:24:17 +00001102 fprintf(stderr, "\n");
1103 }
1104
1105 // For a multi-file compilation, some things are ok with nuking the source
1106 // manager tables, other require stable fileid/macroid's across multiple
1107 // files.
Chris Lattner968982d2007-12-15 20:48:40 +00001108 if (ClearSourceMgr)
1109 PP.getSourceManager().clearIDTables();
Chris Lattner4b009652007-07-25 00:24:17 +00001110}
1111
Ted Kremenek80d53372007-12-12 23:41:08 +00001112static void ProcessSerializedFile(const std::string& InFile, Diagnostic& Diag,
1113 FileManager& FileMgr) {
1114
1115 if (VerifyDiagnostics) {
1116 fprintf(stderr, "-verify does not yet work with serialized ASTs.\n");
1117 exit (1);
1118 }
1119
1120 llvm::sys::Path Filename(InFile);
1121
1122 if (!Filename.isValid()) {
1123 fprintf(stderr, "serialized file '%s' not available.\n",InFile.c_str());
1124 exit (1);
1125 }
1126
Ted Kremenek0c7cd7a2007-12-20 19:47:16 +00001127 llvm::OwningPtr<TranslationUnit> TU(ReadASTBitcodeFile(Filename,FileMgr));
Ted Kremenek2bd42412007-12-13 18:11:11 +00001128
1129 if (!TU) {
1130 fprintf(stderr, "error: file '%s' could not be deserialized\n",
1131 InFile.c_str());
1132 exit (1);
1133 }
1134
Ted Kremenekab749372007-12-19 19:27:38 +00001135 // Observe that we use the source file name stored in the deserialized
1136 // translation unit, rather than InFile.
Chris Lattner8d72ee02008-02-06 01:42:25 +00001137 llvm::Module *DestModule;
Ted Kremenek0c7cd7a2007-12-20 19:47:16 +00001138 llvm::OwningPtr<ASTConsumer>
Chris Lattner8d72ee02008-02-06 01:42:25 +00001139 Consumer(CreateASTConsumer(InFile, Diag, FileMgr, TU->getLangOpts(),
1140 DestModule));
Ted Kremenek80d53372007-12-12 23:41:08 +00001141
1142 if (!Consumer) {
1143 fprintf(stderr, "Unsupported program action with serialized ASTs!\n");
1144 exit (1);
1145 }
1146
Ted Kremenek17861c52007-12-19 22:51:13 +00001147 Consumer->Initialize(*TU->getContext());
Ted Kremenek80d53372007-12-12 23:41:08 +00001148
Chris Lattner8d72ee02008-02-06 01:42:25 +00001149 // FIXME: We need to inform Consumer about completed TagDecls as well.
Ted Kremenek80d53372007-12-12 23:41:08 +00001150 for (TranslationUnit::iterator I=TU->begin(), E=TU->end(); I!=E; ++I)
1151 Consumer->HandleTopLevelDecl(*I);
Ted Kremenek80d53372007-12-12 23:41:08 +00001152}
1153
1154
Chris Lattner4b009652007-07-25 00:24:17 +00001155static llvm::cl::list<std::string>
1156InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>"));
1157
Ted Kremenek80d53372007-12-12 23:41:08 +00001158static bool isSerializedFile(const std::string& InFile) {
1159 if (InFile.size() < 4)
1160 return false;
1161
1162 const char* s = InFile.c_str()+InFile.size()-4;
1163
1164 return s[0] == '.' &&
1165 s[1] == 'a' &&
1166 s[2] == 's' &&
1167 s[3] == 't';
1168}
1169
Chris Lattner4b009652007-07-25 00:24:17 +00001170
1171int main(int argc, char **argv) {
1172 llvm::cl::ParseCommandLineOptions(argc, argv, " llvm cfe\n");
1173 llvm::sys::PrintStackTraceOnErrorSignal();
1174
1175 // If no input was specified, read from stdin.
1176 if (InputFilenames.empty())
1177 InputFilenames.push_back("-");
Ted Kremenekb240e822007-12-11 23:28:38 +00001178
Chris Lattner4b009652007-07-25 00:24:17 +00001179 // Create a file manager object to provide access to and cache the filesystem.
1180 FileManager FileMgr;
1181
Ted Kremenekb240e822007-12-11 23:28:38 +00001182 // Create the diagnostic client for reporting errors or for
1183 // implementing -verify.
Chris Lattner4b009652007-07-25 00:24:17 +00001184 std::auto_ptr<TextDiagnostics> DiagClient;
Ted Kremenek56b70862007-09-26 20:14:22 +00001185 if (!VerifyDiagnostics) {
Chris Lattner4b009652007-07-25 00:24:17 +00001186 // Print diagnostics to stderr by default.
Ted Kremenekb3ee1932007-12-11 21:27:55 +00001187 DiagClient.reset(new TextDiagnosticPrinter());
Chris Lattner4b009652007-07-25 00:24:17 +00001188 } else {
1189 // When checking diagnostics, just buffer them up.
Ted Kremenekb3ee1932007-12-11 21:27:55 +00001190 DiagClient.reset(new TextDiagnosticBuffer());
Chris Lattner4b009652007-07-25 00:24:17 +00001191
1192 if (InputFilenames.size() != 1) {
1193 fprintf(stderr,
Ted Kremenek56b70862007-09-26 20:14:22 +00001194 "-verify only works on single input files for now.\n");
Chris Lattner4b009652007-07-25 00:24:17 +00001195 return 1;
1196 }
1197 }
1198
1199 // Configure our handling of diagnostics.
1200 Diagnostic Diags(*DiagClient);
Ted Kremenekb240e822007-12-11 23:28:38 +00001201 InitializeDiagnostics(Diags);
1202
Chris Lattner45a56e02007-12-05 23:24:17 +00001203 // -I- is a deprecated GCC feature, scan for it and reject it.
1204 for (unsigned i = 0, e = I_dirs.size(); i != e; ++i) {
1205 if (I_dirs[i] == "-") {
Ted Kremenekde79f792007-12-11 22:57:35 +00001206 Diags.Report(diag::err_pp_I_dash_not_supported);
Chris Lattner45a56e02007-12-05 23:24:17 +00001207 I_dirs.erase(I_dirs.begin()+i);
1208 --i;
1209 }
1210 }
1211
Chris Lattner4b009652007-07-25 00:24:17 +00001212 for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
Ted Kremenekb240e822007-12-11 23:28:38 +00001213 const std::string &InFile = InputFilenames[i];
Ted Kremenekb240e822007-12-11 23:28:38 +00001214
Ted Kremenek80d53372007-12-12 23:41:08 +00001215 if (isSerializedFile(InFile))
1216 ProcessSerializedFile(InFile,Diags,FileMgr);
1217 else {
1218 /// Create a SourceManager object. This tracks and owns all the file
1219 /// buffers allocated to a translation unit.
1220 SourceManager SourceMgr;
Ted Kremenekb240e822007-12-11 23:28:38 +00001221
Ted Kremenek80d53372007-12-12 23:41:08 +00001222 // Initialize language options, inferring file types from input filenames.
1223 LangOptions LangInfo;
1224 InitializeBaseLanguage();
1225 LangKind LK = GetLanguage(InFile);
1226 InitializeLangOptions(LangInfo, LK);
1227 InitializeLanguageStandard(LangInfo, LK);
1228
1229 // Process the -I options and set them in the HeaderInfo.
1230 HeaderSearch HeaderInfo(FileMgr);
1231 DiagClient->setHeaderSearch(HeaderInfo);
1232 InitializeIncludePaths(HeaderInfo, FileMgr, LangInfo);
1233
1234 // Get information about the targets being compiled for. Note that this
1235 // pointer and the TargetInfoImpl objects are never deleted by this toy
1236 // driver.
1237 TargetInfo *Target;
1238
1239 // Create triples, and create the TargetInfo.
1240 std::vector<std::string> triples;
1241 CreateTargetTriples(triples);
1242 Target = TargetInfo::CreateTargetInfo(&triples[0],
1243 &triples[0]+triples.size(),
1244 &Diags);
1245
1246 if (Target == 0) {
1247 fprintf(stderr, "Sorry, I don't know what target this is: %s\n",
1248 triples[0].c_str());
1249 fprintf(stderr, "Please use -triple or -arch.\n");
1250 exit(1);
1251 }
1252
1253 // Set up the preprocessor with these options.
1254 Preprocessor PP(Diags, LangInfo, *Target, SourceMgr, HeaderInfo);
1255
1256 std::vector<char> PredefineBuffer;
Ted Kremenek6d1d3ac2007-12-19 23:48:45 +00001257 if (!InitializePreprocessor(PP, InFile, PredefineBuffer))
Ted Kremenek2578dd02007-12-19 22:29:55 +00001258 continue;
1259
Ted Kremenek6d1d3ac2007-12-19 23:48:45 +00001260 ProcessInputFile(PP, InFile, *DiagClient);
Ted Kremenek80d53372007-12-12 23:41:08 +00001261 HeaderInfo.ClearFileInfo();
1262
1263 if (Stats)
1264 SourceMgr.PrintStats();
1265 }
Chris Lattner4b009652007-07-25 00:24:17 +00001266 }
1267
1268 unsigned NumDiagnostics = Diags.getNumDiagnostics();
1269
1270 if (NumDiagnostics)
1271 fprintf(stderr, "%d diagnostic%s generated.\n", NumDiagnostics,
1272 (NumDiagnostics == 1 ? "" : "s"));
1273
1274 if (Stats) {
Chris Lattner4b009652007-07-25 00:24:17 +00001275 FileMgr.PrintStats();
1276 fprintf(stderr, "\n");
1277 }
1278
1279 return Diags.getNumErrors() != 0;
1280}