blob: faa7178f2547888f0817813c97ae75627d65eb31 [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"
Daniel Dunbaraa7a0662008-10-23 05:50:47 +000027#include "clang/Driver/CompileOptions.h"
Ted Kremenek21b88b72008-11-03 22:31:48 +000028#include "clang/Driver/PathDiagnosticClients.h"
Nico Weber770e3882008-08-22 09:25:22 +000029#include "clang/Driver/InitHeaderSearch.h"
Nico Weber0e13eaa2008-08-05 23:33:20 +000030#include "clang/Driver/TextDiagnosticBuffer.h"
31#include "clang/Driver/TextDiagnosticPrinter.h"
Ted Kremenekfd75e312008-03-27 06:17:42 +000032#include "clang/Analysis/PathDiagnostic.h"
Daniel Dunbarde300732008-08-11 04:54:23 +000033#include "clang/AST/Decl.h"
Ted Kremenekac881932007-12-18 21:34:28 +000034#include "clang/AST/TranslationUnit.h"
Chris Lattnerf5e9db02008-02-06 02:01:47 +000035#include "clang/CodeGen/ModuleBuilder.h"
Chris Lattner0bed6ec2008-02-06 00:23:21 +000036#include "clang/Sema/ParseAST.h"
Chris Lattner1cc01712007-09-15 22:56:56 +000037#include "clang/AST/ASTConsumer.h"
Chris Lattner4b009652007-07-25 00:24:17 +000038#include "clang/Parse/Parser.h"
39#include "clang/Lex/HeaderSearch.h"
40#include "clang/Basic/FileManager.h"
41#include "clang/Basic/SourceManager.h"
42#include "clang/Basic/TargetInfo.h"
Chris Lattner01de9c82008-09-30 20:16:56 +000043#include "llvm/ADT/OwningPtr.h"
Chris Lattnerac139d22007-12-15 23:20:07 +000044#include "llvm/ADT/SmallPtrSet.h"
Chris Lattner01de9c82008-09-30 20:16:56 +000045#include "llvm/ADT/StringExtras.h"
46#include "llvm/Config/config.h"
Chris Lattner4b009652007-07-25 00:24:17 +000047#include "llvm/Support/CommandLine.h"
Daniel Dunbarbb298c02008-10-28 00:38:08 +000048#include "llvm/Support/ManagedStatic.h"
Chris Lattner4b009652007-07-25 00:24:17 +000049#include "llvm/Support/MemoryBuffer.h"
Daniel Dunbarabe2e542008-10-02 01:21:33 +000050#include "llvm/System/Host.h"
Chris Lattner3ee4a2f2008-03-03 03:16:03 +000051#include "llvm/System/Path.h"
Chris Lattner01de9c82008-09-30 20:16:56 +000052#include "llvm/System/Signals.h"
Chris Lattner4b009652007-07-25 00:24:17 +000053using namespace clang;
54
55//===----------------------------------------------------------------------===//
56// Global options.
57//===----------------------------------------------------------------------===//
58
Daniel Dunbar4efedde2008-10-16 16:54:18 +000059static bool HadErrors = false;
Daniel Dunbar70a66b12008-10-04 23:42:49 +000060
Chris Lattner4b009652007-07-25 00:24:17 +000061static llvm::cl::opt<bool>
62Verbose("v", llvm::cl::desc("Enable verbose output"));
63static llvm::cl::opt<bool>
Nate Begeman6acbedd2007-12-30 01:38:50 +000064Stats("print-stats",
65 llvm::cl::desc("Print performance metrics and statistics"));
Daniel Dunbar4efedde2008-10-16 16:54:18 +000066static llvm::cl::opt<bool>
67DisableFree("disable-free",
68 llvm::cl::desc("Disable freeing of memory on exit"),
69 llvm::cl::init(false));
Chris Lattner4b009652007-07-25 00:24:17 +000070
71enum ProgActions {
Steve Naroff44e81222008-04-14 22:03:09 +000072 RewriteObjC, // ObjC->C Rewriter.
Steve Naroff93c18352008-09-18 14:10:13 +000073 RewriteBlocks, // ObjC->C Rewriter for Blocks.
Chris Lattner1665a9f2008-05-08 06:52:13 +000074 RewriteMacros, // Expand macros but not #includes.
Chris Lattnerc3fbf392008-10-12 05:29:20 +000075 RewriteTest, // Rewriter playground
Ted Kremeneke1a79d82008-03-19 07:53:42 +000076 HTMLTest, // HTML displayer testing stuff.
Daniel Dunbar85e44e22008-10-21 23:49:24 +000077 EmitAssembly, // Emit a .s file.
Chris Lattner4b009652007-07-25 00:24:17 +000078 EmitLLVM, // Emit a .ll file.
Seo Sanghyeon550a1eb2007-12-24 01:52:34 +000079 EmitBC, // Emit a .bc file.
Ted Kremenek397de012007-12-13 00:37:31 +000080 SerializeAST, // Emit a .ast file.
Ted Kremenek24612ae2008-03-18 21:19:49 +000081 EmitHTML, // Translate input source into HTML.
Chris Lattner4045a8a2007-10-11 00:18:28 +000082 ASTPrint, // Parse ASTs and print them.
83 ASTDump, // Parse ASTs and dump them.
84 ASTView, // Parse ASTs and view them in Graphviz.
Ted Kremenek221bb8d2007-10-16 23:37:27 +000085 TestSerialization, // Run experimental serialization code.
Chris Lattner4b009652007-07-25 00:24:17 +000086 ParsePrintCallbacks, // Parse and print each callback.
87 ParseSyntaxOnly, // Parse and perform semantic analysis.
88 ParseNoop, // Parse with noop callbacks.
89 RunPreprocessorOnly, // Just lex, no output.
90 PrintPreprocessedInput, // -E mode.
Chris Lattneraf669fb2008-10-12 05:03:36 +000091 DumpTokens, // Dump out preprocessed tokens.
92 DumpRawTokens, // Dump out raw tokens.
Ted Kremenek71c6cc62008-10-21 00:54:44 +000093 RunAnalysis, // Run one or more source code analyses.
Ted Kremenekd9ceb3d2008-10-23 23:36:29 +000094 GeneratePCH, // Generate precompiled header.
95 InheritanceView // View C++ inheritance for a specified class.
Chris Lattner4b009652007-07-25 00:24:17 +000096};
97
98static llvm::cl::opt<ProgActions>
99ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
100 llvm::cl::init(ParseSyntaxOnly),
101 llvm::cl::values(
102 clEnumValN(RunPreprocessorOnly, "Eonly",
103 "Just run preprocessor, no output (for timings)"),
104 clEnumValN(PrintPreprocessedInput, "E",
105 "Run preprocessor, emit preprocessed file"),
Chris Lattneraf669fb2008-10-12 05:03:36 +0000106 clEnumValN(DumpRawTokens, "dump-raw-tokens",
107 "Lex file in raw mode and dump raw tokens"),
108 clEnumValN(DumpTokens, "dump-tokens",
Chris Lattner4b009652007-07-25 00:24:17 +0000109 "Run preprocessor, dump internal rep of tokens"),
110 clEnumValN(ParseNoop, "parse-noop",
111 "Run parser with noop callbacks (for timings)"),
112 clEnumValN(ParseSyntaxOnly, "fsyntax-only",
113 "Run parser and perform semantic analysis"),
114 clEnumValN(ParsePrintCallbacks, "parse-print-callbacks",
115 "Run parser and print each callback invoked"),
Ted Kremenek24612ae2008-03-18 21:19:49 +0000116 clEnumValN(EmitHTML, "emit-html",
117 "Output input source as HTML"),
Chris Lattner4045a8a2007-10-11 00:18:28 +0000118 clEnumValN(ASTPrint, "ast-print",
119 "Build ASTs and then pretty-print them"),
120 clEnumValN(ASTDump, "ast-dump",
121 "Build ASTs and then debug dump them"),
Chris Lattner664dd082007-10-11 00:37:43 +0000122 clEnumValN(ASTView, "ast-view",
Sanjiv Gupta69683532008-05-08 08:28:14 +0000123 "Build ASTs and view them with GraphViz"),
Ted Kremenek221bb8d2007-10-16 23:37:27 +0000124 clEnumValN(TestSerialization, "test-pickling",
Sanjiv Gupta69683532008-05-08 08:28:14 +0000125 "Run prototype serialization code"),
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000126 clEnumValN(EmitAssembly, "S",
127 "Emit native assembly code"),
Chris Lattner4b009652007-07-25 00:24:17 +0000128 clEnumValN(EmitLLVM, "emit-llvm",
Ted Kremenek05334682007-09-06 21:26:58 +0000129 "Build ASTs then convert to LLVM, emit .ll file"),
Seo Sanghyeon550a1eb2007-12-24 01:52:34 +0000130 clEnumValN(EmitBC, "emit-llvm-bc",
131 "Build ASTs then convert to LLVM, emit .bc file"),
Ted Kremenekd01eae62007-12-19 19:47:59 +0000132 clEnumValN(SerializeAST, "serialize",
Ted Kremenek397de012007-12-13 00:37:31 +0000133 "Build ASTs and emit .ast file"),
Chris Lattnerc3fbf392008-10-12 05:29:20 +0000134 clEnumValN(RewriteTest, "rewrite-test",
135 "Rewriter playground"),
Steve Naroff44e81222008-04-14 22:03:09 +0000136 clEnumValN(RewriteObjC, "rewrite-objc",
Chris Lattner1665a9f2008-05-08 06:52:13 +0000137 "Rewrite ObjC into C (code rewriter example)"),
138 clEnumValN(RewriteMacros, "rewrite-macros",
139 "Expand macros without full preprocessing"),
Steve Naroff93c18352008-09-18 14:10:13 +0000140 clEnumValN(RewriteBlocks, "rewrite-blocks",
141 "Rewrite Blocks to C"),
Chris Lattner4b009652007-07-25 00:24:17 +0000142 clEnumValEnd));
143
Ted Kremenekd01eae62007-12-19 19:47:59 +0000144
145static llvm::cl::opt<std::string>
146OutputFile("o",
Ted Kremenek09b3f0d2007-12-19 19:50:41 +0000147 llvm::cl::value_desc("path"),
Ted Kremenekd01eae62007-12-19 19:47:59 +0000148 llvm::cl::desc("Specify output file (for --serialize, this is a directory)"));
Ted Kremenek517cb512008-04-14 18:40:58 +0000149
150//===----------------------------------------------------------------------===//
Sanjiv Gupta40e56a12008-05-08 08:54:20 +0000151// Code Generator Options
152//===----------------------------------------------------------------------===//
153static llvm::cl::opt<bool>
154GenerateDebugInfo("g",
155 llvm::cl::desc("Generate source level debug information"));
156
157//===----------------------------------------------------------------------===//
Ted Kremenek517cb512008-04-14 18:40:58 +0000158// Diagnostic Options
159//===----------------------------------------------------------------------===//
160
Ted Kremenek10389cf2007-09-26 19:42:19 +0000161static llvm::cl::opt<bool>
162VerifyDiagnostics("verify",
Sanjiv Gupta69683532008-05-08 08:28:14 +0000163 llvm::cl::desc("Verify emitted diagnostics and warnings"));
Ted Kremenek10389cf2007-09-26 19:42:19 +0000164
Ted Kremenekfd75e312008-03-27 06:17:42 +0000165static llvm::cl::opt<std::string>
166HTMLDiag("html-diags",
167 llvm::cl::desc("Generate HTML to report diagnostics"),
168 llvm::cl::value_desc("HTML directory"));
169
Nico Weber0e13eaa2008-08-05 23:33:20 +0000170static llvm::cl::opt<bool>
171NoShowColumn("fno-show-column",
172 llvm::cl::desc("Do not include column number on diagnostics"));
173
174static llvm::cl::opt<bool>
175NoCaretDiagnostics("fno-caret-diagnostics",
176 llvm::cl::desc("Do not include source line and caret with"
177 " diagnostics"));
178
179
Chris Lattner4b009652007-07-25 00:24:17 +0000180//===----------------------------------------------------------------------===//
Ted Kremenekd9ceb3d2008-10-23 23:36:29 +0000181// C++ Visualization.
182//===----------------------------------------------------------------------===//
183
184static llvm::cl::opt<std::string>
185InheritanceViewCls("cxx-inheritance-view",
186 llvm::cl::value_desc("class name"),
187 llvm::cl::desc("View C++ inhertance for a specified class"));
188
189//===----------------------------------------------------------------------===//
190// Analyzer Options.
Ted Kremenek517cb512008-04-14 18:40:58 +0000191//===----------------------------------------------------------------------===//
192
193static llvm::cl::opt<bool>
Ted Kremenekcf262252008-08-27 22:31:43 +0000194VisualizeEGDot("analyzer-viz-egraph-graphviz",
195 llvm::cl::desc("Display exploded graph using GraphViz"));
Ted Kremenek517cb512008-04-14 18:40:58 +0000196
197static llvm::cl::opt<bool>
Ted Kremenekcf262252008-08-27 22:31:43 +0000198VisualizeEGUbi("analyzer-viz-egraph-ubigraph",
199 llvm::cl::desc("Display exploded graph using Ubigraph"));
200
201static llvm::cl::opt<bool>
202AnalyzeAll("analyzer-opt-analyze-headers",
Ted Kremenek517cb512008-04-14 18:40:58 +0000203 llvm::cl::desc("Force the static analyzer to analyze "
Sanjiv Gupta69683532008-05-08 08:28:14 +0000204 "functions defined in header files"));
Ted Kremenek517cb512008-04-14 18:40:58 +0000205
Ted Kremenek81ea7992008-07-02 00:03:09 +0000206static llvm::cl::list<Analyses>
Ted Kremenekc3803992008-10-24 01:04:59 +0000207AnalysisList(llvm::cl::desc("SCA Checks/Analyses:"),
Ted Kremenek81ea7992008-07-02 00:03:09 +0000208llvm::cl::values(
Ted Kremenekfbda0ef2008-07-15 00:46:02 +0000209#define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE)\
Ted Kremenek8ce61b32008-07-14 23:41:13 +0000210clEnumValN(NAME, CMDFLAG, DESC),
211#include "Analyses.def"
212clEnumValEnd));
Ted Kremenek81ea7992008-07-02 00:03:09 +0000213
Ted Kremenekc3803992008-10-24 01:04:59 +0000214static llvm::cl::opt<AnalysisStores>
215AnalysisStoreOpt(llvm::cl::desc("SCA Low-Level Options (Store):"),
216 llvm::cl::init(BasicStoreModel),
217 llvm::cl::values(
218#define ANALYSIS_STORE(NAME, CMDFLAG, DESC)\
219clEnumValN(NAME##Model, "analyzer-store-" CMDFLAG, DESC),
220#include "Analyses.def"
221clEnumValEnd));
222
Ted Kremeneka3f825e2008-11-03 23:18:07 +0000223static llvm::cl::opt<AnalysisDiagClients>
224AnalysisDiagOpt(llvm::cl::desc("SCA Output Options:"),
225 llvm::cl::init(PD_HTML),
226 llvm::cl::values(
227#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN)\
228clEnumValN(PD_##NAME, "analyzer-output-" CMDFLAG, DESC),
229#include "Analyses.def"
230clEnumValEnd));
231
Ted Kremenek517cb512008-04-14 18:40:58 +0000232//===----------------------------------------------------------------------===//
Chris Lattner4b009652007-07-25 00:24:17 +0000233// Language Options
234//===----------------------------------------------------------------------===//
235
236enum LangKind {
237 langkind_unspecified,
238 langkind_c,
239 langkind_c_cpp,
Chris Lattnera19689a2008-10-22 17:29:21 +0000240 langkind_asm_cpp,
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000241 langkind_c_pch,
Chris Lattner4b009652007-07-25 00:24:17 +0000242 langkind_cxx,
243 langkind_cxx_cpp,
244 langkind_objc,
245 langkind_objc_cpp,
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000246 langkind_objc_pch,
Chris Lattner4b009652007-07-25 00:24:17 +0000247 langkind_objcxx,
248 langkind_objcxx_cpp
249};
250
251/* TODO: GCC also accepts:
252 c-header c++-header objective-c-header objective-c++-header
Chris Lattnera19689a2008-10-22 17:29:21 +0000253 assembler
Chris Lattner4b009652007-07-25 00:24:17 +0000254 ada, f77*, ratfor (!), f95, java, treelang
255 */
256static llvm::cl::opt<LangKind>
257BaseLang("x", llvm::cl::desc("Base language to compile"),
258 llvm::cl::init(langkind_unspecified),
259 llvm::cl::values(clEnumValN(langkind_c, "c", "C"),
260 clEnumValN(langkind_cxx, "c++", "C++"),
261 clEnumValN(langkind_objc, "objective-c", "Objective C"),
262 clEnumValN(langkind_objcxx,"objective-c++","Objective C++"),
263 clEnumValN(langkind_c_cpp, "c-cpp-output",
264 "Preprocessed C"),
Chris Lattnera19689a2008-10-22 17:29:21 +0000265 clEnumValN(langkind_asm_cpp, "assembler-with-cpp",
266 "Preprocessed asm"),
Chris Lattner4b009652007-07-25 00:24:17 +0000267 clEnumValN(langkind_cxx_cpp, "c++-cpp-output",
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000268 "Preprocessed C++"),
Chris Lattner4b009652007-07-25 00:24:17 +0000269 clEnumValN(langkind_objc_cpp, "objective-c-cpp-output",
270 "Preprocessed Objective C"),
271 clEnumValN(langkind_objcxx_cpp,"objective-c++-cpp-output",
272 "Preprocessed Objective C++"),
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000273 clEnumValN(langkind_c_pch,"c-header",
274 "Precompiled C header"),
275 clEnumValN(langkind_objc_pch, "objective-c-header",
276 "Precompiled Objective C header"),
Chris Lattner4b009652007-07-25 00:24:17 +0000277 clEnumValEnd));
278
279static llvm::cl::opt<bool>
280LangObjC("ObjC", llvm::cl::desc("Set base language to Objective-C"),
281 llvm::cl::Hidden);
282static llvm::cl::opt<bool>
283LangObjCXX("ObjC++", llvm::cl::desc("Set base language to Objective-C++"),
284 llvm::cl::Hidden);
285
Ted Kremenek11ad8952007-12-05 23:49:08 +0000286/// InitializeBaseLanguage - Handle the -x foo options.
287static void InitializeBaseLanguage() {
288 if (LangObjC)
289 BaseLang = langkind_objc;
290 else if (LangObjCXX)
291 BaseLang = langkind_objcxx;
292}
293
294static LangKind GetLanguage(const std::string &Filename) {
295 if (BaseLang != langkind_unspecified)
296 return BaseLang;
297
298 std::string::size_type DotPos = Filename.rfind('.');
299
300 if (DotPos == std::string::npos) {
301 BaseLang = langkind_c; // Default to C if no extension.
Chris Lattner4eac0502008-01-04 19:12:28 +0000302 return langkind_c;
Chris Lattner4b009652007-07-25 00:24:17 +0000303 }
304
Ted Kremenek11ad8952007-12-05 23:49:08 +0000305 std::string Ext = std::string(Filename.begin()+DotPos+1, Filename.end());
306 // C header: .h
307 // C++ header: .hh or .H;
308 // assembler no preprocessing: .s
309 // assembler: .S
310 if (Ext == "c")
311 return langkind_c;
Chris Lattner1cbb3032008-10-28 20:33:42 +0000312 else if (Ext == "S")
Chris Lattnera19689a2008-10-22 17:29:21 +0000313 return langkind_asm_cpp;
Ted Kremenek11ad8952007-12-05 23:49:08 +0000314 else if (Ext == "i")
315 return langkind_c_cpp;
316 else if (Ext == "ii")
317 return langkind_cxx_cpp;
318 else if (Ext == "m")
319 return langkind_objc;
320 else if (Ext == "mi")
321 return langkind_objc_cpp;
322 else if (Ext == "mm" || Ext == "M")
323 return langkind_objcxx;
324 else if (Ext == "mii")
325 return langkind_objcxx_cpp;
326 else if (Ext == "C" || Ext == "cc" || Ext == "cpp" || Ext == "CPP" ||
327 Ext == "c++" || Ext == "cp" || Ext == "cxx")
328 return langkind_cxx;
329 else
330 return langkind_c;
331}
332
333
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000334static void InitializeCOptions(LangOptions &Options) {
335 // Do nothing.
336}
337
338static void InitializeObjCOptions(LangOptions &Options) {
339 Options.ObjC1 = Options.ObjC2 = 1;
340}
341
342
343static bool InitializeLangOptions(LangOptions &Options, LangKind LK){
Chris Lattner4b009652007-07-25 00:24:17 +0000344 // FIXME: implement -fpreprocessed mode.
345 bool NoPreprocess = false;
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000346 bool PCH = false;
Chris Lattner4b009652007-07-25 00:24:17 +0000347
Ted Kremenek11ad8952007-12-05 23:49:08 +0000348 switch (LK) {
Chris Lattner4b009652007-07-25 00:24:17 +0000349 default: assert(0 && "Unknown language kind!");
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000350 case langkind_c_pch:
351 InitializeCOptions(Options);
352 PCH = true;
353 break;
Chris Lattnera19689a2008-10-22 17:29:21 +0000354 case langkind_asm_cpp:
355 // FALLTHROUGH
Chris Lattner4b009652007-07-25 00:24:17 +0000356 case langkind_c_cpp:
357 NoPreprocess = true;
358 // FALLTHROUGH
359 case langkind_c:
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000360 InitializeCOptions(Options);
Chris Lattner4b009652007-07-25 00:24:17 +0000361 break;
362 case langkind_cxx_cpp:
363 NoPreprocess = true;
364 // FALLTHROUGH
365 case langkind_cxx:
366 Options.CPlusPlus = 1;
367 break;
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000368 case langkind_objc_pch:
369 InitializeObjCOptions(Options);
370 PCH = true;
371 break;
Chris Lattner4b009652007-07-25 00:24:17 +0000372 case langkind_objc_cpp:
373 NoPreprocess = true;
374 // FALLTHROUGH
375 case langkind_objc:
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000376 InitializeObjCOptions(Options);
Chris Lattner4b009652007-07-25 00:24:17 +0000377 break;
378 case langkind_objcxx_cpp:
379 NoPreprocess = true;
380 // FALLTHROUGH
381 case langkind_objcxx:
382 Options.ObjC1 = Options.ObjC2 = 1;
383 Options.CPlusPlus = 1;
384 break;
385 }
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000386
387 return PCH;
Chris Lattner4b009652007-07-25 00:24:17 +0000388}
389
390/// LangStds - Language standards we support.
391enum LangStds {
392 lang_unspecified,
393 lang_c89, lang_c94, lang_c99,
Ted Kremenek88bec0f2008-09-03 21:22:16 +0000394 lang_gnu_START,
395 lang_gnu89 = lang_gnu_START, lang_gnu99,
Chris Lattner4b009652007-07-25 00:24:17 +0000396 lang_cxx98, lang_gnucxx98,
397 lang_cxx0x, lang_gnucxx0x
398};
399
400static llvm::cl::opt<LangStds>
401LangStd("std", llvm::cl::desc("Language standard to compile for"),
402 llvm::cl::init(lang_unspecified),
403 llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
404 clEnumValN(lang_c89, "c90", "ISO C 1990"),
405 clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
406 clEnumValN(lang_c94, "iso9899:199409",
407 "ISO C 1990 with amendment 1"),
408 clEnumValN(lang_c99, "c99", "ISO C 1999"),
409// clEnumValN(lang_c99, "c9x", "ISO C 1999"),
410 clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
411// clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
412 clEnumValN(lang_gnu89, "gnu89",
413 "ISO C 1990 with GNU extensions (default for C)"),
414 clEnumValN(lang_gnu99, "gnu99",
415 "ISO C 1999 with GNU extensions"),
416 clEnumValN(lang_gnu99, "gnu9x",
417 "ISO C 1999 with GNU extensions"),
418 clEnumValN(lang_cxx98, "c++98",
419 "ISO C++ 1998 with amendments"),
420 clEnumValN(lang_gnucxx98, "gnu++98",
421 "ISO C++ 1998 with amendments and GNU "
422 "extensions (default for C++)"),
423 clEnumValN(lang_cxx0x, "c++0x",
424 "Upcoming ISO C++ 200x with amendments"),
425 clEnumValN(lang_gnucxx0x, "gnu++0x",
426 "Upcoming ISO C++ 200x with amendments and GNU "
427 "extensions (default for C++)"),
428 clEnumValEnd));
429
430static llvm::cl::opt<bool>
431NoOperatorNames("fno-operator-names",
432 llvm::cl::desc("Do not treat C++ operator name keywords as "
433 "synonyms for operators"));
434
Anders Carlsson55bfe0d2007-10-15 02:50:23 +0000435static llvm::cl::opt<bool>
436PascalStrings("fpascal-strings",
437 llvm::cl::desc("Recognize and construct Pascal-style "
438 "string literals"));
Steve Naroff73a07032008-02-07 03:50:06 +0000439
440static llvm::cl::opt<bool>
441MSExtensions("fms-extensions",
442 llvm::cl::desc("Accept some non-standard constructs used in "
Sanjiv Gupta69683532008-05-08 08:28:14 +0000443 "Microsoft header files "));
Chris Lattnerdb6be562007-11-28 05:34:05 +0000444
445static llvm::cl::opt<bool>
446WritableStrings("fwritable-strings",
Sanjiv Gupta69683532008-05-08 08:28:14 +0000447 llvm::cl::desc("Store string literals as writable data"));
Anders Carlssone87cd982007-11-30 04:21:22 +0000448
449static llvm::cl::opt<bool>
450LaxVectorConversions("flax-vector-conversions",
451 llvm::cl::desc("Allow implicit conversions between vectors"
452 " with a different number of elements or "
Sanjiv Gupta69683532008-05-08 08:28:14 +0000453 "different element types"));
Ted Kremenek2658c4a2008-04-29 04:37:03 +0000454
Daniel Dunbar91692d92008-08-11 17:36:14 +0000455// FIXME: This (and all GCC -f options) really come in -f... and
456// -fno-... forms, and additionally support automagic behavior when
457// they are not defined. For example, -fexceptions defaults to on or
458// off depending on the language. We should support this behavior in
459// some form (perhaps just add a facility for distinguishing when an
460// has its default value from when it has been set to its default
461// value).
462static llvm::cl::opt<bool>
463Exceptions("fexceptions",
464 llvm::cl::desc("Enable support for exception handling."));
465
Daniel Dunbar1be1df32008-08-11 21:35:06 +0000466static llvm::cl::opt<bool>
467GNURuntime("fgnu-runtime",
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000468 llvm::cl::desc("Generate output compatible with the standard GNU "
469 "Objective-C runtime."));
Daniel Dunbar1be1df32008-08-11 21:35:06 +0000470
471static llvm::cl::opt<bool>
472NeXTRuntime("fnext-runtime",
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000473 llvm::cl::desc("Generate output compatible with the NeXT "
474 "runtime."));
Daniel Dunbar1be1df32008-08-11 21:35:06 +0000475
Ted Kremenek88bec0f2008-09-03 21:22:16 +0000476
477
478static llvm::cl::opt<bool>
479Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences."));
480
481static llvm::cl::opt<bool>
482Ansi("ansi", llvm::cl::desc("Equivalent to specifying -std=c89."));
483
Chris Lattner4b009652007-07-25 00:24:17 +0000484// FIXME: add:
Chris Lattner4b009652007-07-25 00:24:17 +0000485// -fdollars-in-identifiers
Anders Carlsson55bfe0d2007-10-15 02:50:23 +0000486// -fpascal-strings
Daniel Dunbar34542952008-08-23 08:43:39 +0000487static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
488 TargetInfo *Target) {
Ted Kremenek88bec0f2008-09-03 21:22:16 +0000489
490 if (Ansi) // "The -ansi option is equivalent to -std=c89."
491 LangStd = lang_c89;
492
Chris Lattner4b009652007-07-25 00:24:17 +0000493 if (LangStd == lang_unspecified) {
494 // Based on the base language, pick one.
Ted Kremenek11ad8952007-12-05 23:49:08 +0000495 switch (LK) {
Chris Lattner4b009652007-07-25 00:24:17 +0000496 default: assert(0 && "Unknown base language");
497 case langkind_c:
Chris Lattnera19689a2008-10-22 17:29:21 +0000498 case langkind_asm_cpp:
Chris Lattner4b009652007-07-25 00:24:17 +0000499 case langkind_c_cpp:
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000500 case langkind_c_pch:
Chris Lattner4b009652007-07-25 00:24:17 +0000501 case langkind_objc:
502 case langkind_objc_cpp:
Ted Kremenek71c6cc62008-10-21 00:54:44 +0000503 case langkind_objc_pch:
Chris Lattner4b009652007-07-25 00:24:17 +0000504 LangStd = lang_gnu99;
505 break;
506 case langkind_cxx:
507 case langkind_cxx_cpp:
508 case langkind_objcxx:
509 case langkind_objcxx_cpp:
510 LangStd = lang_gnucxx98;
511 break;
512 }
513 }
514
515 switch (LangStd) {
516 default: assert(0 && "Unknown language standard!");
517
518 // Fall through from newer standards to older ones. This isn't really right.
519 // FIXME: Enable specifically the right features based on the language stds.
520 case lang_gnucxx0x:
521 case lang_cxx0x:
522 Options.CPlusPlus0x = 1;
523 // FALL THROUGH
524 case lang_gnucxx98:
525 case lang_cxx98:
526 Options.CPlusPlus = 1;
527 Options.CXXOperatorNames = !NoOperatorNames;
Nate Begemanca893342007-11-15 07:30:50 +0000528 Options.Boolean = 1;
Chris Lattner4b009652007-07-25 00:24:17 +0000529 // FALL THROUGH.
530 case lang_gnu99:
531 case lang_c99:
Chris Lattner4b009652007-07-25 00:24:17 +0000532 Options.C99 = 1;
533 Options.HexFloats = 1;
534 // FALL THROUGH.
535 case lang_gnu89:
536 Options.BCPLComment = 1; // Only for C99/C++.
537 // FALL THROUGH.
538 case lang_c94:
Chris Lattner0297c762008-02-25 04:01:39 +0000539 Options.Digraphs = 1; // C94, C99, C++.
540 // FALL THROUGH.
Chris Lattner4b009652007-07-25 00:24:17 +0000541 case lang_c89:
542 break;
543 }
Argiris Kirtzidisb1519552008-09-11 04:21:06 +0000544
545 if (Options.CPlusPlus) {
546 Options.C99 = 0;
547 Options.HexFloats = (LangStd == lang_gnucxx98 || LangStd==lang_gnucxx0x);
548 }
Chris Lattner4b009652007-07-25 00:24:17 +0000549
Chris Lattner6ab935b2008-04-05 06:32:51 +0000550 if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
551 Options.ImplicitInt = 1;
552 else
553 Options.ImplicitInt = 0;
Ted Kremenek88bec0f2008-09-03 21:22:16 +0000554
555 // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs or -ansi
556 // is specified, or -std is set to a conforming mode.
557 Options.Trigraphs = LangStd < lang_gnu_START || Trigraphs ? 1 : 0;
558
Chris Lattner4b009652007-07-25 00:24:17 +0000559 Options.DollarIdents = 1; // FIXME: Really a target property.
Anders Carlsson55bfe0d2007-10-15 02:50:23 +0000560 Options.PascalStrings = PascalStrings;
Steve Naroff73a07032008-02-07 03:50:06 +0000561 Options.Microsoft = MSExtensions;
Chris Lattnerdb6be562007-11-28 05:34:05 +0000562 Options.WritableStrings = WritableStrings;
Anders Carlssone87cd982007-11-30 04:21:22 +0000563 Options.LaxVectorConversions = LaxVectorConversions;
Daniel Dunbar91692d92008-08-11 17:36:14 +0000564 Options.Exceptions = Exceptions;
Daniel Dunbar1be1df32008-08-11 21:35:06 +0000565
566 if (NeXTRuntime) {
567 Options.NeXTRuntime = 1;
568 } else if (GNURuntime) {
569 Options.NeXTRuntime = 0;
570 } else {
Daniel Dunbar34542952008-08-23 08:43:39 +0000571 Options.NeXTRuntime = Target->useNeXTRuntimeAsDefault();
Daniel Dunbar1be1df32008-08-11 21:35:06 +0000572 }
Chris Lattner4b009652007-07-25 00:24:17 +0000573}
574
Ted Kremenek2658c4a2008-04-29 04:37:03 +0000575static llvm::cl::opt<bool>
576ObjCExclusiveGC("fobjc-gc-only",
577 llvm::cl::desc("Use GC exclusively for Objective-C related "
Sanjiv Gupta69683532008-05-08 08:28:14 +0000578 "memory management"));
Ted Kremenek2658c4a2008-04-29 04:37:03 +0000579
580static llvm::cl::opt<bool>
581ObjCEnableGC("fobjc-gc",
Nico Weber0e13eaa2008-08-05 23:33:20 +0000582 llvm::cl::desc("Enable Objective-C garbage collection"));
Ted Kremenek2658c4a2008-04-29 04:37:03 +0000583
584void InitializeGCMode(LangOptions &Options) {
585 if (ObjCExclusiveGC)
586 Options.setGCMode(LangOptions::GCOnly);
587 else if (ObjCEnableGC)
588 Options.setGCMode(LangOptions::HybridGC);
589}
590
591
Chris Lattner4b009652007-07-25 00:24:17 +0000592//===----------------------------------------------------------------------===//
593// Our DiagnosticClient implementation
594//===----------------------------------------------------------------------===//
595
596// FIXME: Werror should take a list of things, -Werror=foo,bar
597static llvm::cl::opt<bool>
598WarningsAsErrors("Werror", llvm::cl::desc("Treat all warnings as errors"));
599
600static llvm::cl::opt<bool>
Chris Lattner3a22b7c2008-05-29 15:36:45 +0000601SilenceWarnings("w", llvm::cl::desc("Do not emit any warnings"));
602
603static llvm::cl::opt<bool>
Chris Lattner4b009652007-07-25 00:24:17 +0000604WarnOnExtensions("pedantic", llvm::cl::init(false),
605 llvm::cl::desc("Issue a warning on uses of GCC extensions"));
606
607static llvm::cl::opt<bool>
608ErrorOnExtensions("pedantic-errors",
609 llvm::cl::desc("Issue an error on uses of GCC extensions"));
610
611static llvm::cl::opt<bool>
Daniel Dunbar4dbd8572008-09-12 18:10:20 +0000612SuppressSystemWarnings("suppress-system-warnings",
Daniel Dunbar35e50942008-09-30 20:49:53 +0000613 llvm::cl::desc("Suppress warnings issued in system headers"),
Daniel Dunbar4dbd8572008-09-12 18:10:20 +0000614 llvm::cl::init(true));
615
616static llvm::cl::opt<bool>
Chris Lattner4b009652007-07-25 00:24:17 +0000617WarnUnusedMacros("Wunused_macros",
618 llvm::cl::desc("Warn for unused macros in the main translation unit"));
619
Ted Kremenek24f59fb2007-11-13 18:37:02 +0000620static llvm::cl::opt<bool>
621WarnFloatEqual("Wfloat-equal",
Sanjiv Gupta69683532008-05-08 08:28:14 +0000622 llvm::cl::desc("Warn about equality comparisons of floating point values"));
Ted Kremenek24f59fb2007-11-13 18:37:02 +0000623
Ted Kremenek4b57bc72007-12-17 17:50:07 +0000624static llvm::cl::opt<bool>
625WarnNoFormatNonLiteral("Wno-format-nonliteral",
Sanjiv Gupta69683532008-05-08 08:28:14 +0000626 llvm::cl::desc("Do not warn about non-literal format strings"));
Ted Kremenek4b57bc72007-12-17 17:50:07 +0000627
Chris Lattnera616ee32008-01-23 17:19:46 +0000628static llvm::cl::opt<bool>
629WarnUndefMacros("Wundef",
630 llvm::cl::desc("Warn on use of undefined macros in #if's"));
631
Chris Lattnerdea31bf2008-05-05 21:18:06 +0000632static llvm::cl::opt<bool>
Ted Kremenekc6e16692008-05-30 16:42:02 +0000633WarnImplicitFunctionDeclaration("Wimplicit-function-declaration",
634 llvm::cl::desc("Warn about uses of implicitly defined functions"));
Chris Lattnera616ee32008-01-23 17:19:46 +0000635
Steve Naroffb91afca2008-10-21 10:37:50 +0000636static llvm::cl::opt<bool>
637WarnNoStrictSelectorMatch("Wno-strict-selector-match",
638 llvm::cl::desc("Do not warn about duplicate methods that have the same size and alignment"),
639 llvm::cl::init(true));
640
Chris Lattner4b009652007-07-25 00:24:17 +0000641/// InitializeDiagnostics - Initialize the diagnostic object, based on the
642/// current command line option settings.
643static void InitializeDiagnostics(Diagnostic &Diags) {
Chris Lattner3a22b7c2008-05-29 15:36:45 +0000644 Diags.setIgnoreAllWarnings(SilenceWarnings);
Chris Lattner4b009652007-07-25 00:24:17 +0000645 Diags.setWarningsAsErrors(WarningsAsErrors);
646 Diags.setWarnOnExtensions(WarnOnExtensions);
647 Diags.setErrorOnExtensions(ErrorOnExtensions);
648
Daniel Dunbar4dbd8572008-09-12 18:10:20 +0000649 // Suppress warnings in system headers unless requested not to.
650 Diags.setSuppressSystemWarnings(SuppressSystemWarnings);
651
Chris Lattner4b009652007-07-25 00:24:17 +0000652 // Silence the "macro is not used" warning unless requested.
653 if (!WarnUnusedMacros)
654 Diags.setDiagnosticMapping(diag::pp_macro_not_used, diag::MAP_IGNORE);
Ted Kremenek24f59fb2007-11-13 18:37:02 +0000655
656 // Silence "floating point comparison" warnings unless requested.
657 if (!WarnFloatEqual)
658 Diags.setDiagnosticMapping(diag::warn_floatingpoint_eq, diag::MAP_IGNORE);
Ted Kremenek4b57bc72007-12-17 17:50:07 +0000659
660 // Silence "format string is not a string literal" warnings if requested
661 if (WarnNoFormatNonLiteral)
Ted Kremenekf0a6ae02007-12-17 17:50:39 +0000662 Diags.setDiagnosticMapping(diag::warn_printf_not_string_constant,
663 diag::MAP_IGNORE);
Chris Lattnera616ee32008-01-23 17:19:46 +0000664 if (!WarnUndefMacros)
665 Diags.setDiagnosticMapping(diag::warn_pp_undef_identifier,diag::MAP_IGNORE);
Steve Naroff606f7072008-02-11 22:40:08 +0000666
Chris Lattnerdea31bf2008-05-05 21:18:06 +0000667 if (!WarnImplicitFunctionDeclaration)
668 Diags.setDiagnosticMapping(diag::warn_implicit_function_decl,
669 diag::MAP_IGNORE);
670
Steve Naroff606f7072008-02-11 22:40:08 +0000671 if (MSExtensions) // MS allows unnamed struct/union fields.
672 Diags.setDiagnosticMapping(diag::w_no_declarators, diag::MAP_IGNORE);
Chris Lattner057a2f52008-05-04 23:52:02 +0000673
674 // If -pedantic-errors is set, turn extensions that warn by default into
675 // errors.
676 if (ErrorOnExtensions) {
677 Diags.setDiagnosticMapping(diag::warn_hex_escape_too_large,
678 diag::MAP_ERROR);
679 Diags.setDiagnosticMapping(diag::warn_octal_escape_too_large,
680 diag::MAP_ERROR);
681 }
Chris Lattner4b009652007-07-25 00:24:17 +0000682}
683
684//===----------------------------------------------------------------------===//
Ted Kremenek0118bb52008-02-18 21:21:23 +0000685// Analysis-specific options.
686//===----------------------------------------------------------------------===//
687
688static llvm::cl::opt<std::string>
689AnalyzeSpecificFunction("analyze-function",
Sanjiv Gupta69683532008-05-08 08:28:14 +0000690 llvm::cl::desc("Run analysis on specific function"));
Ted Kremenek0118bb52008-02-18 21:21:23 +0000691
Ted Kremenek5e1e05c2008-03-07 22:58:01 +0000692static llvm::cl::opt<bool>
Ted Kremenekb1983ba2008-04-10 22:16:52 +0000693TrimGraph("trim-egraph",
Sanjiv Gupta69683532008-05-08 08:28:14 +0000694 llvm::cl::desc("Only show error-related paths in the analysis graph"));
Ted Kremenek5e1e05c2008-03-07 22:58:01 +0000695
Ted Kremenek0118bb52008-02-18 21:21:23 +0000696//===----------------------------------------------------------------------===//
Ted Kremenek40499482007-12-03 22:06:55 +0000697// Target Triple Processing.
698//===----------------------------------------------------------------------===//
699
700static llvm::cl::opt<std::string>
701TargetTriple("triple",
Sanjiv Gupta69683532008-05-08 08:28:14 +0000702 llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)"));
Ted Kremenek40499482007-12-03 22:06:55 +0000703
Chris Lattnerfc457002008-03-05 01:18:20 +0000704static llvm::cl::opt<std::string>
Sanjiv Gupta69683532008-05-08 08:28:14 +0000705Arch("arch", llvm::cl::desc("Specify target architecture (e.g. i686)"));
Ted Kremenek40499482007-12-03 22:06:55 +0000706
Chris Lattner2b168e02008-09-30 01:13:12 +0000707static llvm::cl::opt<std::string>
708MacOSVersionMin("mmacosx-version-min",
709 llvm::cl::desc("Specify target Mac OS/X version (e.g. 10.5)"));
710
Chris Lattner01de9c82008-09-30 20:16:56 +0000711// If -mmacosx-version-min=10.3.9 is specified, change the triple from being
712// something like powerpc-apple-darwin9 to powerpc-apple-darwin7
713static void HandleMacOSVersionMin(std::string &Triple) {
714 std::string::size_type DarwinDashIdx = Triple.find("-darwin");
715 if (DarwinDashIdx == std::string::npos) {
716 fprintf(stderr,
717 "-mmacosx-version-min only valid for darwin (Mac OS/X) targets\n");
718 exit(1);
719 }
720 unsigned DarwinNumIdx = DarwinDashIdx + strlen("-darwin");
721
Chris Lattner01de9c82008-09-30 20:16:56 +0000722 // Remove the number.
723 Triple.resize(DarwinNumIdx);
724
725 // Validate that MacOSVersionMin is a 'version number', starting with 10.[3-9]
726 bool MacOSVersionMinIsInvalid = false;
727 int VersionNum = 0;
728 if (MacOSVersionMin.size() < 4 ||
729 MacOSVersionMin.substr(0, 3) != "10." ||
730 !isdigit(MacOSVersionMin[3])) {
731 MacOSVersionMinIsInvalid = true;
732 } else {
733 const char *Start = MacOSVersionMin.c_str()+3;
734 char *End = 0;
735 VersionNum = (int)strtol(Start, &End, 10);
736
Chris Lattnerd376f6d2008-09-30 20:30:12 +0000737 // The version number must be in the range 0-9.
738 MacOSVersionMinIsInvalid = (unsigned)VersionNum > 9;
739
Chris Lattner01de9c82008-09-30 20:16:56 +0000740 // Turn MacOSVersionMin into a darwin number: e.g. 10.3.9 is 3 -> 7.
741 Triple += llvm::itostr(VersionNum+4);
742
Chris Lattnerd376f6d2008-09-30 20:30:12 +0000743 if (End[0] == '.' && isdigit(End[1]) && End[2] == '\0') { // 10.4.7 is ok.
744 // Add the period piece (.7) to the end of the triple. This gives us
745 // something like ...-darwin8.7
Chris Lattner01de9c82008-09-30 20:16:56 +0000746 Triple += End;
Chris Lattner01de9c82008-09-30 20:16:56 +0000747 } else if (End[0] != '\0') { // "10.4" is ok. 10.4x is not.
748 MacOSVersionMinIsInvalid = true;
749 }
750 }
751
752 if (MacOSVersionMinIsInvalid) {
753 fprintf(stderr,
754 "-mmacosx-version-min=%s is invalid, expected something like '10.4'.\n",
755 MacOSVersionMin.c_str());
756 exit(1);
757 }
758}
759
760/// CreateTargetTriple - Process the various options that affect the target
761/// triple and build a final aggregate triple that we are compiling for.
Chris Lattnerf3d79c32008-03-09 01:35:13 +0000762static std::string CreateTargetTriple() {
Ted Kremenek40499482007-12-03 22:06:55 +0000763 // Initialize base triple. If a -triple option has been specified, use
764 // that triple. Otherwise, default to the host triple.
Chris Lattner210c0cc2007-12-12 05:01:48 +0000765 std::string Triple = TargetTriple;
Daniel Dunbarabe2e542008-10-02 01:21:33 +0000766 if (Triple.empty()) {
767 Triple = LLVM_HOSTTRIPLE;
768
769 // On darwin, we want to update the version to match that of the
770 // host.
771 std::string::size_type DarwinDashIdx = Triple.find("-darwin");
772 if (DarwinDashIdx != std::string::npos) {
773 Triple.resize(DarwinDashIdx + strlen("-darwin"));
774
775 Triple += llvm::sys::osVersion();
776 }
777 }
Ted Kremenek40499482007-12-03 22:06:55 +0000778
Chris Lattnerf3d79c32008-03-09 01:35:13 +0000779 // If -arch foo was specified, remove the architecture from the triple we have
780 // so far and replace it with the specified one.
Chris Lattner2b168e02008-09-30 01:13:12 +0000781 if (!Arch.empty()) {
782 // Decompose the base triple into "arch" and suffix.
783 std::string::size_type FirstDashIdx = Triple.find('-');
Chris Lattnerf3d79c32008-03-09 01:35:13 +0000784
Chris Lattner2b168e02008-09-30 01:13:12 +0000785 if (FirstDashIdx == std::string::npos) {
786 fprintf(stderr,
787 "Malformed target triple: \"%s\" ('-' could not be found).\n",
788 Triple.c_str());
789 exit(1);
790 }
Ted Kremenek40499482007-12-03 22:06:55 +0000791
Chris Lattner2b168e02008-09-30 01:13:12 +0000792 Triple = Arch + std::string(Triple.begin()+FirstDashIdx, Triple.end());
793 }
794
795 // If -mmacosx-version-min=10.3.9 is specified, change the triple from being
796 // something like powerpc-apple-darwin9 to powerpc-apple-darwin7
Chris Lattner01de9c82008-09-30 20:16:56 +0000797 if (!MacOSVersionMin.empty())
798 HandleMacOSVersionMin(Triple);
Ted Kremenek40499482007-12-03 22:06:55 +0000799
Chris Lattner2b168e02008-09-30 01:13:12 +0000800 return Triple;
Ted Kremenek40499482007-12-03 22:06:55 +0000801}
802
803//===----------------------------------------------------------------------===//
Chris Lattner4b009652007-07-25 00:24:17 +0000804// Preprocessor Initialization
805//===----------------------------------------------------------------------===//
806
807// FIXME: Preprocessor builtins to support.
808// -A... - Play with #assertions
809// -undef - Undefine all predefined macros
810
811static llvm::cl::list<std::string>
812D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
813 llvm::cl::desc("Predefine the specified macro"));
814static llvm::cl::list<std::string>
815U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
816 llvm::cl::desc("Undefine the specified macro"));
817
Chris Lattner008da782008-01-10 01:53:41 +0000818static llvm::cl::list<std::string>
819ImplicitIncludes("include", llvm::cl::value_desc("file"),
820 llvm::cl::desc("Include file before parsing"));
821
822
Chris Lattner4b009652007-07-25 00:24:17 +0000823// Append a #define line to Buf for Macro. Macro should be of the form XXX,
824// in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
825// "#define XXX Y z W". To get a #define with no value, use "XXX=".
826static void DefineBuiltinMacro(std::vector<char> &Buf, const char *Macro,
827 const char *Command = "#define ") {
828 Buf.insert(Buf.end(), Command, Command+strlen(Command));
829 if (const char *Equal = strchr(Macro, '=')) {
830 // Turn the = into ' '.
831 Buf.insert(Buf.end(), Macro, Equal);
832 Buf.push_back(' ');
833 Buf.insert(Buf.end(), Equal+1, Equal+strlen(Equal));
834 } else {
835 // Push "macroname 1".
836 Buf.insert(Buf.end(), Macro, Macro+strlen(Macro));
837 Buf.push_back(' ');
838 Buf.push_back('1');
839 }
840 Buf.push_back('\n');
841}
842
Chris Lattner008da782008-01-10 01:53:41 +0000843/// AddImplicitInclude - Add an implicit #include of the specified file to the
844/// predefines buffer.
845static void AddImplicitInclude(std::vector<char> &Buf, const std::string &File){
846 const char *Inc = "#include \"";
847 Buf.insert(Buf.end(), Inc, Inc+strlen(Inc));
848 Buf.insert(Buf.end(), File.begin(), File.end());
849 Buf.push_back('"');
850 Buf.push_back('\n');
851}
852
Chris Lattner4b009652007-07-25 00:24:17 +0000853
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000854/// InitializePreprocessor - Initialize the preprocessor getting it and the
Chris Lattner9d818a22008-04-19 23:25:44 +0000855/// environment ready to process a single file. This returns true on error.
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000856///
Chris Lattner9d818a22008-04-19 23:25:44 +0000857static bool InitializePreprocessor(Preprocessor &PP,
858 bool InitializeSourceMgr,
859 const std::string &InFile) {
Chris Lattner968982d2007-12-15 20:48:40 +0000860 FileManager &FileMgr = PP.getFileManager();
Chris Lattner4b009652007-07-25 00:24:17 +0000861
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000862 // Figure out where to get and map in the main file.
Chris Lattner968982d2007-12-15 20:48:40 +0000863 SourceManager &SourceMgr = PP.getSourceManager();
Ted Kremenek4e9899f2008-04-17 22:31:54 +0000864
865 if (InitializeSourceMgr) {
866 if (InFile != "-") {
867 const FileEntry *File = FileMgr.getFile(InFile);
868 if (File) SourceMgr.createMainFileID(File, SourceLocation());
869 if (SourceMgr.getMainFileID() == 0) {
870 fprintf(stderr, "Error reading '%s'!\n",InFile.c_str());
Chris Lattner9d818a22008-04-19 23:25:44 +0000871 return true;
Ted Kremenek4e9899f2008-04-17 22:31:54 +0000872 }
873 } else {
874 llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
875 if (SB) SourceMgr.createMainFileIDForMemBuffer(SB);
876 if (SourceMgr.getMainFileID() == 0) {
877 fprintf(stderr, "Error reading standard input! Empty?\n");
Chris Lattner9d818a22008-04-19 23:25:44 +0000878 return true;
Ted Kremenek4e9899f2008-04-17 22:31:54 +0000879 }
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000880 }
Chris Lattner4b009652007-07-25 00:24:17 +0000881 }
Sam Bishop61a20782008-04-14 14:41:57 +0000882
Chris Lattner47b6a162008-04-19 23:09:31 +0000883 std::vector<char> PredefineBuffer;
884
Chris Lattner4b009652007-07-25 00:24:17 +0000885 // Add macros from the command line.
Sam Bishop61a20782008-04-14 14:41:57 +0000886 unsigned d = 0, D = D_macros.size();
887 unsigned u = 0, U = U_macros.size();
888 while (d < D || u < U) {
889 if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
890 DefineBuiltinMacro(PredefineBuffer, D_macros[d++].c_str());
891 else
892 DefineBuiltinMacro(PredefineBuffer, U_macros[u++].c_str(), "#undef ");
893 }
894
Chris Lattner008da782008-01-10 01:53:41 +0000895 // FIXME: Read any files specified by -imacros.
896
897 // Add implicit #includes from -include.
898 for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
899 AddImplicitInclude(PredefineBuffer, ImplicitIncludes[i]);
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000900
Chris Lattner47b6a162008-04-19 23:09:31 +0000901 // Null terminate PredefinedBuffer and add it.
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000902 PredefineBuffer.push_back(0);
Chris Lattner47b6a162008-04-19 23:09:31 +0000903 PP.setPredefines(&PredefineBuffer[0]);
Chris Lattnerd1f21e12007-10-09 22:10:18 +0000904
905 // Once we've read this, we're done.
Chris Lattner9d818a22008-04-19 23:25:44 +0000906 return false;
Chris Lattner4b009652007-07-25 00:24:17 +0000907}
908
909//===----------------------------------------------------------------------===//
910// Preprocessor include path information.
911//===----------------------------------------------------------------------===//
912
913// This tool exports a large number of command line options to control how the
914// preprocessor searches for header files. At root, however, the Preprocessor
915// object takes a very simple interface: a list of directories to search for
916//
917// FIXME: -nostdinc,-nostdinc++
Chris Lattnerae3dcc02007-08-26 17:47:35 +0000918// FIXME: -imultilib
Chris Lattner4b009652007-07-25 00:24:17 +0000919//
Chris Lattner008da782008-01-10 01:53:41 +0000920// FIXME: -imacros
Chris Lattner4b009652007-07-25 00:24:17 +0000921
922static llvm::cl::opt<bool>
923nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories"));
924
925// Various command line options. These four add directories to each chain.
926static llvm::cl::list<std::string>
927F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
928 llvm::cl::desc("Add directory to framework include search path"));
929static llvm::cl::list<std::string>
930I_dirs("I", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
931 llvm::cl::desc("Add directory to include search path"));
932static llvm::cl::list<std::string>
933idirafter_dirs("idirafter", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
934 llvm::cl::desc("Add directory to AFTER include search path"));
935static llvm::cl::list<std::string>
936iquote_dirs("iquote", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
937 llvm::cl::desc("Add directory to QUOTE include search path"));
938static llvm::cl::list<std::string>
939isystem_dirs("isystem", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
940 llvm::cl::desc("Add directory to SYSTEM include search path"));
941
942// These handle -iprefix/-iwithprefix/-iwithprefixbefore.
943static llvm::cl::list<std::string>
944iprefix_vals("iprefix", llvm::cl::value_desc("prefix"), llvm::cl::Prefix,
945 llvm::cl::desc("Set the -iwithprefix/-iwithprefixbefore prefix"));
946static llvm::cl::list<std::string>
947iwithprefix_vals("iwithprefix", llvm::cl::value_desc("dir"), llvm::cl::Prefix,
948 llvm::cl::desc("Set directory to SYSTEM include search path with prefix"));
949static llvm::cl::list<std::string>
950iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"),
951 llvm::cl::Prefix,
952 llvm::cl::desc("Set directory to include search path with prefix"));
953
Chris Lattnerae3dcc02007-08-26 17:47:35 +0000954static llvm::cl::opt<std::string>
955isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"),
956 llvm::cl::desc("Set the system root directory (usually /)"));
957
Chris Lattner4b009652007-07-25 00:24:17 +0000958// Finally, implement the code that groks the options above.
Chris Lattner4f022a72008-03-01 08:07:28 +0000959
Chris Lattner4b009652007-07-25 00:24:17 +0000960/// InitializeIncludePaths - Process the -I options and set them in the
961/// HeaderSearch object.
Nico Weber770e3882008-08-22 09:25:22 +0000962void InitializeIncludePaths(const char *Argv0, HeaderSearch &Headers,
963 FileManager &FM, const LangOptions &Lang) {
964 InitHeaderSearch Init(Headers, Verbose, isysroot);
965
Ted Kremenekb4d41e12008-05-31 00:27:00 +0000966 // Handle -I... and -F... options, walking the lists in parallel.
967 unsigned Iidx = 0, Fidx = 0;
968 while (Iidx < I_dirs.size() && Fidx < F_dirs.size()) {
969 if (I_dirs.getPosition(Iidx) < F_dirs.getPosition(Fidx)) {
Nico Weber770e3882008-08-22 09:25:22 +0000970 Init.AddPath(I_dirs[Iidx], InitHeaderSearch::Angled, false, true, false);
Ted Kremenekb4d41e12008-05-31 00:27:00 +0000971 ++Iidx;
972 } else {
Nico Weber770e3882008-08-22 09:25:22 +0000973 Init.AddPath(F_dirs[Fidx], InitHeaderSearch::Angled, false, true, true);
Ted Kremenekb4d41e12008-05-31 00:27:00 +0000974 ++Fidx;
975 }
976 }
Chris Lattner4b009652007-07-25 00:24:17 +0000977
Ted Kremenekb4d41e12008-05-31 00:27:00 +0000978 // Consume what's left from whatever list was longer.
979 for (; Iidx != I_dirs.size(); ++Iidx)
Nico Weber770e3882008-08-22 09:25:22 +0000980 Init.AddPath(I_dirs[Iidx], InitHeaderSearch::Angled, false, true, false);
Ted Kremenekb4d41e12008-05-31 00:27:00 +0000981 for (; Fidx != F_dirs.size(); ++Fidx)
Nico Weber770e3882008-08-22 09:25:22 +0000982 Init.AddPath(F_dirs[Fidx], InitHeaderSearch::Angled, false, true, true);
Chris Lattner4b009652007-07-25 00:24:17 +0000983
984 // Handle -idirafter... options.
985 for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i)
Nico Weber770e3882008-08-22 09:25:22 +0000986 Init.AddPath(idirafter_dirs[i], InitHeaderSearch::After,
987 false, true, false);
Chris Lattner4b009652007-07-25 00:24:17 +0000988
989 // Handle -iquote... options.
990 for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i)
Nico Weber770e3882008-08-22 09:25:22 +0000991 Init.AddPath(iquote_dirs[i], InitHeaderSearch::Quoted, false, true, false);
Chris Lattner4b009652007-07-25 00:24:17 +0000992
993 // Handle -isystem... options.
994 for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i)
Nico Weber770e3882008-08-22 09:25:22 +0000995 Init.AddPath(isystem_dirs[i], InitHeaderSearch::System, false, true, false);
Chris Lattner4b009652007-07-25 00:24:17 +0000996
997 // Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in
998 // parallel, processing the values in order of occurance to get the right
999 // prefixes.
1000 {
1001 std::string Prefix = ""; // FIXME: this isn't the correct default prefix.
1002 unsigned iprefix_idx = 0;
1003 unsigned iwithprefix_idx = 0;
1004 unsigned iwithprefixbefore_idx = 0;
1005 bool iprefix_done = iprefix_vals.empty();
1006 bool iwithprefix_done = iwithprefix_vals.empty();
1007 bool iwithprefixbefore_done = iwithprefixbefore_vals.empty();
1008 while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) {
1009 if (!iprefix_done &&
1010 (iwithprefix_done ||
1011 iprefix_vals.getPosition(iprefix_idx) <
1012 iwithprefix_vals.getPosition(iwithprefix_idx)) &&
1013 (iwithprefixbefore_done ||
1014 iprefix_vals.getPosition(iprefix_idx) <
1015 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
1016 Prefix = iprefix_vals[iprefix_idx];
1017 ++iprefix_idx;
1018 iprefix_done = iprefix_idx == iprefix_vals.size();
1019 } else if (!iwithprefix_done &&
1020 (iwithprefixbefore_done ||
1021 iwithprefix_vals.getPosition(iwithprefix_idx) <
1022 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
Nico Weber770e3882008-08-22 09:25:22 +00001023 Init.AddPath(Prefix+iwithprefix_vals[iwithprefix_idx],
1024 InitHeaderSearch::System, false, false, false);
Chris Lattner4b009652007-07-25 00:24:17 +00001025 ++iwithprefix_idx;
1026 iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size();
1027 } else {
Nico Weber770e3882008-08-22 09:25:22 +00001028 Init.AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx],
1029 InitHeaderSearch::Angled, false, false, false);
Chris Lattner4b009652007-07-25 00:24:17 +00001030 ++iwithprefixbefore_idx;
1031 iwithprefixbefore_done =
1032 iwithprefixbefore_idx == iwithprefixbefore_vals.size();
1033 }
1034 }
1035 }
Chris Lattner4f022a72008-03-01 08:07:28 +00001036
Nico Weber770e3882008-08-22 09:25:22 +00001037 Init.AddDefaultEnvVarPaths(Lang);
Chris Lattner4f022a72008-03-01 08:07:28 +00001038
Chris Lattner3ee4a2f2008-03-03 03:16:03 +00001039 // Add the clang headers, which are relative to the clang driver.
1040 llvm::sys::Path MainExecutablePath =
Chris Lattner716a0542008-03-03 05:57:43 +00001041 llvm::sys::Path::GetMainExecutable(Argv0,
1042 (void*)(intptr_t)InitializeIncludePaths);
Chris Lattner3ee4a2f2008-03-03 03:16:03 +00001043 if (!MainExecutablePath.isEmpty()) {
1044 MainExecutablePath.eraseComponent(); // Remove /clang from foo/bin/clang
1045 MainExecutablePath.eraseComponent(); // Remove /bin from foo/bin
1046 MainExecutablePath.appendComponent("Headers"); // Get foo/Headers
Nico Weber770e3882008-08-22 09:25:22 +00001047 Init.AddPath(MainExecutablePath.c_str(), InitHeaderSearch::System,
1048 false, false, false);
Chris Lattner3ee4a2f2008-03-03 03:16:03 +00001049 }
1050
Nico Weber770e3882008-08-22 09:25:22 +00001051 if (!nostdinc)
1052 Init.AddDefaultSystemIncludePaths(Lang);
Chris Lattner4b009652007-07-25 00:24:17 +00001053
1054 // Now that we have collected all of the include paths, merge them all
1055 // together and tell the preprocessor about them.
1056
Nico Weber770e3882008-08-22 09:25:22 +00001057 Init.Realize();
Chris Lattner4b009652007-07-25 00:24:17 +00001058}
1059
Ted Kremenek01d3bf72008-04-17 21:38:34 +00001060//===----------------------------------------------------------------------===//
1061// Driver PreprocessorFactory - For lazily generating preprocessors ...
1062//===----------------------------------------------------------------------===//
1063
1064namespace {
1065class VISIBILITY_HIDDEN DriverPreprocessorFactory : public PreprocessorFactory {
Ted Kremenek4e9899f2008-04-17 22:31:54 +00001066 const std::string &InFile;
Ted Kremenek01d3bf72008-04-17 21:38:34 +00001067 Diagnostic &Diags;
1068 const LangOptions &LangInfo;
1069 TargetInfo &Target;
1070 SourceManager &SourceMgr;
1071 HeaderSearch &HeaderInfo;
Ted Kremenek4e9899f2008-04-17 22:31:54 +00001072 bool InitializeSourceMgr;
1073
Ted Kremenek01d3bf72008-04-17 21:38:34 +00001074public:
Ted Kremenek4e9899f2008-04-17 22:31:54 +00001075 DriverPreprocessorFactory(const std::string &infile,
1076 Diagnostic &diags, const LangOptions &opts,
Ted Kremenek01d3bf72008-04-17 21:38:34 +00001077 TargetInfo &target, SourceManager &SM,
1078 HeaderSearch &Headers)
Ted Kremenek4e9899f2008-04-17 22:31:54 +00001079 : InFile(infile), Diags(diags), LangInfo(opts), Target(target),
1080 SourceMgr(SM), HeaderInfo(Headers), InitializeSourceMgr(true) {}
1081
Ted Kremenek01d3bf72008-04-17 21:38:34 +00001082
1083 virtual ~DriverPreprocessorFactory() {}
1084
1085 virtual Preprocessor* CreatePreprocessor() {
Ted Kremenek4e9899f2008-04-17 22:31:54 +00001086 Preprocessor* PP = new Preprocessor(Diags, LangInfo, Target,
1087 SourceMgr, HeaderInfo);
1088
Chris Lattner9d818a22008-04-19 23:25:44 +00001089 if (InitializePreprocessor(*PP, InitializeSourceMgr, InFile)) {
Ted Kremenek4e9899f2008-04-17 22:31:54 +00001090 delete PP;
1091 return NULL;
1092 }
1093
Daniel Dunbar35fe5de2008-10-24 22:12:41 +00001094 /// FIXME: PP can only handle one callback
1095 if (ProgAction != PrintPreprocessedInput) {
1096 const char* ErrStr;
1097 bool DFG = CreateDependencyFileGen(PP, OutputFile, InFile, ErrStr);
1098 if (!DFG && ErrStr) {
Ted Kremenekdf349f32008-10-25 20:19:34 +00001099 fprintf(stderr, "%s", ErrStr);
Daniel Dunbar35fe5de2008-10-24 22:12:41 +00001100 return NULL;
1101 }
1102 }
1103
Ted Kremenek4e9899f2008-04-17 22:31:54 +00001104 InitializeSourceMgr = false;
Ted Kremenek4e9899f2008-04-17 22:31:54 +00001105 return PP;
Ted Kremenek01d3bf72008-04-17 21:38:34 +00001106 }
1107};
1108}
Chris Lattner4b009652007-07-25 00:24:17 +00001109
Chris Lattner4b009652007-07-25 00:24:17 +00001110//===----------------------------------------------------------------------===//
1111// Basic Parser driver
1112//===----------------------------------------------------------------------===//
1113
Chris Lattner9d818a22008-04-19 23:25:44 +00001114static void ParseFile(Preprocessor &PP, MinimalAction *PA) {
Chris Lattner4b009652007-07-25 00:24:17 +00001115 Parser P(PP, *PA);
Ted Kremenek17861c52007-12-19 22:51:13 +00001116 PP.EnterMainSourceFile();
Chris Lattner4b009652007-07-25 00:24:17 +00001117
1118 // Parsing the specified input file.
1119 P.ParseTranslationUnit();
1120 delete PA;
1121}
1122
1123//===----------------------------------------------------------------------===//
Daniel Dunbaraa7a0662008-10-23 05:50:47 +00001124// Code generation options
1125//===----------------------------------------------------------------------===//
1126
1127static llvm::cl::opt<bool>
1128OptSize("Os",
1129 llvm::cl::desc("Optimize for size"));
1130
1131// It might be nice to add bounds to the CommandLine library directly.
1132struct OptLevelParser : public llvm::cl::parser<unsigned> {
1133 bool parse(llvm::cl::Option &O, const char *ArgName,
1134 const std::string &Arg, unsigned &Val) {
1135 if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val))
1136 return true;
1137 // FIXME: Support -O4.
1138 if (Val > 3)
1139 return O.error(": '" + Arg + "' invalid optimization level!");
1140 return false;
1141 }
1142};
1143static llvm::cl::opt<unsigned, false, OptLevelParser>
1144OptLevel("O", llvm::cl::Prefix,
1145 llvm::cl::desc("Optimization level"),
1146 llvm::cl::init(0));
1147
1148static void InitializeCompileOptions(CompileOptions &Opts) {
Daniel Dunbaraa7a0662008-10-23 05:50:47 +00001149 Opts.OptimizeSize = OptSize;
Daniel Dunbard725b162008-10-29 07:56:11 +00001150 if (OptSize) {
1151 // -Os implies -O2
1152 // FIXME: Diagnose conflicting options.
1153 Opts.OptimizationLevel = 2;
1154 } else {
1155 Opts.OptimizationLevel = OptLevel;
1156 }
Daniel Dunbar721cbf12008-10-29 03:42:18 +00001157
1158 // FIXME: There are llvm-gcc options to control these selectively.
1159 Opts.InlineFunctions = (Opts.OptimizationLevel > 1);
1160 Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
1161 Opts.SimplifyLibCalls = 1;
Daniel Dunbare8d0ba72008-10-31 09:34:21 +00001162
1163#ifdef NDEBUG
1164 Opts.VerifyModule = 0;
1165#endif
Daniel Dunbaraa7a0662008-10-23 05:50:47 +00001166}
1167
1168//===----------------------------------------------------------------------===//
Chris Lattner4b009652007-07-25 00:24:17 +00001169// Main driver
1170//===----------------------------------------------------------------------===//
1171
Ted Kremeneka36aaef2007-12-05 18:27:04 +00001172/// CreateASTConsumer - Create the ASTConsumer for the corresponding program
1173/// action. These consumers can operate on both ASTs that are freshly
1174/// parsed from source files as well as those deserialized from Bitcode.
Ted Kremenekd890f6a2007-12-19 22:24:34 +00001175static ASTConsumer* CreateASTConsumer(const std::string& InFile,
Ted Kremenek397de012007-12-13 00:37:31 +00001176 Diagnostic& Diag, FileManager& FileMgr,
Chris Lattner8d72ee02008-02-06 01:42:25 +00001177 const LangOptions& LangOpts,
Chris Lattner21f72d62008-04-16 06:11:58 +00001178 Preprocessor *PP,
Ted Kremenek7c65b6c2008-08-05 18:50:11 +00001179 PreprocessorFactory *PPF) {
Ted Kremeneka36aaef2007-12-05 18:27:04 +00001180 switch (ProgAction) {
1181 default:
1182 return NULL;
1183
1184 case ASTPrint:
1185 return CreateASTPrinter();
1186
1187 case ASTDump:
1188 return CreateASTDumper();
1189
1190 case ASTView:
Ted Kremenek24612ae2008-03-18 21:19:49 +00001191 return CreateASTViewer();
1192
1193 case EmitHTML:
Ted Kremenek4e9899f2008-04-17 22:31:54 +00001194 return CreateHTMLPrinter(OutputFile, Diag, PP, PPF);
Ted Kremeneke972d852008-07-02 18:23:21 +00001195
Ted Kremenekd9ceb3d2008-10-23 23:36:29 +00001196 case InheritanceView:
1197 return CreateInheritanceViewer(InheritanceViewCls);
1198
Ted Kremeneka36aaef2007-12-05 18:27:04 +00001199 case TestSerialization:
Ted Kremenek842126e2008-06-04 15:55:15 +00001200 return CreateSerializationTest(Diag, FileMgr);
Ted Kremeneka36aaef2007-12-05 18:27:04 +00001201
Daniel Dunbar85e44e22008-10-21 23:49:24 +00001202 case EmitAssembly:
Ted Kremeneka36aaef2007-12-05 18:27:04 +00001203 case EmitLLVM:
Daniel Dunbaraa7a0662008-10-23 05:50:47 +00001204 case EmitBC: {
1205 BackendAction Act;
1206 if (ProgAction == EmitAssembly) {
1207 Act = Backend_EmitAssembly;
1208 } else if (ProgAction == EmitLLVM) {
1209 Act = Backend_EmitLL;
1210 } else {
1211 Act = Backend_EmitBC;
1212 }
1213 CompileOptions Opts;
1214 InitializeCompileOptions(Opts);
1215 return CreateBackendConsumer(Act, Diag, LangOpts, Opts,
Daniel Dunbar85e44e22008-10-21 23:49:24 +00001216 InFile, OutputFile, GenerateDebugInfo);
Daniel Dunbaraa7a0662008-10-23 05:50:47 +00001217 }
Seo Sanghyeon550a1eb2007-12-24 01:52:34 +00001218
Ted Kremenekbde30332007-12-19 17:25:59 +00001219 case SerializeAST:
Ted Kremenek397de012007-12-13 00:37:31 +00001220 // FIXME: Allow user to tailor where the file is written.
Ted Kremenek842126e2008-06-04 15:55:15 +00001221 return CreateASTSerializer(InFile, OutputFile, Diag);
Ted Kremenek397de012007-12-13 00:37:31 +00001222
Steve Naroff44e81222008-04-14 22:03:09 +00001223 case RewriteObjC:
Chris Lattner673f2bd2008-03-22 00:08:40 +00001224 return CreateCodeRewriterTest(InFile, OutputFile, Diag, LangOpts);
Steve Naroff93c18352008-09-18 14:10:13 +00001225
1226 case RewriteBlocks:
1227 return CreateBlockRewriter(InFile, OutputFile, Diag, LangOpts);
Ted Kremenek81ea7992008-07-02 00:03:09 +00001228
1229 case RunAnalysis:
1230 assert (!AnalysisList.empty());
1231 return CreateAnalysisConsumer(&AnalysisList[0],
1232 &AnalysisList[0]+AnalysisList.size(),
Ted Kremeneka3f825e2008-11-03 23:18:07 +00001233 AnalysisStoreOpt, AnalysisDiagOpt,
Ted Kremenek81ea7992008-07-02 00:03:09 +00001234 Diag, PP, PPF, LangOpts,
1235 AnalyzeSpecificFunction,
Ted Kremenekcf262252008-08-27 22:31:43 +00001236 OutputFile, VisualizeEGDot, VisualizeEGUbi,
1237 TrimGraph, AnalyzeAll);
Ted Kremeneka36aaef2007-12-05 18:27:04 +00001238 }
1239}
1240
Chris Lattner4b009652007-07-25 00:24:17 +00001241/// ProcessInputFile - Process a single input file with the specified state.
1242///
Ted Kremenek4e9899f2008-04-17 22:31:54 +00001243static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
Ted Kremenek71c6cc62008-10-21 00:54:44 +00001244 const std::string &InFile, ProgActions PA) {
Ted Kremenek50aab982008-08-08 02:46:37 +00001245 llvm::OwningPtr<ASTConsumer> Consumer;
Chris Lattner4b009652007-07-25 00:24:17 +00001246 bool ClearSourceMgr = false;
Ted Kremenek6856c632007-09-26 18:39:29 +00001247
Ted Kremenek71c6cc62008-10-21 00:54:44 +00001248 switch (PA) {
Chris Lattner4b009652007-07-25 00:24:17 +00001249 default:
Ted Kremenek50aab982008-08-08 02:46:37 +00001250 Consumer.reset(CreateASTConsumer(InFile, PP.getDiagnostics(),
1251 PP.getFileManager(), PP.getLangOptions(),
1252 &PP, &PPF));
Ted Kremeneka36aaef2007-12-05 18:27:04 +00001253
1254 if (!Consumer) {
1255 fprintf(stderr, "Unexpected program action!\n");
Daniel Dunbar70a66b12008-10-04 23:42:49 +00001256 HadErrors = true;
Ted Kremeneka36aaef2007-12-05 18:27:04 +00001257 return;
1258 }
Ted Kremenekd890f6a2007-12-19 22:24:34 +00001259
Ted Kremeneka36aaef2007-12-05 18:27:04 +00001260 break;
1261
Chris Lattneraf669fb2008-10-12 05:03:36 +00001262 case DumpRawTokens: {
1263 SourceManager &SM = PP.getSourceManager();
1264 std::pair<const char*,const char*> File =
1265 SM.getBufferData(SM.getMainFileID());
1266 // Start lexing the specified input file.
1267 Lexer RawLex(SourceLocation::getFileLoc(SM.getMainFileID(), 0),
1268 PP.getLangOptions(), File.first, File.second);
1269 RawLex.SetKeepWhitespaceMode(true);
1270
1271 Token RawTok;
1272
1273 RawLex.LexFromRawLexer(RawTok);
1274 while (RawTok.isNot(tok::eof)) {
1275 PP.DumpToken(RawTok, true);
1276 fprintf(stderr, "\n");
1277 RawLex.LexFromRawLexer(RawTok);
1278 }
1279 ClearSourceMgr = true;
1280 break;
1281 }
Chris Lattner4b009652007-07-25 00:24:17 +00001282 case DumpTokens: { // Token dump mode.
1283 Token Tok;
Chris Lattneraf669fb2008-10-12 05:03:36 +00001284 // Start preprocessing the specified input file.
Ted Kremenek17861c52007-12-19 22:51:13 +00001285 PP.EnterMainSourceFile();
Chris Lattner4b009652007-07-25 00:24:17 +00001286 do {
1287 PP.Lex(Tok);
1288 PP.DumpToken(Tok, true);
1289 fprintf(stderr, "\n");
Chris Lattner3b494152007-10-09 18:03:42 +00001290 } while (Tok.isNot(tok::eof));
Chris Lattner4b009652007-07-25 00:24:17 +00001291 ClearSourceMgr = true;
1292 break;
1293 }
1294 case RunPreprocessorOnly: { // Just lex as fast as we can, no output.
1295 Token Tok;
1296 // Start parsing the specified input file.
Ted Kremenek17861c52007-12-19 22:51:13 +00001297 PP.EnterMainSourceFile();
Chris Lattner4b009652007-07-25 00:24:17 +00001298 do {
1299 PP.Lex(Tok);
Chris Lattner3b494152007-10-09 18:03:42 +00001300 } while (Tok.isNot(tok::eof));
Chris Lattner4b009652007-07-25 00:24:17 +00001301 ClearSourceMgr = true;
1302 break;
1303 }
Ted Kremenek71c6cc62008-10-21 00:54:44 +00001304
1305 case GeneratePCH: {
1306 CacheTokens(PP, OutputFile);
1307 ClearSourceMgr = true;
1308 break;
1309 }
Chris Lattner4b009652007-07-25 00:24:17 +00001310
1311 case PrintPreprocessedInput: // -E mode.
Chris Lattnerefd02a32008-01-27 23:55:11 +00001312 DoPrintPreprocessedInput(PP, OutputFile);
Chris Lattner4b009652007-07-25 00:24:17 +00001313 ClearSourceMgr = true;
1314 break;
Chris Lattner1665a9f2008-05-08 06:52:13 +00001315
Chris Lattner4b009652007-07-25 00:24:17 +00001316 case ParseNoop: // -parse-noop
Daniel Dunbar747a95e2008-10-31 08:56:51 +00001317 ParseFile(PP, new MinimalAction(PP));
Chris Lattner4b009652007-07-25 00:24:17 +00001318 ClearSourceMgr = true;
1319 break;
1320
1321 case ParsePrintCallbacks:
Daniel Dunbar747a95e2008-10-31 08:56:51 +00001322 ParseFile(PP, CreatePrintParserActionsAction(PP));
Chris Lattner4b009652007-07-25 00:24:17 +00001323 ClearSourceMgr = true;
1324 break;
Ted Kremenek0841c702007-09-25 18:37:20 +00001325
Ted Kremenek6856c632007-09-26 18:39:29 +00001326 case ParseSyntaxOnly: // -fsyntax-only
Ted Kremenek50aab982008-08-08 02:46:37 +00001327 Consumer.reset(new ASTConsumer());
Ted Kremenek0a03ce62007-09-17 20:49:30 +00001328 break;
Chris Lattner1665a9f2008-05-08 06:52:13 +00001329
1330 case RewriteMacros:
Chris Lattner302b0622008-05-09 22:43:24 +00001331 RewriteMacrosInInput(PP, InFile, OutputFile);
Chris Lattner1665a9f2008-05-08 06:52:13 +00001332 ClearSourceMgr = true;
1333 break;
Chris Lattnerc3fbf392008-10-12 05:29:20 +00001334
1335 case RewriteTest:
1336 DoRewriteTest(PP, InFile, OutputFile);
1337 ClearSourceMgr = true;
1338 break;
Chris Lattner129758d2007-09-16 19:46:59 +00001339 }
Ted Kremenek6856c632007-09-26 18:39:29 +00001340
Daniel Dunbar849bfc62008-10-27 22:03:52 +00001341 if (Consumer)
Daniel Dunbar4efedde2008-10-16 16:54:18 +00001342 ParseAST(PP, Consumer.get(), Stats, !DisableFree);
Daniel Dunbar849bfc62008-10-27 22:03:52 +00001343
1344 if (VerifyDiagnostics)
Daniel Dunbar8d4dff52008-10-27 22:10:13 +00001345 if (CheckDiagnostics(PP))
1346 exit(1);
Chris Lattner8d72ee02008-02-06 01:42:25 +00001347
Chris Lattner4b009652007-07-25 00:24:17 +00001348 if (Stats) {
Ted Kremenekd890f6a2007-12-19 22:24:34 +00001349 fprintf(stderr, "\nSTATISTICS FOR '%s':\n", InFile.c_str());
Chris Lattner4b009652007-07-25 00:24:17 +00001350 PP.PrintStats();
1351 PP.getIdentifierTable().PrintStats();
Chris Lattner968982d2007-12-15 20:48:40 +00001352 PP.getHeaderSearchInfo().PrintStats();
Chris Lattner4b009652007-07-25 00:24:17 +00001353 if (ClearSourceMgr)
Chris Lattner968982d2007-12-15 20:48:40 +00001354 PP.getSourceManager().PrintStats();
Chris Lattner4b009652007-07-25 00:24:17 +00001355 fprintf(stderr, "\n");
1356 }
1357
1358 // For a multi-file compilation, some things are ok with nuking the source
1359 // manager tables, other require stable fileid/macroid's across multiple
1360 // files.
Chris Lattner968982d2007-12-15 20:48:40 +00001361 if (ClearSourceMgr)
1362 PP.getSourceManager().clearIDTables();
Daniel Dunbar622d6d02008-11-11 06:35:39 +00001363
1364 if (DisableFree)
1365 Consumer.take();
Chris Lattner4b009652007-07-25 00:24:17 +00001366}
1367
Ted Kremenek80d53372007-12-12 23:41:08 +00001368static void ProcessSerializedFile(const std::string& InFile, Diagnostic& Diag,
1369 FileManager& FileMgr) {
1370
1371 if (VerifyDiagnostics) {
1372 fprintf(stderr, "-verify does not yet work with serialized ASTs.\n");
1373 exit (1);
1374 }
1375
1376 llvm::sys::Path Filename(InFile);
1377
1378 if (!Filename.isValid()) {
1379 fprintf(stderr, "serialized file '%s' not available.\n",InFile.c_str());
1380 exit (1);
1381 }
1382
Ted Kremenek863b01f2008-04-23 16:25:39 +00001383 llvm::OwningPtr<TranslationUnit> TU(ReadASTBitcodeFile(Filename, FileMgr));
Ted Kremenek2bd42412007-12-13 18:11:11 +00001384
1385 if (!TU) {
1386 fprintf(stderr, "error: file '%s' could not be deserialized\n",
1387 InFile.c_str());
1388 exit (1);
1389 }
1390
Ted Kremenekab749372007-12-19 19:27:38 +00001391 // Observe that we use the source file name stored in the deserialized
1392 // translation unit, rather than InFile.
Ted Kremenek0c7cd7a2007-12-20 19:47:16 +00001393 llvm::OwningPtr<ASTConsumer>
Ted Kremenek842126e2008-06-04 15:55:15 +00001394 Consumer(CreateASTConsumer(InFile, Diag, FileMgr, TU->getLangOptions(),
Ted Kremenek7c65b6c2008-08-05 18:50:11 +00001395 0, 0));
Nico Weberd2a6ac92008-08-10 19:59:06 +00001396
Ted Kremenek80d53372007-12-12 23:41:08 +00001397 if (!Consumer) {
1398 fprintf(stderr, "Unsupported program action with serialized ASTs!\n");
1399 exit (1);
1400 }
Nico Weberd2a6ac92008-08-10 19:59:06 +00001401
Ted Kremenek863b01f2008-04-23 16:25:39 +00001402 Consumer->Initialize(TU->getContext());
Nico Weberd2a6ac92008-08-10 19:59:06 +00001403
Chris Lattner8d72ee02008-02-06 01:42:25 +00001404 // FIXME: We need to inform Consumer about completed TagDecls as well.
Ted Kremenek80d53372007-12-12 23:41:08 +00001405 for (TranslationUnit::iterator I=TU->begin(), E=TU->end(); I!=E; ++I)
1406 Consumer->HandleTopLevelDecl(*I);
Ted Kremenek80d53372007-12-12 23:41:08 +00001407}
1408
1409
Chris Lattner4b009652007-07-25 00:24:17 +00001410static llvm::cl::list<std::string>
1411InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>"));
1412
Ted Kremenek80d53372007-12-12 23:41:08 +00001413static bool isSerializedFile(const std::string& InFile) {
1414 if (InFile.size() < 4)
1415 return false;
1416
1417 const char* s = InFile.c_str()+InFile.size()-4;
1418
1419 return s[0] == '.' &&
1420 s[1] == 'a' &&
1421 s[2] == 's' &&
1422 s[3] == 't';
1423}
1424
Chris Lattner4b009652007-07-25 00:24:17 +00001425
1426int main(int argc, char **argv) {
Chris Lattner3ee4a2f2008-03-03 03:16:03 +00001427 llvm::cl::ParseCommandLineOptions(argc, argv, " llvm clang cfe\n");
Chris Lattner4b009652007-07-25 00:24:17 +00001428 llvm::sys::PrintStackTraceOnErrorSignal();
1429
1430 // If no input was specified, read from stdin.
1431 if (InputFilenames.empty())
1432 InputFilenames.push_back("-");
Ted Kremenekb240e822007-12-11 23:28:38 +00001433
Chris Lattner4b009652007-07-25 00:24:17 +00001434 // Create a file manager object to provide access to and cache the filesystem.
1435 FileManager FileMgr;
1436
Ted Kremenekb240e822007-12-11 23:28:38 +00001437 // Create the diagnostic client for reporting errors or for
1438 // implementing -verify.
Nico Weberd2a6ac92008-08-10 19:59:06 +00001439 DiagnosticClient* TextDiagClient = 0;
Ted Kremenekfd75e312008-03-27 06:17:42 +00001440
Ted Kremenek5c341732008-08-07 17:49:57 +00001441 if (!VerifyDiagnostics) {
1442 // Print diagnostics to stderr by default.
Chris Lattner92a33532008-11-19 06:56:25 +00001443 TextDiagClient = new TextDiagnosticPrinter(llvm::errs(),
1444 !NoShowColumn,
Ted Kremenek5c341732008-08-07 17:49:57 +00001445 !NoCaretDiagnostics);
1446 } else {
1447 // When checking diagnostics, just buffer them up.
1448 TextDiagClient = new TextDiagnosticBuffer();
1449
1450 if (InputFilenames.size() != 1) {
1451 fprintf(stderr,
1452 "-verify only works on single input files for now.\n");
1453 return 1;
Chris Lattner4b009652007-07-25 00:24:17 +00001454 }
1455 }
Ted Kremenek5c341732008-08-07 17:49:57 +00001456
Chris Lattner4b009652007-07-25 00:24:17 +00001457 // Configure our handling of diagnostics.
Ted Kremenek5c341732008-08-07 17:49:57 +00001458 llvm::OwningPtr<DiagnosticClient> DiagClient(TextDiagClient);
1459 Diagnostic Diags(DiagClient.get());
Ted Kremenekb240e822007-12-11 23:28:38 +00001460 InitializeDiagnostics(Diags);
1461
Chris Lattner45a56e02007-12-05 23:24:17 +00001462 // -I- is a deprecated GCC feature, scan for it and reject it.
1463 for (unsigned i = 0, e = I_dirs.size(); i != e; ++i) {
1464 if (I_dirs[i] == "-") {
Chris Lattnera1433472008-11-18 05:05:28 +00001465 Diags.Report(FullSourceLoc(), diag::err_pp_I_dash_not_supported);
Chris Lattner45a56e02007-12-05 23:24:17 +00001466 I_dirs.erase(I_dirs.begin()+i);
1467 --i;
1468 }
1469 }
Chris Lattner2c77d852008-03-14 06:12:05 +00001470
1471 // Get information about the target being compiled for.
1472 std::string Triple = CreateTargetTriple();
Ted Kremenekec6c5252008-08-07 18:13:12 +00001473 llvm::OwningPtr<TargetInfo> Target(TargetInfo::CreateTargetInfo(Triple));
1474
Chris Lattner2c77d852008-03-14 06:12:05 +00001475 if (Target == 0) {
1476 fprintf(stderr, "Sorry, I don't know what target this is: %s\n",
1477 Triple.c_str());
1478 fprintf(stderr, "Please use -triple or -arch.\n");
1479 exit(1);
1480 }
Chris Lattner45a56e02007-12-05 23:24:17 +00001481
Ted Kremenek81ea7992008-07-02 00:03:09 +00001482 // Are we invoking one or more source analyses?
1483 if (!AnalysisList.empty() && ProgAction == ParseSyntaxOnly)
1484 ProgAction = RunAnalysis;
Ted Kremenekd9ceb3d2008-10-23 23:36:29 +00001485 else if (!InheritanceViewCls.empty()) // C++ visualization?
1486 ProgAction = InheritanceView;
Ted Kremenek5c341732008-08-07 17:49:57 +00001487
Ted Kremenek2a4224a2008-06-06 22:42:39 +00001488 llvm::OwningPtr<SourceManager> SourceMgr;
1489
Chris Lattner4b009652007-07-25 00:24:17 +00001490 for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
Ted Kremenekb240e822007-12-11 23:28:38 +00001491 const std::string &InFile = InputFilenames[i];
Ted Kremenekb240e822007-12-11 23:28:38 +00001492
Ted Kremenek5c341732008-08-07 17:49:57 +00001493 if (isSerializedFile(InFile)) {
1494 Diags.setClient(TextDiagClient);
Ted Kremenek80d53372007-12-12 23:41:08 +00001495 ProcessSerializedFile(InFile,Diags,FileMgr);
Ted Kremenek5c341732008-08-07 17:49:57 +00001496 }
Ted Kremenek80d53372007-12-12 23:41:08 +00001497 else {
1498 /// Create a SourceManager object. This tracks and owns all the file
1499 /// buffers allocated to a translation unit.
Ted Kremenek2a4224a2008-06-06 22:42:39 +00001500 if (!SourceMgr)
1501 SourceMgr.reset(new SourceManager());
1502 else
1503 SourceMgr->clearIDTables();
Ted Kremenekb240e822007-12-11 23:28:38 +00001504
Ted Kremenek80d53372007-12-12 23:41:08 +00001505 // Initialize language options, inferring file types from input filenames.
1506 LangOptions LangInfo;
1507 InitializeBaseLanguage();
1508 LangKind LK = GetLanguage(InFile);
Ted Kremenek71c6cc62008-10-21 00:54:44 +00001509 bool PCH = InitializeLangOptions(LangInfo, LK);
Daniel Dunbar34542952008-08-23 08:43:39 +00001510 InitializeLanguageStandard(LangInfo, LK, Target.get());
Ted Kremenek2658c4a2008-04-29 04:37:03 +00001511 InitializeGCMode(LangInfo);
Ted Kremenek71c6cc62008-10-21 00:54:44 +00001512
Ted Kremenek80d53372007-12-12 23:41:08 +00001513 // Process the -I options and set them in the HeaderInfo.
1514 HeaderSearch HeaderInfo(FileMgr);
Ted Kremenek649465c2008-06-06 01:47:30 +00001515
Chris Lattner3ee4a2f2008-03-03 03:16:03 +00001516 InitializeIncludePaths(argv[0], HeaderInfo, FileMgr, LangInfo);
Ted Kremenek80d53372007-12-12 23:41:08 +00001517
Ted Kremenek80d53372007-12-12 23:41:08 +00001518 // Set up the preprocessor with these options.
Ted Kremenek4e9899f2008-04-17 22:31:54 +00001519 DriverPreprocessorFactory PPFactory(InFile, Diags, LangInfo, *Target,
Ted Kremenek2a4224a2008-06-06 22:42:39 +00001520 *SourceMgr.get(), HeaderInfo);
Ted Kremenek80d53372007-12-12 23:41:08 +00001521
Ted Kremenek01d3bf72008-04-17 21:38:34 +00001522 llvm::OwningPtr<Preprocessor> PP(PPFactory.CreatePreprocessor());
1523
Ted Kremenek4e9899f2008-04-17 22:31:54 +00001524 if (!PP)
Ted Kremenek2578dd02007-12-19 22:29:55 +00001525 continue;
Ted Kremenek5c341732008-08-07 17:49:57 +00001526
1527 // Create the HTMLDiagnosticsClient if we are using one. Otherwise,
1528 // always reset to using TextDiagClient.
1529 llvm::OwningPtr<DiagnosticClient> TmpClient;
Ted Kremenek2578dd02007-12-19 22:29:55 +00001530
Ted Kremenek5c341732008-08-07 17:49:57 +00001531 if (!HTMLDiag.empty()) {
1532 TmpClient.reset(CreateHTMLDiagnosticClient(HTMLDiag, PP.get(),
1533 &PPFactory));
1534 Diags.setClient(TmpClient.get());
1535 }
1536 else
1537 Diags.setClient(TextDiagClient);
1538
1539 // Process the source file.
Ted Kremenek71c6cc62008-10-21 00:54:44 +00001540 ProcessInputFile(*PP, PPFactory, InFile, PCH ? GeneratePCH : ProgAction);
1541
Ted Kremenek2a4224a2008-06-06 22:42:39 +00001542 HeaderInfo.ClearFileInfo();
Ted Kremenek80d53372007-12-12 23:41:08 +00001543
1544 if (Stats)
Ted Kremenek2a4224a2008-06-06 22:42:39 +00001545 SourceMgr->PrintStats();
Ted Kremenek80d53372007-12-12 23:41:08 +00001546 }
Chris Lattner4b009652007-07-25 00:24:17 +00001547 }
Chris Lattner2c77d852008-03-14 06:12:05 +00001548
Ted Kremenekec6c5252008-08-07 18:13:12 +00001549 if (unsigned NumDiagnostics = Diags.getNumDiagnostics())
Chris Lattner4b009652007-07-25 00:24:17 +00001550 fprintf(stderr, "%d diagnostic%s generated.\n", NumDiagnostics,
1551 (NumDiagnostics == 1 ? "" : "s"));
1552
1553 if (Stats) {
Chris Lattner4b009652007-07-25 00:24:17 +00001554 FileMgr.PrintStats();
1555 fprintf(stderr, "\n");
1556 }
1557
Daniel Dunbar8d4dff52008-10-27 22:10:13 +00001558 // If verifying diagnostics and we reached here, all is well.
1559 if (VerifyDiagnostics)
1560 return 0;
1561
Daniel Dunbarbb298c02008-10-28 00:38:08 +00001562 // Managed static deconstruction. Useful for making things like
1563 // -time-passes usable.
1564 llvm::llvm_shutdown();
1565
Daniel Dunbar70a66b12008-10-04 23:42:49 +00001566 return HadErrors || (Diags.getNumErrors() != 0);
Chris Lattner4b009652007-07-25 00:24:17 +00001567}