Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- clang.cpp - C-Language Front-end ---------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 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 | // |
Chris Lattner | dddaa9c | 2009-02-18 01:17:01 +0000 | [diff] [blame] | 20 | // -Wfatal-errors |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 21 | // -ftabstop=width |
| 22 | // |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | |
Eli Friedman | 0ec78fa | 2009-05-19 21:10:40 +0000 | [diff] [blame] | 25 | #include "clang/Frontend/AnalysisConsumer.h" |
Eli Friedman | 8ceb0d9 | 2009-05-18 23:02:01 +0000 | [diff] [blame] | 26 | #include "clang/Frontend/ASTConsumers.h" |
Daniel Dunbar | e1bd4e6 | 2009-03-02 06:16:29 +0000 | [diff] [blame] | 27 | #include "clang/Frontend/CompileOptions.h" |
Douglas Gregor | 558cb56 | 2009-04-02 01:08:08 +0000 | [diff] [blame] | 28 | #include "clang/Frontend/FixItRewriter.h" |
Daniel Dunbar | 50f4f46 | 2009-03-12 10:14:16 +0000 | [diff] [blame] | 29 | #include "clang/Frontend/FrontendDiagnostic.h" |
Daniel Dunbar | e1bd4e6 | 2009-03-02 06:16:29 +0000 | [diff] [blame] | 30 | #include "clang/Frontend/InitHeaderSearch.h" |
Chris Lattner | e116ccf | 2009-04-21 05:40:52 +0000 | [diff] [blame] | 31 | #include "clang/Frontend/InitPreprocessor.h" |
Daniel Dunbar | 50f4f46 | 2009-03-12 10:14:16 +0000 | [diff] [blame] | 32 | #include "clang/Frontend/PathDiagnosticClients.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 33 | #include "clang/Frontend/PCHReader.h" |
Daniel Dunbar | e1bd4e6 | 2009-03-02 06:16:29 +0000 | [diff] [blame] | 34 | #include "clang/Frontend/TextDiagnosticBuffer.h" |
| 35 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
Eli Friedman | b09f6e1 | 2009-05-19 04:14:29 +0000 | [diff] [blame] | 36 | #include "clang/Frontend/Utils.h" |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 37 | #include "clang/Analysis/PathDiagnostic.h" |
Chris Lattner | 8ee3c03 | 2008-02-06 02:01:47 +0000 | [diff] [blame] | 38 | #include "clang/CodeGen/ModuleBuilder.h" |
Chris Lattner | e91c134 | 2008-02-06 00:23:21 +0000 | [diff] [blame] | 39 | #include "clang/Sema/ParseAST.h" |
Chris Lattner | 88eccaf | 2009-01-29 06:55:46 +0000 | [diff] [blame] | 40 | #include "clang/Sema/SemaDiagnostic.h" |
Chris Lattner | 556beb7 | 2007-09-15 22:56:56 +0000 | [diff] [blame] | 41 | #include "clang/AST/ASTConsumer.h" |
Chris Lattner | 1266eca | 2009-03-28 04:31:31 +0000 | [diff] [blame] | 42 | #include "clang/AST/ASTContext.h" |
| 43 | #include "clang/AST/Decl.h" |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 44 | #include "clang/AST/DeclGroup.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 45 | #include "clang/Parse/Parser.h" |
| 46 | #include "clang/Lex/HeaderSearch.h" |
Chris Lattner | db76684 | 2009-02-06 04:16:41 +0000 | [diff] [blame] | 47 | #include "clang/Lex/LexDiagnostic.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 48 | #include "clang/Basic/FileManager.h" |
| 49 | #include "clang/Basic/SourceManager.h" |
| 50 | #include "clang/Basic/TargetInfo.h" |
Daniel Dunbar | aa338bc | 2009-05-06 04:07:06 +0000 | [diff] [blame] | 51 | #include "clang/Basic/Version.h" |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 52 | #include "llvm/ADT/OwningPtr.h" |
Chris Lattner | 8f3dab8 | 2007-12-15 23:20:07 +0000 | [diff] [blame] | 53 | #include "llvm/ADT/SmallPtrSet.h" |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 54 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 55 | #include "llvm/ADT/StringMap.h" |
Chris Lattner | b8e240e | 2009-04-08 18:24:34 +0000 | [diff] [blame] | 56 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 57 | #include "llvm/Config/config.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 58 | #include "llvm/Support/CommandLine.h" |
Daniel Dunbar | 524b86f | 2008-10-28 00:38:08 +0000 | [diff] [blame] | 59 | #include "llvm/Support/ManagedStatic.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 60 | #include "llvm/Support/MemoryBuffer.h" |
Zhongxing Xu | 2092236 | 2008-11-26 05:23:17 +0000 | [diff] [blame] | 61 | #include "llvm/Support/PluginLoader.h" |
Chris Lattner | 09e94a3 | 2009-03-04 21:41:39 +0000 | [diff] [blame] | 62 | #include "llvm/Support/PrettyStackTrace.h" |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 63 | #include "llvm/Support/Streams.h" |
Chris Lattner | 4709974 | 2009-02-18 01:51:21 +0000 | [diff] [blame] | 64 | #include "llvm/Support/Timer.h" |
Daniel Dunbar | e553a72 | 2008-10-02 01:21:33 +0000 | [diff] [blame] | 65 | #include "llvm/System/Host.h" |
Chris Lattner | dcaa096 | 2008-03-03 03:16:03 +0000 | [diff] [blame] | 66 | #include "llvm/System/Path.h" |
Douglas Gregor | 44cf08e | 2009-05-03 03:52:38 +0000 | [diff] [blame] | 67 | #include "llvm/System/Process.h" |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 68 | #include "llvm/System/Program.h" |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 69 | #include "llvm/System/Signals.h" |
Douglas Gregor | 26df2f0 | 2009-04-02 19:05:20 +0000 | [diff] [blame] | 70 | #include <cstdlib> |
Douglas Gregor | 44cf08e | 2009-05-03 03:52:38 +0000 | [diff] [blame] | 71 | #if HAVE_SYS_TYPES_H |
Douglas Gregor | 68a0d78 | 2009-05-02 00:03:46 +0000 | [diff] [blame] | 72 | # include <sys/types.h> |
| 73 | #endif |
Douglas Gregor | 26df2f0 | 2009-04-02 19:05:20 +0000 | [diff] [blame] | 74 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 75 | using namespace clang; |
| 76 | |
| 77 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 26df2f0 | 2009-04-02 19:05:20 +0000 | [diff] [blame] | 78 | // Source Location Parser |
| 79 | //===----------------------------------------------------------------------===// |
| 80 | |
| 81 | /// \brief A source location that has been parsed on the command line. |
| 82 | struct ParsedSourceLocation { |
| 83 | std::string FileName; |
| 84 | unsigned Line; |
| 85 | unsigned Column; |
| 86 | |
| 87 | /// \brief Try to resolve the file name of a parsed source location. |
| 88 | /// |
| 89 | /// \returns true if there was an error, false otherwise. |
| 90 | bool ResolveLocation(FileManager &FileMgr, RequestedSourceLocation &Result); |
| 91 | }; |
| 92 | |
| 93 | bool |
| 94 | ParsedSourceLocation::ResolveLocation(FileManager &FileMgr, |
| 95 | RequestedSourceLocation &Result) { |
| 96 | const FileEntry *File = FileMgr.getFile(FileName); |
| 97 | if (!File) |
| 98 | return true; |
| 99 | |
| 100 | Result.File = File; |
| 101 | Result.Line = Line; |
| 102 | Result.Column = Column; |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | namespace llvm { |
| 107 | namespace cl { |
| 108 | /// \brief Command-line option parser that parses source locations. |
| 109 | /// |
| 110 | /// Source locations are of the form filename:line:column. |
| 111 | template<> |
| 112 | class parser<ParsedSourceLocation> |
| 113 | : public basic_parser<ParsedSourceLocation> { |
| 114 | public: |
| 115 | bool parse(Option &O, const char *ArgName, |
| 116 | const std::string &ArgValue, |
| 117 | ParsedSourceLocation &Val); |
| 118 | }; |
| 119 | |
| 120 | bool |
| 121 | parser<ParsedSourceLocation>:: |
| 122 | parse(Option &O, const char *ArgName, const std::string &ArgValue, |
| 123 | ParsedSourceLocation &Val) { |
| 124 | using namespace clang; |
| 125 | |
| 126 | const char *ExpectedFormat |
| 127 | = "source location must be of the form filename:line:column"; |
| 128 | std::string::size_type SecondColon = ArgValue.rfind(':'); |
| 129 | if (SecondColon == std::string::npos) { |
| 130 | std::fprintf(stderr, "%s\n", ExpectedFormat); |
| 131 | return true; |
| 132 | } |
| 133 | char *EndPtr; |
| 134 | long Column |
| 135 | = std::strtol(ArgValue.c_str() + SecondColon + 1, &EndPtr, 10); |
| 136 | if (EndPtr != ArgValue.c_str() + ArgValue.size()) { |
| 137 | std::fprintf(stderr, "%s\n", ExpectedFormat); |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | std::string::size_type FirstColon = ArgValue.rfind(':', SecondColon-1); |
| 142 | if (SecondColon == std::string::npos) { |
| 143 | std::fprintf(stderr, "%s\n", ExpectedFormat); |
| 144 | return true; |
| 145 | } |
| 146 | long Line = std::strtol(ArgValue.c_str() + FirstColon + 1, &EndPtr, 10); |
| 147 | if (EndPtr != ArgValue.c_str() + SecondColon) { |
| 148 | std::fprintf(stderr, "%s\n", ExpectedFormat); |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | Val.FileName = ArgValue.substr(0, FirstColon); |
| 153 | Val.Line = Line; |
| 154 | Val.Column = Column; |
| 155 | return false; |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | //===----------------------------------------------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 161 | // Global options. |
| 162 | //===----------------------------------------------------------------------===// |
| 163 | |
Chris Lattner | 4709974 | 2009-02-18 01:51:21 +0000 | [diff] [blame] | 164 | /// ClangFrontendTimer - The front-end activities should charge time to it with |
| 165 | /// TimeRegion. The -ftime-report option controls whether this will do |
| 166 | /// anything. |
| 167 | llvm::Timer *ClangFrontendTimer = 0; |
| 168 | |
Daniel Dunbar | d3db401 | 2008-10-16 16:54:18 +0000 | [diff] [blame] | 169 | static bool HadErrors = false; |
Daniel Dunbar | b0adbba | 2008-10-04 23:42:49 +0000 | [diff] [blame] | 170 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 171 | static llvm::cl::opt<bool> |
| 172 | Verbose("v", llvm::cl::desc("Enable verbose output")); |
| 173 | static llvm::cl::opt<bool> |
Nate Begeman | aabbb12 | 2007-12-30 01:38:50 +0000 | [diff] [blame] | 174 | Stats("print-stats", |
| 175 | llvm::cl::desc("Print performance metrics and statistics")); |
Daniel Dunbar | d3db401 | 2008-10-16 16:54:18 +0000 | [diff] [blame] | 176 | static llvm::cl::opt<bool> |
| 177 | DisableFree("disable-free", |
| 178 | llvm::cl::desc("Disable freeing of memory on exit"), |
| 179 | llvm::cl::init(false)); |
Daniel Dunbar | 57cbfc0 | 2009-04-27 21:19:07 +0000 | [diff] [blame] | 180 | static llvm::cl::opt<bool> |
| 181 | EmptyInputOnly("empty-input-only", |
| 182 | llvm::cl::desc("Force running on an empty input file")); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 183 | |
| 184 | enum ProgActions { |
Steve Naroff | b29b427 | 2008-04-14 22:03:09 +0000 | [diff] [blame] | 185 | RewriteObjC, // ObjC->C Rewriter. |
Steve Naroff | 1318895 | 2008-09-18 14:10:13 +0000 | [diff] [blame] | 186 | RewriteBlocks, // ObjC->C Rewriter for Blocks. |
Chris Lattner | b57e3d4 | 2008-05-08 06:52:13 +0000 | [diff] [blame] | 187 | RewriteMacros, // Expand macros but not #includes. |
Chris Lattner | b13c5ee | 2008-10-12 05:29:20 +0000 | [diff] [blame] | 188 | RewriteTest, // Rewriter playground |
Douglas Gregor | 558cb56 | 2009-04-02 01:08:08 +0000 | [diff] [blame] | 189 | FixIt, // Fix-It Rewriter |
Ted Kremenek | 13e479b | 2008-03-19 07:53:42 +0000 | [diff] [blame] | 190 | HTMLTest, // HTML displayer testing stuff. |
Daniel Dunbar | d69bacc | 2008-10-21 23:49:24 +0000 | [diff] [blame] | 191 | EmitAssembly, // Emit a .s file. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 192 | EmitLLVM, // Emit a .ll file. |
Seo Sanghyeon | fe947ad | 2007-12-24 01:52:34 +0000 | [diff] [blame] | 193 | EmitBC, // Emit a .bc file. |
Daniel Dunbar | e8e2600 | 2009-02-26 22:39:37 +0000 | [diff] [blame] | 194 | EmitLLVMOnly, // Generate LLVM IR, but do not |
Ted Kremenek | 6a34083 | 2008-03-18 21:19:49 +0000 | [diff] [blame] | 195 | EmitHTML, // Translate input source into HTML. |
Chris Lattner | 3b427b3 | 2007-10-11 00:18:28 +0000 | [diff] [blame] | 196 | ASTPrint, // Parse ASTs and print them. |
Douglas Gregor | ee75c05 | 2009-05-21 20:55:50 +0000 | [diff] [blame] | 197 | ASTPrintXML, // Parse ASTs and print them in XML. |
Chris Lattner | 3b427b3 | 2007-10-11 00:18:28 +0000 | [diff] [blame] | 198 | ASTDump, // Parse ASTs and dump them. |
| 199 | ASTView, // Parse ASTs and view them in Graphviz. |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 200 | PrintDeclContext, // Print DeclContext and their Decls. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 201 | ParsePrintCallbacks, // Parse and print each callback. |
| 202 | ParseSyntaxOnly, // Parse and perform semantic analysis. |
| 203 | ParseNoop, // Parse with noop callbacks. |
| 204 | RunPreprocessorOnly, // Just lex, no output. |
| 205 | PrintPreprocessedInput, // -E mode. |
Chris Lattner | c106c10 | 2008-10-12 05:03:36 +0000 | [diff] [blame] | 206 | DumpTokens, // Dump out preprocessed tokens. |
| 207 | DumpRawTokens, // Dump out raw tokens. |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 208 | RunAnalysis, // Run one or more source code analyses. |
Douglas Gregor | bf1bd6e | 2009-04-02 23:43:50 +0000 | [diff] [blame] | 209 | GeneratePTH, // Generate pre-tokenized header. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 210 | GeneratePCH, // Generate pre-compiled header. |
Ted Kremenek | 7cae2f6 | 2008-10-23 23:36:29 +0000 | [diff] [blame] | 211 | InheritanceView // View C++ inheritance for a specified class. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | static llvm::cl::opt<ProgActions> |
| 215 | ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore, |
| 216 | llvm::cl::init(ParseSyntaxOnly), |
| 217 | llvm::cl::values( |
| 218 | clEnumValN(RunPreprocessorOnly, "Eonly", |
| 219 | "Just run preprocessor, no output (for timings)"), |
| 220 | clEnumValN(PrintPreprocessedInput, "E", |
| 221 | "Run preprocessor, emit preprocessed file"), |
Chris Lattner | c106c10 | 2008-10-12 05:03:36 +0000 | [diff] [blame] | 222 | clEnumValN(DumpRawTokens, "dump-raw-tokens", |
| 223 | "Lex file in raw mode and dump raw tokens"), |
Daniel Dunbar | d427023 | 2009-01-20 23:17:32 +0000 | [diff] [blame] | 224 | clEnumValN(RunAnalysis, "analyze", |
| 225 | "Run static analysis engine"), |
Chris Lattner | c106c10 | 2008-10-12 05:03:36 +0000 | [diff] [blame] | 226 | clEnumValN(DumpTokens, "dump-tokens", |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 227 | "Run preprocessor, dump internal rep of tokens"), |
| 228 | clEnumValN(ParseNoop, "parse-noop", |
| 229 | "Run parser with noop callbacks (for timings)"), |
| 230 | clEnumValN(ParseSyntaxOnly, "fsyntax-only", |
| 231 | "Run parser and perform semantic analysis"), |
| 232 | clEnumValN(ParsePrintCallbacks, "parse-print-callbacks", |
| 233 | "Run parser and print each callback invoked"), |
Ted Kremenek | 6a34083 | 2008-03-18 21:19:49 +0000 | [diff] [blame] | 234 | clEnumValN(EmitHTML, "emit-html", |
| 235 | "Output input source as HTML"), |
Chris Lattner | 3b427b3 | 2007-10-11 00:18:28 +0000 | [diff] [blame] | 236 | clEnumValN(ASTPrint, "ast-print", |
| 237 | "Build ASTs and then pretty-print them"), |
Douglas Gregor | ee75c05 | 2009-05-21 20:55:50 +0000 | [diff] [blame] | 238 | clEnumValN(ASTPrintXML, "ast-print-xml", |
| 239 | "Build ASTs and then print them in XML format"), |
Chris Lattner | 3b427b3 | 2007-10-11 00:18:28 +0000 | [diff] [blame] | 240 | clEnumValN(ASTDump, "ast-dump", |
| 241 | "Build ASTs and then debug dump them"), |
Chris Lattner | ea254db | 2007-10-11 00:37:43 +0000 | [diff] [blame] | 242 | clEnumValN(ASTView, "ast-view", |
Sanjiv Gupta | 56cf96b | 2008-05-08 08:28:14 +0000 | [diff] [blame] | 243 | "Build ASTs and view them with GraphViz"), |
Zhongxing Xu | 2d75d6f | 2009-01-13 01:29:24 +0000 | [diff] [blame] | 244 | clEnumValN(PrintDeclContext, "print-decl-contexts", |
Ted Kremenek | 08478eb | 2009-04-01 00:23:28 +0000 | [diff] [blame] | 245 | "Print DeclContexts and their Decls"), |
Douglas Gregor | bf1bd6e | 2009-04-02 23:43:50 +0000 | [diff] [blame] | 246 | clEnumValN(GeneratePTH, "emit-pth", |
Ted Kremenek | 08478eb | 2009-04-01 00:23:28 +0000 | [diff] [blame] | 247 | "Generate pre-tokenized header file"), |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 248 | clEnumValN(GeneratePCH, "emit-pch", |
| 249 | "Generate pre-compiled header file"), |
Daniel Dunbar | d69bacc | 2008-10-21 23:49:24 +0000 | [diff] [blame] | 250 | clEnumValN(EmitAssembly, "S", |
| 251 | "Emit native assembly code"), |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 252 | clEnumValN(EmitLLVM, "emit-llvm", |
Ted Kremenek | 27b07c5 | 2007-09-06 21:26:58 +0000 | [diff] [blame] | 253 | "Build ASTs then convert to LLVM, emit .ll file"), |
Seo Sanghyeon | fe947ad | 2007-12-24 01:52:34 +0000 | [diff] [blame] | 254 | clEnumValN(EmitBC, "emit-llvm-bc", |
| 255 | "Build ASTs then convert to LLVM, emit .bc file"), |
Daniel Dunbar | e8e2600 | 2009-02-26 22:39:37 +0000 | [diff] [blame] | 256 | clEnumValN(EmitLLVMOnly, "emit-llvm-only", |
| 257 | "Build ASTs and convert to LLVM, discarding output"), |
Chris Lattner | b13c5ee | 2008-10-12 05:29:20 +0000 | [diff] [blame] | 258 | clEnumValN(RewriteTest, "rewrite-test", |
| 259 | "Rewriter playground"), |
Steve Naroff | b29b427 | 2008-04-14 22:03:09 +0000 | [diff] [blame] | 260 | clEnumValN(RewriteObjC, "rewrite-objc", |
Chris Lattner | b57e3d4 | 2008-05-08 06:52:13 +0000 | [diff] [blame] | 261 | "Rewrite ObjC into C (code rewriter example)"), |
| 262 | clEnumValN(RewriteMacros, "rewrite-macros", |
| 263 | "Expand macros without full preprocessing"), |
Steve Naroff | 1318895 | 2008-09-18 14:10:13 +0000 | [diff] [blame] | 264 | clEnumValN(RewriteBlocks, "rewrite-blocks", |
| 265 | "Rewrite Blocks to C"), |
Douglas Gregor | 558cb56 | 2009-04-02 01:08:08 +0000 | [diff] [blame] | 266 | clEnumValN(FixIt, "fixit", |
| 267 | "Apply fix-it advice to the input source"), |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 268 | clEnumValEnd)); |
| 269 | |
Ted Kremenek | ccc7647 | 2007-12-19 19:47:59 +0000 | [diff] [blame] | 270 | |
| 271 | static llvm::cl::opt<std::string> |
| 272 | OutputFile("o", |
Ted Kremenek | 50b5641 | 2007-12-19 19:50:41 +0000 | [diff] [blame] | 273 | llvm::cl::value_desc("path"), |
Douglas Gregor | 370187c | 2009-04-22 21:45:53 +0000 | [diff] [blame] | 274 | llvm::cl::desc("Specify output file")); |
Ted Kremenek | 55af98c | 2008-04-14 18:40:58 +0000 | [diff] [blame] | 275 | |
Ted Kremenek | c2e7299 | 2008-12-02 19:57:31 +0000 | [diff] [blame] | 276 | |
| 277 | //===----------------------------------------------------------------------===// |
| 278 | // PTH. |
| 279 | //===----------------------------------------------------------------------===// |
| 280 | |
| 281 | static llvm::cl::opt<std::string> |
| 282 | TokenCache("token-cache", llvm::cl::value_desc("path"), |
| 283 | llvm::cl::desc("Use specified token cache file")); |
| 284 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 285 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 55af98c | 2008-04-14 18:40:58 +0000 | [diff] [blame] | 286 | // Diagnostic Options |
| 287 | //===----------------------------------------------------------------------===// |
| 288 | |
Ted Kremenek | 41193e4 | 2007-09-26 19:42:19 +0000 | [diff] [blame] | 289 | static llvm::cl::opt<bool> |
| 290 | VerifyDiagnostics("verify", |
Sanjiv Gupta | 56cf96b | 2008-05-08 08:28:14 +0000 | [diff] [blame] | 291 | llvm::cl::desc("Verify emitted diagnostics and warnings")); |
Ted Kremenek | 41193e4 | 2007-09-26 19:42:19 +0000 | [diff] [blame] | 292 | |
Ted Kremenek | 88f5cde | 2008-03-27 06:17:42 +0000 | [diff] [blame] | 293 | static llvm::cl::opt<std::string> |
| 294 | HTMLDiag("html-diags", |
| 295 | llvm::cl::desc("Generate HTML to report diagnostics"), |
| 296 | llvm::cl::value_desc("HTML directory")); |
| 297 | |
Nico Weber | fd54ebc | 2008-08-05 23:33:20 +0000 | [diff] [blame] | 298 | static llvm::cl::opt<bool> |
| 299 | NoShowColumn("fno-show-column", |
| 300 | llvm::cl::desc("Do not include column number on diagnostics")); |
| 301 | |
| 302 | static llvm::cl::opt<bool> |
Chris Lattner | 65f5e64 | 2009-01-30 19:01:41 +0000 | [diff] [blame] | 303 | NoShowLocation("fno-show-source-location", |
| 304 | llvm::cl::desc("Do not include source location information with" |
| 305 | " diagnostics")); |
| 306 | |
| 307 | static llvm::cl::opt<bool> |
Nico Weber | fd54ebc | 2008-08-05 23:33:20 +0000 | [diff] [blame] | 308 | NoCaretDiagnostics("fno-caret-diagnostics", |
| 309 | llvm::cl::desc("Do not include source line and caret with" |
| 310 | " diagnostics")); |
| 311 | |
Chris Lattner | 1fbee5d | 2009-03-13 01:08:23 +0000 | [diff] [blame] | 312 | static llvm::cl::opt<bool> |
Chris Lattner | aa5bf2e | 2009-04-19 07:44:08 +0000 | [diff] [blame] | 313 | NoDiagnosticsFixIt("fno-diagnostics-fixit-info", |
| 314 | llvm::cl::desc("Do not include fixit information in" |
| 315 | " diagnostics")); |
| 316 | |
| 317 | static llvm::cl::opt<bool> |
Chris Lattner | 182e092 | 2009-04-21 05:34:31 +0000 | [diff] [blame] | 318 | PrintSourceRangeInfo("fdiagnostics-print-source-range-info", |
| 319 | llvm::cl::desc("Print source range spans in numeric form")); |
| 320 | |
Chris Lattner | d51d74a | 2009-04-16 05:44:38 +0000 | [diff] [blame] | 321 | static llvm::cl::opt<bool> |
| 322 | PrintDiagnosticOption("fdiagnostics-show-option", |
| 323 | llvm::cl::desc("Print diagnostic name with mappable diagnostics")); |
Nico Weber | fd54ebc | 2008-08-05 23:33:20 +0000 | [diff] [blame] | 324 | |
Douglas Gregor | fffd93f | 2009-05-01 21:53:04 +0000 | [diff] [blame] | 325 | static llvm::cl::opt<unsigned> |
| 326 | MessageLength("fmessage-length", |
| 327 | llvm::cl::desc("Format message diagnostics so that they fit " |
| 328 | "within N columns or fewer, when possible."), |
| 329 | llvm::cl::value_desc("N")); |
| 330 | |
Torok Edwin | 603fca7 | 2009-06-04 07:18:23 +0000 | [diff] [blame] | 331 | static llvm::cl::opt<bool> |
Torok Edwin | a46c71a | 2009-06-04 07:27:53 +0000 | [diff] [blame] | 332 | NoColorDiagnostic("fno-color-diagnostics", |
Torok Edwin | 603fca7 | 2009-06-04 07:18:23 +0000 | [diff] [blame] | 333 | llvm::cl::desc("Don't use colors when showing diagnostics " |
| 334 | "(automatically turned off if output is not a " |
| 335 | "terminal).")); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 336 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 7cae2f6 | 2008-10-23 23:36:29 +0000 | [diff] [blame] | 337 | // C++ Visualization. |
| 338 | //===----------------------------------------------------------------------===// |
| 339 | |
| 340 | static llvm::cl::opt<std::string> |
| 341 | InheritanceViewCls("cxx-inheritance-view", |
| 342 | llvm::cl::value_desc("class name"), |
Daniel Dunbar | d77b251 | 2009-01-14 18:56:36 +0000 | [diff] [blame] | 343 | llvm::cl::desc("View C++ inheritance for a specified class")); |
Ted Kremenek | 7cae2f6 | 2008-10-23 23:36:29 +0000 | [diff] [blame] | 344 | |
| 345 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 3573c0c | 2009-02-14 20:49:29 +0000 | [diff] [blame] | 346 | // Builtin Options |
| 347 | //===----------------------------------------------------------------------===// |
Chris Lattner | b2509e1 | 2009-02-18 01:12:43 +0000 | [diff] [blame] | 348 | |
| 349 | static llvm::cl::opt<bool> |
| 350 | TimeReport("ftime-report", |
| 351 | llvm::cl::desc("Print the amount of time each " |
| 352 | "phase of compilation takes")); |
| 353 | |
Douglas Gregor | 3573c0c | 2009-02-14 20:49:29 +0000 | [diff] [blame] | 354 | static llvm::cl::opt<bool> |
| 355 | Freestanding("ffreestanding", |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 356 | llvm::cl::desc("Assert that the compilation takes place in a " |
Douglas Gregor | 3573c0c | 2009-02-14 20:49:29 +0000 | [diff] [blame] | 357 | "freestanding environment")); |
| 358 | |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 359 | static llvm::cl::opt<bool> |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 360 | AllowBuiltins("fbuiltin", llvm::cl::init(true), |
| 361 | llvm::cl::desc("Disable implicit builtin knowledge of functions")); |
Chris Lattner | 7644f07 | 2009-03-13 22:38:49 +0000 | [diff] [blame] | 362 | |
| 363 | |
| 364 | static llvm::cl::opt<bool> |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 365 | MathErrno("fmath-errno", llvm::cl::init(true), |
| 366 | llvm::cl::desc("Require math functions to respect errno")); |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 367 | |
Douglas Gregor | 3573c0c | 2009-02-14 20:49:29 +0000 | [diff] [blame] | 368 | //===----------------------------------------------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 369 | // Language Options |
| 370 | //===----------------------------------------------------------------------===// |
| 371 | |
| 372 | enum LangKind { |
| 373 | langkind_unspecified, |
| 374 | langkind_c, |
| 375 | langkind_c_cpp, |
Chris Lattner | a778d7d | 2008-10-22 17:29:21 +0000 | [diff] [blame] | 376 | langkind_asm_cpp, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 377 | langkind_cxx, |
| 378 | langkind_cxx_cpp, |
| 379 | langkind_objc, |
| 380 | langkind_objc_cpp, |
| 381 | langkind_objcxx, |
Daniel Dunbar | 0b5b0da | 2009-04-01 05:09:09 +0000 | [diff] [blame] | 382 | langkind_objcxx_cpp |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 383 | }; |
| 384 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 385 | static llvm::cl::opt<LangKind> |
| 386 | BaseLang("x", llvm::cl::desc("Base language to compile"), |
| 387 | llvm::cl::init(langkind_unspecified), |
| 388 | llvm::cl::values(clEnumValN(langkind_c, "c", "C"), |
| 389 | clEnumValN(langkind_cxx, "c++", "C++"), |
| 390 | clEnumValN(langkind_objc, "objective-c", "Objective C"), |
| 391 | clEnumValN(langkind_objcxx,"objective-c++","Objective C++"), |
Daniel Dunbar | d2ea386 | 2009-01-29 23:50:47 +0000 | [diff] [blame] | 392 | clEnumValN(langkind_c_cpp, "cpp-output", |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 393 | "Preprocessed C"), |
Chris Lattner | a778d7d | 2008-10-22 17:29:21 +0000 | [diff] [blame] | 394 | clEnumValN(langkind_asm_cpp, "assembler-with-cpp", |
| 395 | "Preprocessed asm"), |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 396 | clEnumValN(langkind_cxx_cpp, "c++-cpp-output", |
Chris Lattner | c76d807 | 2009-02-06 06:19:20 +0000 | [diff] [blame] | 397 | "Preprocessed C++"), |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 398 | clEnumValN(langkind_objc_cpp, "objective-c-cpp-output", |
| 399 | "Preprocessed Objective C"), |
Chris Lattner | c76d807 | 2009-02-06 06:19:20 +0000 | [diff] [blame] | 400 | clEnumValN(langkind_objcxx_cpp, "objective-c++-cpp-output", |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 401 | "Preprocessed Objective C++"), |
Daniel Dunbar | 0b5b0da | 2009-04-01 05:09:09 +0000 | [diff] [blame] | 402 | clEnumValN(langkind_c, "c-header", |
| 403 | "C header"), |
| 404 | clEnumValN(langkind_objc, "objective-c-header", |
| 405 | "Objective-C header"), |
| 406 | clEnumValN(langkind_cxx, "c++-header", |
| 407 | "C++ header"), |
| 408 | clEnumValN(langkind_objcxx, "objective-c++-header", |
| 409 | "Objective-C++ header"), |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 410 | clEnumValEnd)); |
| 411 | |
| 412 | static llvm::cl::opt<bool> |
| 413 | LangObjC("ObjC", llvm::cl::desc("Set base language to Objective-C"), |
| 414 | llvm::cl::Hidden); |
| 415 | static llvm::cl::opt<bool> |
| 416 | LangObjCXX("ObjC++", llvm::cl::desc("Set base language to Objective-C++"), |
| 417 | llvm::cl::Hidden); |
| 418 | |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 419 | static llvm::cl::opt<bool> |
| 420 | ObjCExclusiveGC("fobjc-gc-only", |
| 421 | llvm::cl::desc("Use GC exclusively for Objective-C related " |
| 422 | "memory management")); |
| 423 | |
| 424 | static llvm::cl::opt<bool> |
| 425 | ObjCEnableGC("fobjc-gc", |
| 426 | llvm::cl::desc("Enable Objective-C garbage collection")); |
| 427 | |
Fariborz Jahanian | 448f5e6 | 2009-04-17 03:04:15 +0000 | [diff] [blame] | 428 | static llvm::cl::opt<bool> |
| 429 | ObjCEnableGCBitmapPrint("print-ivar-layout", |
| 430 | llvm::cl::desc("Enable Objective-C Ivar layout bitmap print trace")); |
| 431 | |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 432 | static llvm::cl::opt<LangOptions::VisibilityMode> |
| 433 | SymbolVisibility("fvisibility", |
| 434 | llvm::cl::desc("Set the default symbol visibility:"), |
| 435 | llvm::cl::init(LangOptions::Default), |
| 436 | llvm::cl::values(clEnumValN(LangOptions::Default, "default", |
| 437 | "Use default symbol visibility"), |
| 438 | clEnumValN(LangOptions::Hidden, "hidden", |
| 439 | "Use hidden symbol visibility"), |
| 440 | clEnumValN(LangOptions::Protected,"protected", |
| 441 | "Use protected symbol visibility"), |
| 442 | clEnumValEnd)); |
| 443 | |
| 444 | static llvm::cl::opt<bool> |
| 445 | OverflowChecking("ftrapv", |
| 446 | llvm::cl::desc("Trap on integer overflow"), |
| 447 | llvm::cl::init(false)); |
| 448 | |
Fariborz Jahanian | 34e6577 | 2009-05-22 20:17:16 +0000 | [diff] [blame] | 449 | static llvm::cl::opt<bool> |
| 450 | ObjCSenderDispatch("fobjc-sender-dependent-dispatch", |
| 451 | llvm::cl::desc("Enable sender-dependent dispatch for" |
| 452 | "Objective-C messages"), llvm::cl::init(false)); |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 453 | |
Ted Kremenek | 8904f15 | 2007-12-05 23:49:08 +0000 | [diff] [blame] | 454 | /// InitializeBaseLanguage - Handle the -x foo options. |
| 455 | static void InitializeBaseLanguage() { |
| 456 | if (LangObjC) |
| 457 | BaseLang = langkind_objc; |
| 458 | else if (LangObjCXX) |
| 459 | BaseLang = langkind_objcxx; |
| 460 | } |
| 461 | |
| 462 | static LangKind GetLanguage(const std::string &Filename) { |
| 463 | if (BaseLang != langkind_unspecified) |
| 464 | return BaseLang; |
| 465 | |
| 466 | std::string::size_type DotPos = Filename.rfind('.'); |
| 467 | |
| 468 | if (DotPos == std::string::npos) { |
| 469 | BaseLang = langkind_c; // Default to C if no extension. |
Chris Lattner | 9b2f6c4 | 2008-01-04 19:12:28 +0000 | [diff] [blame] | 470 | return langkind_c; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Ted Kremenek | 8904f15 | 2007-12-05 23:49:08 +0000 | [diff] [blame] | 473 | std::string Ext = std::string(Filename.begin()+DotPos+1, Filename.end()); |
| 474 | // C header: .h |
| 475 | // C++ header: .hh or .H; |
| 476 | // assembler no preprocessing: .s |
| 477 | // assembler: .S |
| 478 | if (Ext == "c") |
| 479 | return langkind_c; |
Chris Lattner | d9cd4c9 | 2009-03-23 16:24:37 +0000 | [diff] [blame] | 480 | else if (Ext == "S" || |
| 481 | // If the compiler is run on a .s file, preprocess it as .S |
| 482 | Ext == "s") |
Chris Lattner | a778d7d | 2008-10-22 17:29:21 +0000 | [diff] [blame] | 483 | return langkind_asm_cpp; |
Ted Kremenek | 8904f15 | 2007-12-05 23:49:08 +0000 | [diff] [blame] | 484 | else if (Ext == "i") |
| 485 | return langkind_c_cpp; |
| 486 | else if (Ext == "ii") |
| 487 | return langkind_cxx_cpp; |
| 488 | else if (Ext == "m") |
| 489 | return langkind_objc; |
| 490 | else if (Ext == "mi") |
| 491 | return langkind_objc_cpp; |
| 492 | else if (Ext == "mm" || Ext == "M") |
| 493 | return langkind_objcxx; |
| 494 | else if (Ext == "mii") |
| 495 | return langkind_objcxx_cpp; |
| 496 | else if (Ext == "C" || Ext == "cc" || Ext == "cpp" || Ext == "CPP" || |
| 497 | Ext == "c++" || Ext == "cp" || Ext == "cxx") |
| 498 | return langkind_cxx; |
| 499 | else |
| 500 | return langkind_c; |
| 501 | } |
| 502 | |
| 503 | |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 504 | static void InitializeCOptions(LangOptions &Options) { |
| 505 | // Do nothing. |
| 506 | } |
| 507 | |
| 508 | static void InitializeObjCOptions(LangOptions &Options) { |
| 509 | Options.ObjC1 = Options.ObjC2 = 1; |
| 510 | } |
| 511 | |
| 512 | |
Daniel Dunbar | 0b5b0da | 2009-04-01 05:09:09 +0000 | [diff] [blame] | 513 | static void InitializeLangOptions(LangOptions &Options, LangKind LK){ |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 514 | // FIXME: implement -fpreprocessed mode. |
| 515 | bool NoPreprocess = false; |
| 516 | |
Ted Kremenek | 8904f15 | 2007-12-05 23:49:08 +0000 | [diff] [blame] | 517 | switch (LK) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 518 | default: assert(0 && "Unknown language kind!"); |
Chris Lattner | a778d7d | 2008-10-22 17:29:21 +0000 | [diff] [blame] | 519 | case langkind_asm_cpp: |
Daniel Dunbar | c157145 | 2008-12-01 18:55:22 +0000 | [diff] [blame] | 520 | Options.AsmPreprocessor = 1; |
Chris Lattner | a778d7d | 2008-10-22 17:29:21 +0000 | [diff] [blame] | 521 | // FALLTHROUGH |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 522 | case langkind_c_cpp: |
| 523 | NoPreprocess = true; |
| 524 | // FALLTHROUGH |
| 525 | case langkind_c: |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 526 | InitializeCOptions(Options); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 527 | break; |
| 528 | case langkind_cxx_cpp: |
| 529 | NoPreprocess = true; |
| 530 | // FALLTHROUGH |
| 531 | case langkind_cxx: |
| 532 | Options.CPlusPlus = 1; |
| 533 | break; |
| 534 | case langkind_objc_cpp: |
| 535 | NoPreprocess = true; |
| 536 | // FALLTHROUGH |
| 537 | case langkind_objc: |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 538 | InitializeObjCOptions(Options); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 539 | break; |
| 540 | case langkind_objcxx_cpp: |
| 541 | NoPreprocess = true; |
| 542 | // FALLTHROUGH |
| 543 | case langkind_objcxx: |
| 544 | Options.ObjC1 = Options.ObjC2 = 1; |
| 545 | Options.CPlusPlus = 1; |
| 546 | break; |
| 547 | } |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 548 | |
| 549 | if (ObjCExclusiveGC) |
| 550 | Options.setGCMode(LangOptions::GCOnly); |
| 551 | else if (ObjCEnableGC) |
| 552 | Options.setGCMode(LangOptions::HybridGC); |
| 553 | |
Fariborz Jahanian | 448f5e6 | 2009-04-17 03:04:15 +0000 | [diff] [blame] | 554 | if (ObjCEnableGCBitmapPrint) |
| 555 | Options.ObjCGCBitmapPrint = 1; |
| 556 | |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 557 | Options.setVisibilityMode(SymbolVisibility); |
| 558 | Options.OverflowChecking = OverflowChecking; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | /// LangStds - Language standards we support. |
| 562 | enum LangStds { |
| 563 | lang_unspecified, |
| 564 | lang_c89, lang_c94, lang_c99, |
Ted Kremenek | ea644d8 | 2008-09-03 21:22:16 +0000 | [diff] [blame] | 565 | lang_gnu_START, |
| 566 | lang_gnu89 = lang_gnu_START, lang_gnu99, |
Chris Lattner | d4b80f1 | 2007-07-16 04:18:29 +0000 | [diff] [blame] | 567 | lang_cxx98, lang_gnucxx98, |
| 568 | lang_cxx0x, lang_gnucxx0x |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 569 | }; |
| 570 | |
| 571 | static llvm::cl::opt<LangStds> |
| 572 | LangStd("std", llvm::cl::desc("Language standard to compile for"), |
| 573 | llvm::cl::init(lang_unspecified), |
| 574 | llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"), |
| 575 | clEnumValN(lang_c89, "c90", "ISO C 1990"), |
| 576 | clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"), |
| 577 | clEnumValN(lang_c94, "iso9899:199409", |
| 578 | "ISO C 1990 with amendment 1"), |
| 579 | clEnumValN(lang_c99, "c99", "ISO C 1999"), |
Chris Lattner | 50748f4 | 2009-04-06 17:17:55 +0000 | [diff] [blame] | 580 | clEnumValN(lang_c99, "c9x", "ISO C 1999"), |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 581 | clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"), |
Chris Lattner | 50748f4 | 2009-04-06 17:17:55 +0000 | [diff] [blame] | 582 | clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"), |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 583 | clEnumValN(lang_gnu89, "gnu89", |
Gabor Greif | 10b2614 | 2009-02-28 09:22:15 +0000 | [diff] [blame] | 584 | "ISO C 1990 with GNU extensions"), |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 585 | clEnumValN(lang_gnu99, "gnu99", |
Gabor Greif | 10b2614 | 2009-02-28 09:22:15 +0000 | [diff] [blame] | 586 | "ISO C 1999 with GNU extensions (default for C)"), |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 587 | clEnumValN(lang_gnu99, "gnu9x", |
| 588 | "ISO C 1999 with GNU extensions"), |
| 589 | clEnumValN(lang_cxx98, "c++98", |
| 590 | "ISO C++ 1998 with amendments"), |
| 591 | clEnumValN(lang_gnucxx98, "gnu++98", |
| 592 | "ISO C++ 1998 with amendments and GNU " |
| 593 | "extensions (default for C++)"), |
Chris Lattner | d4b80f1 | 2007-07-16 04:18:29 +0000 | [diff] [blame] | 594 | clEnumValN(lang_cxx0x, "c++0x", |
| 595 | "Upcoming ISO C++ 200x with amendments"), |
| 596 | clEnumValN(lang_gnucxx0x, "gnu++0x", |
| 597 | "Upcoming ISO C++ 200x with amendments and GNU " |
Gabor Greif | 5f8d1db | 2009-03-11 23:07:18 +0000 | [diff] [blame] | 598 | "extensions"), |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 599 | clEnumValEnd)); |
| 600 | |
| 601 | static llvm::cl::opt<bool> |
| 602 | NoOperatorNames("fno-operator-names", |
| 603 | llvm::cl::desc("Do not treat C++ operator name keywords as " |
| 604 | "synonyms for operators")); |
| 605 | |
Anders Carlsson | ee98ac5 | 2007-10-15 02:50:23 +0000 | [diff] [blame] | 606 | static llvm::cl::opt<bool> |
| 607 | PascalStrings("fpascal-strings", |
| 608 | llvm::cl::desc("Recognize and construct Pascal-style " |
| 609 | "string literals")); |
Steve Naroff | d62701b | 2008-02-07 03:50:06 +0000 | [diff] [blame] | 610 | |
| 611 | static llvm::cl::opt<bool> |
| 612 | MSExtensions("fms-extensions", |
| 613 | llvm::cl::desc("Accept some non-standard constructs used in " |
Sanjiv Gupta | 56cf96b | 2008-05-08 08:28:14 +0000 | [diff] [blame] | 614 | "Microsoft header files ")); |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 615 | |
| 616 | static llvm::cl::opt<bool> |
| 617 | WritableStrings("fwritable-strings", |
Sanjiv Gupta | 56cf96b | 2008-05-08 08:28:14 +0000 | [diff] [blame] | 618 | llvm::cl::desc("Store string literals as writable data")); |
Anders Carlsson | 695dbb6 | 2007-11-30 04:21:22 +0000 | [diff] [blame] | 619 | |
| 620 | static llvm::cl::opt<bool> |
Anders Carlsson | ad53eff | 2009-01-30 23:26:40 +0000 | [diff] [blame] | 621 | NoLaxVectorConversions("fno-lax-vector-conversions", |
Anders Carlsson | b0f90cc | 2009-01-30 23:17:46 +0000 | [diff] [blame] | 622 | llvm::cl::desc("Disallow implicit conversions between " |
| 623 | "vectors with a different number of " |
| 624 | "elements or different element types")); |
Chris Lattner | ae0ee03 | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 625 | |
Fariborz Jahanian | ee0af74 | 2009-01-21 22:04:16 +0000 | [diff] [blame] | 626 | static llvm::cl::opt<bool> |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 627 | EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature")); |
Mike Stump | a0f02aa | 2009-02-02 22:57:57 +0000 | [diff] [blame] | 628 | |
| 629 | static llvm::cl::opt<bool> |
Chris Lattner | 810f6d5 | 2009-03-13 17:38:01 +0000 | [diff] [blame] | 630 | EnableHeinousExtensions("fheinous-gnu-extensions", |
| 631 | llvm::cl::desc("enable GNU extensions that you really really shouldn't use"), |
| 632 | llvm::cl::ValueDisallowed, llvm::cl::Hidden); |
| 633 | |
| 634 | static llvm::cl::opt<bool> |
Mike Stump | a0f02aa | 2009-02-02 22:57:57 +0000 | [diff] [blame] | 635 | ObjCNonFragileABI("fobjc-nonfragile-abi", |
| 636 | llvm::cl::desc("enable objective-c's nonfragile abi")); |
Fariborz Jahanian | ee0af74 | 2009-01-21 22:04:16 +0000 | [diff] [blame] | 637 | |
Daniel Dunbar | d6884a0 | 2009-05-04 05:16:21 +0000 | [diff] [blame] | 638 | |
| 639 | static llvm::cl::opt<bool> |
Daniel Dunbar | d604c40 | 2009-02-04 21:19:06 +0000 | [diff] [blame] | 640 | EmitAllDecls("femit-all-decls", |
| 641 | llvm::cl::desc("Emit all declarations, even if unused")); |
Ted Kremenek | 01d9dbf | 2008-04-29 04:37:03 +0000 | [diff] [blame] | 642 | |
Daniel Dunbar | 6379a7a | 2008-08-11 17:36:14 +0000 | [diff] [blame] | 643 | static llvm::cl::opt<bool> |
| 644 | Exceptions("fexceptions", |
Chris Lattner | f5db8f8 | 2009-04-19 07:00:02 +0000 | [diff] [blame] | 645 | llvm::cl::desc("Enable support for exception handling")); |
Daniel Dunbar | 6379a7a | 2008-08-11 17:36:14 +0000 | [diff] [blame] | 646 | |
Daniel Dunbar | f77ac86 | 2008-08-11 21:35:06 +0000 | [diff] [blame] | 647 | static llvm::cl::opt<bool> |
| 648 | GNURuntime("fgnu-runtime", |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 649 | llvm::cl::desc("Generate output compatible with the standard GNU " |
Chris Lattner | f5db8f8 | 2009-04-19 07:00:02 +0000 | [diff] [blame] | 650 | "Objective-C runtime")); |
Daniel Dunbar | f77ac86 | 2008-08-11 21:35:06 +0000 | [diff] [blame] | 651 | |
| 652 | static llvm::cl::opt<bool> |
| 653 | NeXTRuntime("fnext-runtime", |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 654 | llvm::cl::desc("Generate output compatible with the NeXT " |
Chris Lattner | f5db8f8 | 2009-04-19 07:00:02 +0000 | [diff] [blame] | 655 | "runtime")); |
Daniel Dunbar | f77ac86 | 2008-08-11 21:35:06 +0000 | [diff] [blame] | 656 | |
Ted Kremenek | ea644d8 | 2008-09-03 21:22:16 +0000 | [diff] [blame] | 657 | |
| 658 | |
| 659 | static llvm::cl::opt<bool> |
Chris Lattner | f5db8f8 | 2009-04-19 07:00:02 +0000 | [diff] [blame] | 660 | Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences")); |
Ted Kremenek | ea644d8 | 2008-09-03 21:22:16 +0000 | [diff] [blame] | 661 | |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 662 | static llvm::cl::opt<unsigned> |
| 663 | TemplateDepth("ftemplate-depth", llvm::cl::init(99), |
| 664 | llvm::cl::desc("Maximum depth of recursive template " |
| 665 | "instantiation")); |
Chris Lattner | f5db8f8 | 2009-04-19 07:00:02 +0000 | [diff] [blame] | 666 | static llvm::cl::opt<bool> |
| 667 | DollarsInIdents("fdollars-in-identifiers", |
| 668 | llvm::cl::desc("Allow '$' in identifiers")); |
Chris Lattner | 16167a6 | 2009-03-02 22:11:07 +0000 | [diff] [blame] | 669 | |
Anders Carlsson | 4ca076f | 2009-04-06 17:37:10 +0000 | [diff] [blame] | 670 | |
| 671 | static llvm::cl::opt<bool> |
| 672 | OptSize("Os", llvm::cl::desc("Optimize for size")); |
| 673 | |
| 674 | static llvm::cl::opt<bool> |
Daniel Dunbar | 877db38 | 2009-06-02 22:07:45 +0000 | [diff] [blame] | 675 | DisableLLVMOptimizations("disable-llvm-optzns", |
| 676 | llvm::cl::desc("Don't run LLVM optimization passes")); |
| 677 | |
| 678 | static llvm::cl::opt<bool> |
Anders Carlsson | 4ca076f | 2009-04-06 17:37:10 +0000 | [diff] [blame] | 679 | NoCommon("fno-common", |
| 680 | llvm::cl::desc("Compile common globals like normal definitions"), |
| 681 | llvm::cl::ValueDisallowed); |
| 682 | |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 683 | static llvm::cl::opt<std::string> |
| 684 | MainFileName("main-file-name", |
| 685 | llvm::cl::desc("Main file name to use for debug info")); |
Anders Carlsson | 4ca076f | 2009-04-06 17:37:10 +0000 | [diff] [blame] | 686 | |
Anders Carlsson | a33d9b4 | 2009-05-13 19:49:53 +0000 | [diff] [blame] | 687 | // FIXME: Also add an "-fno-access-control" option. |
| 688 | static llvm::cl::opt<bool> |
| 689 | AccessControl("faccess-control", |
| 690 | llvm::cl::desc("Enable C++ access control")); |
| 691 | |
Anders Carlsson | 4ca076f | 2009-04-06 17:37:10 +0000 | [diff] [blame] | 692 | // It might be nice to add bounds to the CommandLine library directly. |
| 693 | struct OptLevelParser : public llvm::cl::parser<unsigned> { |
| 694 | bool parse(llvm::cl::Option &O, const char *ArgName, |
| 695 | const std::string &Arg, unsigned &Val) { |
| 696 | if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val)) |
| 697 | return true; |
Anders Carlsson | 4ca076f | 2009-04-06 17:37:10 +0000 | [diff] [blame] | 698 | if (Val > 3) |
| 699 | return O.error(": '" + Arg + "' invalid optimization level!"); |
| 700 | return false; |
| 701 | } |
| 702 | }; |
| 703 | static llvm::cl::opt<unsigned, false, OptLevelParser> |
| 704 | OptLevel("O", llvm::cl::Prefix, |
| 705 | llvm::cl::desc("Optimization level"), |
| 706 | llvm::cl::init(0)); |
| 707 | |
Daniel Dunbar | 9fd0b1f | 2009-04-08 03:03:23 +0000 | [diff] [blame] | 708 | static llvm::cl::opt<unsigned> |
Daniel Dunbar | 3bbc753 | 2009-04-08 18:03:55 +0000 | [diff] [blame] | 709 | PICLevel("pic-level", llvm::cl::desc("Value for __PIC__")); |
| 710 | |
| 711 | static llvm::cl::opt<bool> |
| 712 | StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined")); |
Daniel Dunbar | 9fd0b1f | 2009-04-08 03:03:23 +0000 | [diff] [blame] | 713 | |
Daniel Dunbar | dcb4a1a | 2008-08-23 08:43:39 +0000 | [diff] [blame] | 714 | static void InitializeLanguageStandard(LangOptions &Options, LangKind LK, |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 715 | TargetInfo *Target, |
| 716 | const llvm::StringMap<bool> &Features) { |
Chris Lattner | 8fc4dfb | 2008-12-04 22:54:33 +0000 | [diff] [blame] | 717 | // Allow the target to set the default the langauge options as it sees fit. |
| 718 | Target->getDefaultLangOptions(Options); |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 719 | |
| 720 | // Pass the map of target features to the target for validation and |
| 721 | // processing. |
| 722 | Target->HandleTargetFeatures(Features); |
Chris Lattner | 16167a6 | 2009-03-02 22:11:07 +0000 | [diff] [blame] | 723 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 724 | if (LangStd == lang_unspecified) { |
| 725 | // Based on the base language, pick one. |
Ted Kremenek | 8904f15 | 2007-12-05 23:49:08 +0000 | [diff] [blame] | 726 | switch (LK) { |
Ted Kremenek | f2a17b1 | 2009-03-19 19:02:20 +0000 | [diff] [blame] | 727 | case lang_unspecified: assert(0 && "Unknown base language"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 728 | case langkind_c: |
Chris Lattner | a778d7d | 2008-10-22 17:29:21 +0000 | [diff] [blame] | 729 | case langkind_asm_cpp: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 730 | case langkind_c_cpp: |
| 731 | case langkind_objc: |
| 732 | case langkind_objc_cpp: |
| 733 | LangStd = lang_gnu99; |
| 734 | break; |
| 735 | case langkind_cxx: |
| 736 | case langkind_cxx_cpp: |
| 737 | case langkind_objcxx: |
| 738 | case langkind_objcxx_cpp: |
| 739 | LangStd = lang_gnucxx98; |
| 740 | break; |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | switch (LangStd) { |
| 745 | default: assert(0 && "Unknown language standard!"); |
| 746 | |
| 747 | // Fall through from newer standards to older ones. This isn't really right. |
| 748 | // FIXME: Enable specifically the right features based on the language stds. |
Chris Lattner | d4b80f1 | 2007-07-16 04:18:29 +0000 | [diff] [blame] | 749 | case lang_gnucxx0x: |
| 750 | case lang_cxx0x: |
| 751 | Options.CPlusPlus0x = 1; |
| 752 | // FALL THROUGH |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 753 | case lang_gnucxx98: |
| 754 | case lang_cxx98: |
| 755 | Options.CPlusPlus = 1; |
| 756 | Options.CXXOperatorNames = !NoOperatorNames; |
| 757 | // FALL THROUGH. |
| 758 | case lang_gnu99: |
| 759 | case lang_c99: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 760 | Options.C99 = 1; |
| 761 | Options.HexFloats = 1; |
| 762 | // FALL THROUGH. |
| 763 | case lang_gnu89: |
| 764 | Options.BCPLComment = 1; // Only for C99/C++. |
| 765 | // FALL THROUGH. |
| 766 | case lang_c94: |
Chris Lattner | 3426b9b | 2008-02-25 04:01:39 +0000 | [diff] [blame] | 767 | Options.Digraphs = 1; // C94, C99, C++. |
| 768 | // FALL THROUGH. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 769 | case lang_c89: |
| 770 | break; |
| 771 | } |
Argyrios Kyrtzidis | d146552 | 2008-09-11 04:21:06 +0000 | [diff] [blame] | 772 | |
Chris Lattner | 7e9c90b | 2009-03-20 15:44:26 +0000 | [diff] [blame] | 773 | // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc. |
| 774 | Options.GNUMode = LangStd >= lang_gnu_START; |
| 775 | |
Argyrios Kyrtzidis | d146552 | 2008-09-11 04:21:06 +0000 | [diff] [blame] | 776 | if (Options.CPlusPlus) { |
| 777 | Options.C99 = 0; |
Chris Lattner | 7e9c90b | 2009-03-20 15:44:26 +0000 | [diff] [blame] | 778 | Options.HexFloats = Options.GNUMode; |
Argyrios Kyrtzidis | d146552 | 2008-09-11 04:21:06 +0000 | [diff] [blame] | 779 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 780 | |
Chris Lattner | d658b56 | 2008-04-05 06:32:51 +0000 | [diff] [blame] | 781 | if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89) |
| 782 | Options.ImplicitInt = 1; |
| 783 | else |
| 784 | Options.ImplicitInt = 0; |
Ted Kremenek | ea644d8 | 2008-09-03 21:22:16 +0000 | [diff] [blame] | 785 | |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 786 | // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs |
| 787 | // is specified, or -std is set to a conforming mode. |
Chris Lattner | 7e9c90b | 2009-03-20 15:44:26 +0000 | [diff] [blame] | 788 | Options.Trigraphs = !Options.GNUMode; |
Chris Lattner | 802db9b | 2008-12-05 00:10:44 +0000 | [diff] [blame] | 789 | if (Trigraphs.getPosition()) |
Chris Lattner | 7e9c90b | 2009-03-20 15:44:26 +0000 | [diff] [blame] | 790 | Options.Trigraphs = Trigraphs; // Command line option wins if specified. |
Ted Kremenek | ea644d8 | 2008-09-03 21:22:16 +0000 | [diff] [blame] | 791 | |
Chris Lattner | 802db9b | 2008-12-05 00:10:44 +0000 | [diff] [blame] | 792 | // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off |
| 793 | // even if they are normally on for the target. In GNU modes (e.g. |
| 794 | // -std=gnu99) the default for blocks depends on the target settings. |
Anders Carlsson | e56f6ff | 2009-01-21 18:47:36 +0000 | [diff] [blame] | 795 | // However, blocks are not turned off when compiling Obj-C or Obj-C++ code. |
Chris Lattner | 7e9c90b | 2009-03-20 15:44:26 +0000 | [diff] [blame] | 796 | if (!Options.ObjC1 && !Options.GNUMode) |
Chris Lattner | 802db9b | 2008-12-05 00:10:44 +0000 | [diff] [blame] | 797 | Options.Blocks = 0; |
| 798 | |
Chris Lattner | 01638a6 | 2009-04-19 07:06:52 +0000 | [diff] [blame] | 799 | // Default to not accepting '$' in identifiers when preprocessing assembler, |
| 800 | // but do accept when preprocessing C. FIXME: these defaults are right for |
| 801 | // darwin, are they right everywhere? |
| 802 | Options.DollarIdents = LK != langkind_asm_cpp; |
| 803 | if (DollarsInIdents.getPosition()) // Explicit setting overrides default. |
Chris Lattner | f5db8f8 | 2009-04-19 07:00:02 +0000 | [diff] [blame] | 804 | Options.DollarIdents = DollarsInIdents; |
| 805 | |
Chris Lattner | ae0ee03 | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 806 | if (PascalStrings.getPosition()) |
| 807 | Options.PascalStrings = PascalStrings; |
Steve Naroff | d62701b | 2008-02-07 03:50:06 +0000 | [diff] [blame] | 808 | Options.Microsoft = MSExtensions; |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 809 | Options.WritableStrings = WritableStrings; |
Anders Carlsson | b0f90cc | 2009-01-30 23:17:46 +0000 | [diff] [blame] | 810 | if (NoLaxVectorConversions.getPosition()) |
| 811 | Options.LaxVectorConversions = 0; |
Daniel Dunbar | 6379a7a | 2008-08-11 17:36:14 +0000 | [diff] [blame] | 812 | Options.Exceptions = Exceptions; |
Mike Stump | a0f02aa | 2009-02-02 22:57:57 +0000 | [diff] [blame] | 813 | if (EnableBlocks.getPosition()) |
Chris Lattner | ae0ee03 | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 814 | Options.Blocks = EnableBlocks; |
Daniel Dunbar | f77ac86 | 2008-08-11 21:35:06 +0000 | [diff] [blame] | 815 | |
Daniel Dunbar | 9f9768c | 2009-03-20 23:49:28 +0000 | [diff] [blame] | 816 | if (!AllowBuiltins) |
Chris Lattner | 7644f07 | 2009-03-13 22:38:49 +0000 | [diff] [blame] | 817 | Options.NoBuiltin = 1; |
Douglas Gregor | 3573c0c | 2009-02-14 20:49:29 +0000 | [diff] [blame] | 818 | if (Freestanding) |
Chris Lattner | 7644f07 | 2009-03-13 22:38:49 +0000 | [diff] [blame] | 819 | Options.Freestanding = Options.NoBuiltin = 1; |
| 820 | |
Chris Lattner | 810f6d5 | 2009-03-13 17:38:01 +0000 | [diff] [blame] | 821 | if (EnableHeinousExtensions) |
| 822 | Options.HeinousExtensions = 1; |
Douglas Gregor | 3573c0c | 2009-02-14 20:49:29 +0000 | [diff] [blame] | 823 | |
Anders Carlsson | a33d9b4 | 2009-05-13 19:49:53 +0000 | [diff] [blame] | 824 | if (AccessControl) |
| 825 | Options.AccessControl = 1; |
| 826 | |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 827 | Options.MathErrno = MathErrno; |
| 828 | |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 829 | Options.InstantiationDepth = TemplateDepth; |
| 830 | |
Chris Lattner | 8fc4dfb | 2008-12-04 22:54:33 +0000 | [diff] [blame] | 831 | // Override the default runtime if the user requested it. |
| 832 | if (NeXTRuntime) |
Daniel Dunbar | f77ac86 | 2008-08-11 21:35:06 +0000 | [diff] [blame] | 833 | Options.NeXTRuntime = 1; |
Chris Lattner | 8fc4dfb | 2008-12-04 22:54:33 +0000 | [diff] [blame] | 834 | else if (GNURuntime) |
Daniel Dunbar | f77ac86 | 2008-08-11 21:35:06 +0000 | [diff] [blame] | 835 | Options.NeXTRuntime = 0; |
Fariborz Jahanian | ee0af74 | 2009-01-21 22:04:16 +0000 | [diff] [blame] | 836 | |
Fariborz Jahanian | 30bc571 | 2009-01-22 23:02:58 +0000 | [diff] [blame] | 837 | if (ObjCNonFragileABI) |
| 838 | Options.ObjCNonFragileABI = 1; |
Fariborz Jahanian | 34e6577 | 2009-05-22 20:17:16 +0000 | [diff] [blame] | 839 | |
| 840 | Options.ObjCSenderDispatch = ObjCSenderDispatch; |
Daniel Dunbar | d6884a0 | 2009-05-04 05:16:21 +0000 | [diff] [blame] | 841 | |
Daniel Dunbar | d604c40 | 2009-02-04 21:19:06 +0000 | [diff] [blame] | 842 | if (EmitAllDecls) |
| 843 | Options.EmitAllDecls = 1; |
Anders Carlsson | 4ca076f | 2009-04-06 17:37:10 +0000 | [diff] [blame] | 844 | |
Daniel Dunbar | 3bbc753 | 2009-04-08 18:03:55 +0000 | [diff] [blame] | 845 | // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't |
| 846 | // support. |
| 847 | Options.OptimizeSize = 0; |
Anders Carlsson | 4ca076f | 2009-04-06 17:37:10 +0000 | [diff] [blame] | 848 | |
| 849 | // -Os implies -O2 |
Daniel Dunbar | 3bbc753 | 2009-04-08 18:03:55 +0000 | [diff] [blame] | 850 | if (OptSize || OptLevel) |
Anders Carlsson | 4ca076f | 2009-04-06 17:37:10 +0000 | [diff] [blame] | 851 | Options.Optimize = 1; |
Daniel Dunbar | 9fd0b1f | 2009-04-08 03:03:23 +0000 | [diff] [blame] | 852 | |
| 853 | assert(PICLevel <= 2 && "Invalid value for -pic-level"); |
| 854 | Options.PICLevel = PICLevel; |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 855 | |
Daniel Dunbar | 3bbc753 | 2009-04-08 18:03:55 +0000 | [diff] [blame] | 856 | Options.GNUInline = !Options.C99; |
Chris Lattner | 5aeb9e7 | 2009-05-06 04:38:30 +0000 | [diff] [blame] | 857 | // FIXME: This is affected by other options (-fno-inline). |
Daniel Dunbar | 3bbc753 | 2009-04-08 18:03:55 +0000 | [diff] [blame] | 858 | Options.NoInline = !OptSize && !OptLevel; |
| 859 | |
| 860 | Options.Static = StaticDefine; |
| 861 | |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 862 | if (MainFileName.getPosition()) |
| 863 | Options.setMainFileName(MainFileName.c_str()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | //===----------------------------------------------------------------------===// |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 867 | // Target Triple Processing. |
| 868 | //===----------------------------------------------------------------------===// |
| 869 | |
| 870 | static llvm::cl::opt<std::string> |
| 871 | TargetTriple("triple", |
Sanjiv Gupta | 56cf96b | 2008-05-08 08:28:14 +0000 | [diff] [blame] | 872 | llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)")); |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 873 | |
Chris Lattner | 42e6737 | 2008-03-05 01:18:20 +0000 | [diff] [blame] | 874 | static llvm::cl::opt<std::string> |
Chris Lattner | 6a30c1f | 2008-09-30 01:13:12 +0000 | [diff] [blame] | 875 | MacOSVersionMin("mmacosx-version-min", |
Daniel Dunbar | 8d33cd7 | 2009-04-10 19:52:24 +0000 | [diff] [blame] | 876 | llvm::cl::desc("Specify target Mac OS X version (e.g. 10.5)")); |
Chris Lattner | 6a30c1f | 2008-09-30 01:13:12 +0000 | [diff] [blame] | 877 | |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 878 | // If -mmacosx-version-min=10.3.9 is specified, change the triple from being |
| 879 | // something like powerpc-apple-darwin9 to powerpc-apple-darwin7 |
Daniel Dunbar | 64ffc14 | 2009-03-31 20:10:05 +0000 | [diff] [blame] | 880 | |
| 881 | // FIXME: We should have the driver do this instead. |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 882 | static void HandleMacOSVersionMin(std::string &Triple) { |
| 883 | std::string::size_type DarwinDashIdx = Triple.find("-darwin"); |
| 884 | if (DarwinDashIdx == std::string::npos) { |
| 885 | fprintf(stderr, |
Daniel Dunbar | 8d33cd7 | 2009-04-10 19:52:24 +0000 | [diff] [blame] | 886 | "-mmacosx-version-min only valid for darwin (Mac OS X) targets\n"); |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 887 | exit(1); |
| 888 | } |
| 889 | unsigned DarwinNumIdx = DarwinDashIdx + strlen("-darwin"); |
| 890 | |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 891 | // Remove the number. |
| 892 | Triple.resize(DarwinNumIdx); |
| 893 | |
| 894 | // Validate that MacOSVersionMin is a 'version number', starting with 10.[3-9] |
| 895 | bool MacOSVersionMinIsInvalid = false; |
| 896 | int VersionNum = 0; |
| 897 | if (MacOSVersionMin.size() < 4 || |
| 898 | MacOSVersionMin.substr(0, 3) != "10." || |
| 899 | !isdigit(MacOSVersionMin[3])) { |
| 900 | MacOSVersionMinIsInvalid = true; |
| 901 | } else { |
| 902 | const char *Start = MacOSVersionMin.c_str()+3; |
| 903 | char *End = 0; |
| 904 | VersionNum = (int)strtol(Start, &End, 10); |
| 905 | |
Chris Lattner | 079f2c46 | 2008-09-30 20:30:12 +0000 | [diff] [blame] | 906 | // The version number must be in the range 0-9. |
| 907 | MacOSVersionMinIsInvalid = (unsigned)VersionNum > 9; |
| 908 | |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 909 | // Turn MacOSVersionMin into a darwin number: e.g. 10.3.9 is 3 -> 7. |
| 910 | Triple += llvm::itostr(VersionNum+4); |
| 911 | |
Chris Lattner | 079f2c46 | 2008-09-30 20:30:12 +0000 | [diff] [blame] | 912 | if (End[0] == '.' && isdigit(End[1]) && End[2] == '\0') { // 10.4.7 is ok. |
| 913 | // Add the period piece (.7) to the end of the triple. This gives us |
| 914 | // something like ...-darwin8.7 |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 915 | Triple += End; |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 916 | } else if (End[0] != '\0') { // "10.4" is ok. 10.4x is not. |
| 917 | MacOSVersionMinIsInvalid = true; |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | if (MacOSVersionMinIsInvalid) { |
| 922 | fprintf(stderr, |
Daniel Dunbar | af07f93 | 2009-03-31 17:35:15 +0000 | [diff] [blame] | 923 | "-mmacosx-version-min=%s is invalid, expected something like '10.4'.\n", |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 924 | MacOSVersionMin.c_str()); |
| 925 | exit(1); |
| 926 | } |
Fariborz Jahanian | 6a1284a | 2009-04-10 20:33:45 +0000 | [diff] [blame] | 927 | else if (VersionNum <= 4 && |
| 928 | !strncmp(Triple.c_str(), "x86_64", strlen("x86_64"))) { |
| 929 | fprintf(stderr, |
| 930 | "-mmacosx-version-min=%s is invalid with -arch x86_64.\n", |
| 931 | MacOSVersionMin.c_str()); |
| 932 | exit(1); |
| 933 | } |
| 934 | |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 935 | } |
| 936 | |
Daniel Dunbar | 8d33cd7 | 2009-04-10 19:52:24 +0000 | [diff] [blame] | 937 | static llvm::cl::opt<std::string> |
| 938 | IPhoneOSVersionMin("miphoneos-version-min", |
| 939 | llvm::cl::desc("Specify target iPhone OS version (e.g. 2.0)")); |
| 940 | |
| 941 | // If -miphoneos-version-min=2.2 is specified, change the triple from being |
| 942 | // something like armv6-apple-darwin10 to armv6-apple-darwin9.2.2. We use |
| 943 | // 9 as the default major Darwin number, and encode the iPhone OS version |
| 944 | // number in the minor version and revision. |
| 945 | |
| 946 | // FIXME: We should have the driver do this instead. |
| 947 | static void HandleIPhoneOSVersionMin(std::string &Triple) { |
| 948 | std::string::size_type DarwinDashIdx = Triple.find("-darwin"); |
| 949 | if (DarwinDashIdx == std::string::npos) { |
| 950 | fprintf(stderr, |
| 951 | "-miphoneos-version-min only valid for darwin (Mac OS X) targets\n"); |
| 952 | exit(1); |
| 953 | } |
| 954 | unsigned DarwinNumIdx = DarwinDashIdx + strlen("-darwin"); |
| 955 | |
| 956 | // Remove the number. |
| 957 | Triple.resize(DarwinNumIdx); |
| 958 | |
| 959 | // Validate that IPhoneOSVersionMin is a 'version number', starting with [2-9].[0-9] |
| 960 | bool IPhoneOSVersionMinIsInvalid = false; |
| 961 | int VersionNum = 0; |
| 962 | if (IPhoneOSVersionMin.size() < 3 || |
| 963 | !isdigit(IPhoneOSVersionMin[0])) { |
| 964 | IPhoneOSVersionMinIsInvalid = true; |
| 965 | } else { |
| 966 | const char *Start = IPhoneOSVersionMin.c_str(); |
| 967 | char *End = 0; |
| 968 | VersionNum = (int)strtol(Start, &End, 10); |
| 969 | |
| 970 | // The version number must be in the range 0-9. |
| 971 | IPhoneOSVersionMinIsInvalid = (unsigned)VersionNum > 9; |
| 972 | |
| 973 | // Turn IPhoneOSVersionMin into a darwin number: e.g. 2.0 is 2 -> 9.2. |
| 974 | Triple += "9." + llvm::itostr(VersionNum); |
| 975 | |
| 976 | if (End[0] == '.' && isdigit(End[1]) && End[2] == '\0') { // 2.2 is ok. |
| 977 | // Add the period piece (.2) to the end of the triple. This gives us |
| 978 | // something like ...-darwin9.2.2 |
| 979 | Triple += End; |
| 980 | } else if (End[0] != '\0') { // "2.2" is ok. 2x is not. |
| 981 | IPhoneOSVersionMinIsInvalid = true; |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | if (IPhoneOSVersionMinIsInvalid) { |
| 986 | fprintf(stderr, |
| 987 | "-miphoneos-version-min=%s is invalid, expected something like '2.0'.\n", |
| 988 | IPhoneOSVersionMin.c_str()); |
| 989 | exit(1); |
| 990 | } |
| 991 | } |
| 992 | |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 993 | /// CreateTargetTriple - Process the various options that affect the target |
| 994 | /// triple and build a final aggregate triple that we are compiling for. |
Chris Lattner | 6fd9fa1 | 2008-03-09 01:35:13 +0000 | [diff] [blame] | 995 | static std::string CreateTargetTriple() { |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 996 | // Initialize base triple. If a -triple option has been specified, use |
| 997 | // that triple. Otherwise, default to the host triple. |
Chris Lattner | 6590d21 | 2007-12-12 05:01:48 +0000 | [diff] [blame] | 998 | std::string Triple = TargetTriple; |
Daniel Dunbar | af07f93 | 2009-03-31 17:35:15 +0000 | [diff] [blame] | 999 | if (Triple.empty()) |
| 1000 | Triple = llvm::sys::getHostTriple(); |
Chris Lattner | 6a30c1f | 2008-09-30 01:13:12 +0000 | [diff] [blame] | 1001 | |
| 1002 | // If -mmacosx-version-min=10.3.9 is specified, change the triple from being |
| 1003 | // something like powerpc-apple-darwin9 to powerpc-apple-darwin7 |
Chris Lattner | ba0f25f | 2008-09-30 20:16:56 +0000 | [diff] [blame] | 1004 | if (!MacOSVersionMin.empty()) |
| 1005 | HandleMacOSVersionMin(Triple); |
Daniel Dunbar | 8d33cd7 | 2009-04-10 19:52:24 +0000 | [diff] [blame] | 1006 | else if (!IPhoneOSVersionMin.empty()) |
| 1007 | HandleIPhoneOSVersionMin(Triple);; |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 1008 | |
Chris Lattner | 6a30c1f | 2008-09-30 01:13:12 +0000 | [diff] [blame] | 1009 | return Triple; |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | //===----------------------------------------------------------------------===// |
Chris Lattner | e116ccf | 2009-04-21 05:40:52 +0000 | [diff] [blame] | 1013 | // SourceManager initialization. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1014 | //===----------------------------------------------------------------------===// |
| 1015 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1016 | static bool InitializeSourceManager(Preprocessor &PP, |
| 1017 | const std::string &InFile) { |
| 1018 | // Figure out where to get and map in the main file. |
| 1019 | SourceManager &SourceMgr = PP.getSourceManager(); |
| 1020 | FileManager &FileMgr = PP.getFileManager(); |
Daniel Dunbar | 57cbfc0 | 2009-04-27 21:19:07 +0000 | [diff] [blame] | 1021 | |
| 1022 | if (EmptyInputOnly) { |
| 1023 | const char *EmptyStr = ""; |
| 1024 | llvm::MemoryBuffer *SB = |
| 1025 | llvm::MemoryBuffer::getMemBuffer(EmptyStr, EmptyStr, "<empty input>"); |
| 1026 | SourceMgr.createMainFileIDForMemBuffer(SB); |
| 1027 | } else if (InFile != "-") { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1028 | const FileEntry *File = FileMgr.getFile(InFile); |
| 1029 | if (File) SourceMgr.createMainFileID(File, SourceLocation()); |
| 1030 | if (SourceMgr.getMainFileID().isInvalid()) { |
| 1031 | PP.getDiagnostics().Report(FullSourceLoc(), diag::err_fe_error_reading) |
| 1032 | << InFile.c_str(); |
| 1033 | return true; |
| 1034 | } |
| 1035 | } else { |
| 1036 | llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN(); |
| 1037 | |
| 1038 | // If stdin was empty, SB is null. Cons up an empty memory |
| 1039 | // buffer now. |
| 1040 | if (!SB) { |
| 1041 | const char *EmptyStr = ""; |
| 1042 | SB = llvm::MemoryBuffer::getMemBuffer(EmptyStr, EmptyStr, "<stdin>"); |
| 1043 | } |
| 1044 | |
| 1045 | SourceMgr.createMainFileIDForMemBuffer(SB); |
| 1046 | if (SourceMgr.getMainFileID().isInvalid()) { |
| 1047 | PP.getDiagnostics().Report(FullSourceLoc(), |
| 1048 | diag::err_fe_error_reading_stdin); |
| 1049 | return true; |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | return false; |
| 1054 | } |
| 1055 | |
Chris Lattner | aa39197 | 2008-04-19 23:09:31 +0000 | [diff] [blame] | 1056 | |
Chris Lattner | e116ccf | 2009-04-21 05:40:52 +0000 | [diff] [blame] | 1057 | //===----------------------------------------------------------------------===// |
| 1058 | // Preprocessor Initialization |
| 1059 | //===----------------------------------------------------------------------===// |
Sam Bishop | 1102d6b | 2008-04-14 14:41:57 +0000 | [diff] [blame] | 1060 | |
Chris Lattner | e116ccf | 2009-04-21 05:40:52 +0000 | [diff] [blame] | 1061 | // FIXME: Preprocessor builtins to support. |
| 1062 | // -A... - Play with #assertions |
| 1063 | // -undef - Undefine all predefined macros |
Chris Lattner | b31ac22 | 2009-04-08 20:15:42 +0000 | [diff] [blame] | 1064 | |
Chris Lattner | e116ccf | 2009-04-21 05:40:52 +0000 | [diff] [blame] | 1065 | static llvm::cl::list<std::string> |
| 1066 | D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix, |
| 1067 | llvm::cl::desc("Predefine the specified macro")); |
| 1068 | static llvm::cl::list<std::string> |
| 1069 | U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix, |
| 1070 | llvm::cl::desc("Undefine the specified macro")); |
Chris Lattner | b8e240e | 2009-04-08 18:24:34 +0000 | [diff] [blame] | 1071 | |
Chris Lattner | e116ccf | 2009-04-21 05:40:52 +0000 | [diff] [blame] | 1072 | static llvm::cl::list<std::string> |
| 1073 | ImplicitIncludes("include", llvm::cl::value_desc("file"), |
| 1074 | llvm::cl::desc("Include file before parsing")); |
| 1075 | static llvm::cl::list<std::string> |
| 1076 | ImplicitMacroIncludes("imacros", llvm::cl::value_desc("file"), |
| 1077 | llvm::cl::desc("Include macros from file before parsing")); |
Chris Lattner | b8e240e | 2009-04-08 18:24:34 +0000 | [diff] [blame] | 1078 | |
Chris Lattner | e116ccf | 2009-04-21 05:40:52 +0000 | [diff] [blame] | 1079 | static llvm::cl::opt<std::string> |
| 1080 | ImplicitIncludePCH("include-pch", llvm::cl::value_desc("file"), |
| 1081 | llvm::cl::desc("Include precompiled header file")); |
| 1082 | |
| 1083 | static llvm::cl::opt<std::string> |
| 1084 | ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"), |
| 1085 | llvm::cl::desc("Include file before parsing")); |
| 1086 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1087 | |
| 1088 | //===----------------------------------------------------------------------===// |
| 1089 | // Preprocessor include path information. |
| 1090 | //===----------------------------------------------------------------------===// |
| 1091 | |
| 1092 | // This tool exports a large number of command line options to control how the |
| 1093 | // preprocessor searches for header files. At root, however, the Preprocessor |
| 1094 | // object takes a very simple interface: a list of directories to search for |
| 1095 | // |
Daniel Dunbar | fb4ac7b | 2009-05-06 03:48:17 +0000 | [diff] [blame] | 1096 | // FIXME: -nostdinc++ |
Chris Lattner | 0c94641 | 2007-08-26 17:47:35 +0000 | [diff] [blame] | 1097 | // FIXME: -imultilib |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1098 | // |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1099 | |
| 1100 | static llvm::cl::opt<bool> |
| 1101 | nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories")); |
| 1102 | |
| 1103 | // Various command line options. These four add directories to each chain. |
| 1104 | static llvm::cl::list<std::string> |
| 1105 | F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 1106 | llvm::cl::desc("Add directory to framework include search path")); |
| 1107 | static llvm::cl::list<std::string> |
| 1108 | I_dirs("I", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 1109 | llvm::cl::desc("Add directory to include search path")); |
| 1110 | static llvm::cl::list<std::string> |
| 1111 | idirafter_dirs("idirafter", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 1112 | llvm::cl::desc("Add directory to AFTER include search path")); |
| 1113 | static llvm::cl::list<std::string> |
| 1114 | iquote_dirs("iquote", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 1115 | llvm::cl::desc("Add directory to QUOTE include search path")); |
| 1116 | static llvm::cl::list<std::string> |
| 1117 | isystem_dirs("isystem", llvm::cl::value_desc("directory"), llvm::cl::Prefix, |
| 1118 | llvm::cl::desc("Add directory to SYSTEM include search path")); |
| 1119 | |
| 1120 | // These handle -iprefix/-iwithprefix/-iwithprefixbefore. |
| 1121 | static llvm::cl::list<std::string> |
| 1122 | iprefix_vals("iprefix", llvm::cl::value_desc("prefix"), llvm::cl::Prefix, |
| 1123 | llvm::cl::desc("Set the -iwithprefix/-iwithprefixbefore prefix")); |
| 1124 | static llvm::cl::list<std::string> |
| 1125 | iwithprefix_vals("iwithprefix", llvm::cl::value_desc("dir"), llvm::cl::Prefix, |
| 1126 | llvm::cl::desc("Set directory to SYSTEM include search path with prefix")); |
| 1127 | static llvm::cl::list<std::string> |
| 1128 | iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"), |
| 1129 | llvm::cl::Prefix, |
| 1130 | llvm::cl::desc("Set directory to include search path with prefix")); |
| 1131 | |
Chris Lattner | 0c94641 | 2007-08-26 17:47:35 +0000 | [diff] [blame] | 1132 | static llvm::cl::opt<std::string> |
| 1133 | isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"), |
| 1134 | llvm::cl::desc("Set the system root directory (usually /)")); |
| 1135 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1136 | // Finally, implement the code that groks the options above. |
Chris Lattner | 5f9eae5 | 2008-03-01 08:07:28 +0000 | [diff] [blame] | 1137 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1138 | /// InitializeIncludePaths - Process the -I options and set them in the |
| 1139 | /// HeaderSearch object. |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1140 | void InitializeIncludePaths(const char *Argv0, HeaderSearch &Headers, |
| 1141 | FileManager &FM, const LangOptions &Lang) { |
| 1142 | InitHeaderSearch Init(Headers, Verbose, isysroot); |
| 1143 | |
Ted Kremenek | f372111 | 2008-05-31 00:27:00 +0000 | [diff] [blame] | 1144 | // Handle -I... and -F... options, walking the lists in parallel. |
| 1145 | unsigned Iidx = 0, Fidx = 0; |
| 1146 | while (Iidx < I_dirs.size() && Fidx < F_dirs.size()) { |
| 1147 | if (I_dirs.getPosition(Iidx) < F_dirs.getPosition(Fidx)) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1148 | Init.AddPath(I_dirs[Iidx], InitHeaderSearch::Angled, false, true, false); |
Ted Kremenek | f372111 | 2008-05-31 00:27:00 +0000 | [diff] [blame] | 1149 | ++Iidx; |
| 1150 | } else { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1151 | Init.AddPath(F_dirs[Fidx], InitHeaderSearch::Angled, false, true, true); |
Ted Kremenek | f372111 | 2008-05-31 00:27:00 +0000 | [diff] [blame] | 1152 | ++Fidx; |
| 1153 | } |
| 1154 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1155 | |
Ted Kremenek | f372111 | 2008-05-31 00:27:00 +0000 | [diff] [blame] | 1156 | // Consume what's left from whatever list was longer. |
| 1157 | for (; Iidx != I_dirs.size(); ++Iidx) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1158 | Init.AddPath(I_dirs[Iidx], InitHeaderSearch::Angled, false, true, false); |
Ted Kremenek | f372111 | 2008-05-31 00:27:00 +0000 | [diff] [blame] | 1159 | for (; Fidx != F_dirs.size(); ++Fidx) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1160 | Init.AddPath(F_dirs[Fidx], InitHeaderSearch::Angled, false, true, true); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1161 | |
| 1162 | // Handle -idirafter... options. |
| 1163 | for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1164 | Init.AddPath(idirafter_dirs[i], InitHeaderSearch::After, |
| 1165 | false, true, false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1166 | |
| 1167 | // Handle -iquote... options. |
| 1168 | for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1169 | Init.AddPath(iquote_dirs[i], InitHeaderSearch::Quoted, false, true, false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1170 | |
| 1171 | // Handle -isystem... options. |
| 1172 | for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1173 | Init.AddPath(isystem_dirs[i], InitHeaderSearch::System, false, true, false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1174 | |
| 1175 | // Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in |
| 1176 | // parallel, processing the values in order of occurance to get the right |
| 1177 | // prefixes. |
| 1178 | { |
| 1179 | std::string Prefix = ""; // FIXME: this isn't the correct default prefix. |
| 1180 | unsigned iprefix_idx = 0; |
| 1181 | unsigned iwithprefix_idx = 0; |
| 1182 | unsigned iwithprefixbefore_idx = 0; |
| 1183 | bool iprefix_done = iprefix_vals.empty(); |
| 1184 | bool iwithprefix_done = iwithprefix_vals.empty(); |
| 1185 | bool iwithprefixbefore_done = iwithprefixbefore_vals.empty(); |
| 1186 | while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) { |
| 1187 | if (!iprefix_done && |
| 1188 | (iwithprefix_done || |
| 1189 | iprefix_vals.getPosition(iprefix_idx) < |
| 1190 | iwithprefix_vals.getPosition(iwithprefix_idx)) && |
| 1191 | (iwithprefixbefore_done || |
| 1192 | iprefix_vals.getPosition(iprefix_idx) < |
| 1193 | iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) { |
| 1194 | Prefix = iprefix_vals[iprefix_idx]; |
| 1195 | ++iprefix_idx; |
| 1196 | iprefix_done = iprefix_idx == iprefix_vals.size(); |
| 1197 | } else if (!iwithprefix_done && |
| 1198 | (iwithprefixbefore_done || |
| 1199 | iwithprefix_vals.getPosition(iwithprefix_idx) < |
| 1200 | iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1201 | Init.AddPath(Prefix+iwithprefix_vals[iwithprefix_idx], |
| 1202 | InitHeaderSearch::System, false, false, false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1203 | ++iwithprefix_idx; |
| 1204 | iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size(); |
| 1205 | } else { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1206 | Init.AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx], |
| 1207 | InitHeaderSearch::Angled, false, false, false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1208 | ++iwithprefixbefore_idx; |
| 1209 | iwithprefixbefore_done = |
| 1210 | iwithprefixbefore_idx == iwithprefixbefore_vals.size(); |
| 1211 | } |
| 1212 | } |
| 1213 | } |
Chris Lattner | 5f9eae5 | 2008-03-01 08:07:28 +0000 | [diff] [blame] | 1214 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1215 | Init.AddDefaultEnvVarPaths(Lang); |
Chris Lattner | 5f9eae5 | 2008-03-01 08:07:28 +0000 | [diff] [blame] | 1216 | |
Daniel Dunbar | adcf5b3 | 2009-02-21 20:52:41 +0000 | [diff] [blame] | 1217 | // Add the clang headers, which are relative to the clang binary. |
Chris Lattner | dcaa096 | 2008-03-03 03:16:03 +0000 | [diff] [blame] | 1218 | llvm::sys::Path MainExecutablePath = |
Chris Lattner | 985e182 | 2008-03-03 05:57:43 +0000 | [diff] [blame] | 1219 | llvm::sys::Path::GetMainExecutable(Argv0, |
| 1220 | (void*)(intptr_t)InitializeIncludePaths); |
Chris Lattner | dcaa096 | 2008-03-03 03:16:03 +0000 | [diff] [blame] | 1221 | if (!MainExecutablePath.isEmpty()) { |
| 1222 | MainExecutablePath.eraseComponent(); // Remove /clang from foo/bin/clang |
| 1223 | MainExecutablePath.eraseComponent(); // Remove /bin from foo/bin |
Daniel Dunbar | adcf5b3 | 2009-02-21 20:52:41 +0000 | [diff] [blame] | 1224 | |
Daniel Dunbar | fb4ac7b | 2009-05-06 03:48:17 +0000 | [diff] [blame] | 1225 | // Get foo/lib/clang/<version>/include |
Daniel Dunbar | adcf5b3 | 2009-02-21 20:52:41 +0000 | [diff] [blame] | 1226 | MainExecutablePath.appendComponent("lib"); |
| 1227 | MainExecutablePath.appendComponent("clang"); |
Daniel Dunbar | fb4ac7b | 2009-05-06 03:48:17 +0000 | [diff] [blame] | 1228 | MainExecutablePath.appendComponent(CLANG_VERSION_STRING); |
Daniel Dunbar | adcf5b3 | 2009-02-21 20:52:41 +0000 | [diff] [blame] | 1229 | MainExecutablePath.appendComponent("include"); |
Chris Lattner | 6858dd3 | 2009-02-19 06:48:28 +0000 | [diff] [blame] | 1230 | |
| 1231 | // We pass true to ignore sysroot so that we *always* look for clang headers |
| 1232 | // relative to our executable, never relative to -isysroot. |
| 1233 | Init.AddPath(MainExecutablePath.c_str(), InitHeaderSearch::System, |
| 1234 | false, false, false, true /*ignore sysroot*/); |
Chris Lattner | dcaa096 | 2008-03-03 03:16:03 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1237 | if (!nostdinc) |
| 1238 | Init.AddDefaultSystemIncludePaths(Lang); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1239 | |
| 1240 | // Now that we have collected all of the include paths, merge them all |
| 1241 | // together and tell the preprocessor about them. |
| 1242 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1243 | Init.Realize(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
Chris Lattner | e116ccf | 2009-04-21 05:40:52 +0000 | [diff] [blame] | 1246 | void InitializePreprocessorInitOptions(PreprocessorInitOptions &InitOpts) |
| 1247 | { |
| 1248 | // Add macros from the command line. |
| 1249 | unsigned d = 0, D = D_macros.size(); |
| 1250 | unsigned u = 0, U = U_macros.size(); |
| 1251 | while (d < D || u < U) { |
| 1252 | if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u))) |
| 1253 | InitOpts.addMacroDef(D_macros[d++]); |
| 1254 | else |
| 1255 | InitOpts.addMacroUndef(U_macros[u++]); |
| 1256 | } |
| 1257 | |
| 1258 | // If -imacros are specified, include them now. These are processed before |
| 1259 | // any -include directives. |
| 1260 | for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i) |
| 1261 | InitOpts.addMacroInclude(ImplicitMacroIncludes[i]); |
| 1262 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1263 | if (!ImplicitIncludePTH.empty() || !ImplicitIncludes.empty() || |
| 1264 | (!ImplicitIncludePCH.empty() && ProgAction == PrintPreprocessedInput)) { |
Chris Lattner | e116ccf | 2009-04-21 05:40:52 +0000 | [diff] [blame] | 1265 | // We want to add these paths to the predefines buffer in order, make a |
| 1266 | // temporary vector to sort by their occurrence. |
| 1267 | llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths; |
| 1268 | |
| 1269 | if (!ImplicitIncludePTH.empty()) |
| 1270 | OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(), |
| 1271 | &ImplicitIncludePTH)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1272 | if (!ImplicitIncludePCH.empty() && ProgAction == PrintPreprocessedInput) |
| 1273 | OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(), |
| 1274 | &ImplicitIncludePCH)); |
Chris Lattner | e116ccf | 2009-04-21 05:40:52 +0000 | [diff] [blame] | 1275 | for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i) |
| 1276 | OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i), |
| 1277 | &ImplicitIncludes[i])); |
| 1278 | llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end()); |
| 1279 | |
| 1280 | |
| 1281 | // Now that they are ordered by position, add to the predefines buffer. |
| 1282 | for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i) { |
| 1283 | std::string *Ptr = OrderedPaths[i].second; |
| 1284 | if (!ImplicitIncludes.empty() && |
| 1285 | Ptr >= &ImplicitIncludes[0] && |
| 1286 | Ptr <= &ImplicitIncludes[ImplicitIncludes.size()-1]) { |
| 1287 | InitOpts.addInclude(*Ptr, false); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1288 | } else if (Ptr == &ImplicitIncludePTH) { |
Chris Lattner | e116ccf | 2009-04-21 05:40:52 +0000 | [diff] [blame] | 1289 | InitOpts.addInclude(*Ptr, true); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1290 | } else { |
| 1291 | // We end up here when we're producing preprocessed output and |
| 1292 | // we loaded a PCH file. In this case, just include the header |
| 1293 | // file that was used to build the precompiled header. |
| 1294 | assert(Ptr == &ImplicitIncludePCH); |
| 1295 | std::string OriginalFile = PCHReader::getOriginalSourceFile(*Ptr); |
| 1296 | if (!OriginalFile.empty()) { |
| 1297 | InitOpts.addInclude(OriginalFile, false); |
| 1298 | ImplicitIncludePCH.clear(); |
| 1299 | } |
Chris Lattner | e116ccf | 2009-04-21 05:40:52 +0000 | [diff] [blame] | 1300 | } |
| 1301 | } |
| 1302 | } |
| 1303 | } |
| 1304 | |
Ted Kremenek | a42cf2e | 2008-04-17 21:38:34 +0000 | [diff] [blame] | 1305 | //===----------------------------------------------------------------------===// |
| 1306 | // Driver PreprocessorFactory - For lazily generating preprocessors ... |
| 1307 | //===----------------------------------------------------------------------===// |
| 1308 | |
| 1309 | namespace { |
| 1310 | class VISIBILITY_HIDDEN DriverPreprocessorFactory : public PreprocessorFactory { |
| 1311 | Diagnostic &Diags; |
| 1312 | const LangOptions &LangInfo; |
| 1313 | TargetInfo &Target; |
| 1314 | SourceManager &SourceMgr; |
| 1315 | HeaderSearch &HeaderInfo; |
Ted Kremenek | 339b9c2 | 2008-04-17 22:31:54 +0000 | [diff] [blame] | 1316 | |
Ted Kremenek | a42cf2e | 2008-04-17 21:38:34 +0000 | [diff] [blame] | 1317 | public: |
Eli Friedman | f086e3b | 2009-05-18 07:39:39 +0000 | [diff] [blame] | 1318 | DriverPreprocessorFactory(Diagnostic &diags, const LangOptions &opts, |
Ted Kremenek | a42cf2e | 2008-04-17 21:38:34 +0000 | [diff] [blame] | 1319 | TargetInfo &target, SourceManager &SM, |
| 1320 | HeaderSearch &Headers) |
Eli Friedman | f086e3b | 2009-05-18 07:39:39 +0000 | [diff] [blame] | 1321 | : Diags(diags), LangInfo(opts), Target(target), |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1322 | SourceMgr(SM), HeaderInfo(Headers) {} |
Ted Kremenek | 339b9c2 | 2008-04-17 22:31:54 +0000 | [diff] [blame] | 1323 | |
Ted Kremenek | a42cf2e | 2008-04-17 21:38:34 +0000 | [diff] [blame] | 1324 | |
| 1325 | virtual ~DriverPreprocessorFactory() {} |
| 1326 | |
| 1327 | virtual Preprocessor* CreatePreprocessor() { |
Ted Kremenek | 72b1b15 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 1328 | llvm::OwningPtr<PTHManager> PTHMgr; |
| 1329 | |
Ted Kremenek | 748d5d6 | 2009-03-20 00:26:38 +0000 | [diff] [blame] | 1330 | if (!TokenCache.empty() && !ImplicitIncludePTH.empty()) { |
| 1331 | fprintf(stderr, "error: cannot use both -token-cache and -include-pth " |
| 1332 | "options\n"); |
Ted Kremenek | 22f0d09 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 1333 | exit(1); |
Ted Kremenek | 748d5d6 | 2009-03-20 00:26:38 +0000 | [diff] [blame] | 1334 | } |
| 1335 | |
Ted Kremenek | 72b1b15 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 1336 | // Use PTH? |
Ted Kremenek | 748d5d6 | 2009-03-20 00:26:38 +0000 | [diff] [blame] | 1337 | if (!TokenCache.empty() || !ImplicitIncludePTH.empty()) { |
| 1338 | const std::string& x = TokenCache.empty() ? ImplicitIncludePTH:TokenCache; |
Ted Kremenek | 22f0d09 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 1339 | PTHMgr.reset(PTHManager::Create(x, &Diags, |
| 1340 | TokenCache.empty() ? Diagnostic::Error |
| 1341 | : Diagnostic::Warning)); |
Ted Kremenek | 748d5d6 | 2009-03-20 00:26:38 +0000 | [diff] [blame] | 1342 | } |
Ted Kremenek | 72b1b15 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 1343 | |
Ted Kremenek | 22f0d09 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 1344 | if (Diags.hasErrorOccurred()) |
| 1345 | exit(1); |
| 1346 | |
Ted Kremenek | 72b1b15 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 1347 | // Create the Preprocessor. |
| 1348 | llvm::OwningPtr<Preprocessor> PP(new Preprocessor(Diags, LangInfo, Target, |
| 1349 | SourceMgr, HeaderInfo, |
| 1350 | PTHMgr.get())); |
| 1351 | |
| 1352 | // Note that this is different then passing PTHMgr to Preprocessor's ctor. |
| 1353 | // That argument is used as the IdentifierInfoLookup argument to |
| 1354 | // IdentifierTable's ctor. |
| 1355 | if (PTHMgr) { |
| 1356 | PTHMgr->setPreprocessor(PP.get()); |
| 1357 | PP->setPTHManager(PTHMgr.take()); |
| 1358 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1359 | |
Chris Lattner | e116ccf | 2009-04-21 05:40:52 +0000 | [diff] [blame] | 1360 | PreprocessorInitOptions InitOpts; |
| 1361 | InitializePreprocessorInitOptions(InitOpts); |
Eli Friedman | f086e3b | 2009-05-18 07:39:39 +0000 | [diff] [blame] | 1362 | if (InitializePreprocessor(*PP, InitOpts)) |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1363 | return 0; |
Chris Lattner | e116ccf | 2009-04-21 05:40:52 +0000 | [diff] [blame] | 1364 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1365 | return PP.take(); |
Ted Kremenek | a42cf2e | 2008-04-17 21:38:34 +0000 | [diff] [blame] | 1366 | } |
| 1367 | }; |
| 1368 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1369 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1370 | //===----------------------------------------------------------------------===// |
| 1371 | // Basic Parser driver |
| 1372 | //===----------------------------------------------------------------------===// |
| 1373 | |
Chris Lattner | 51574ea | 2008-04-19 23:25:44 +0000 | [diff] [blame] | 1374 | static void ParseFile(Preprocessor &PP, MinimalAction *PA) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1375 | Parser P(PP, *PA); |
Ted Kremenek | 95041a2 | 2007-12-19 22:51:13 +0000 | [diff] [blame] | 1376 | PP.EnterMainSourceFile(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1377 | |
| 1378 | // Parsing the specified input file. |
| 1379 | P.ParseTranslationUnit(); |
| 1380 | delete PA; |
| 1381 | } |
| 1382 | |
| 1383 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | 70f9243 | 2008-10-23 05:50:47 +0000 | [diff] [blame] | 1384 | // Code generation options |
| 1385 | //===----------------------------------------------------------------------===// |
| 1386 | |
| 1387 | static llvm::cl::opt<bool> |
Chris Lattner | 1510488 | 2009-03-09 22:05:03 +0000 | [diff] [blame] | 1388 | GenerateDebugInfo("g", |
| 1389 | llvm::cl::desc("Generate source level debug information")); |
| 1390 | |
Daniel Dunbar | a034ba8 | 2009-02-17 19:47:34 +0000 | [diff] [blame] | 1391 | static llvm::cl::opt<std::string> |
| 1392 | TargetCPU("mcpu", |
| 1393 | llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)")); |
| 1394 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1395 | static llvm::cl::list<std::string> |
| 1396 | TargetFeatures("target-feature", llvm::cl::desc("Target specific attributes")); |
| 1397 | |
Devang Patel | 24095da | 2009-06-04 23:32:02 +0000 | [diff] [blame^] | 1398 | |
| 1399 | static llvm::cl::opt<bool> |
| 1400 | DisableRedZone("disable-red-zone", |
| 1401 | llvm::cl::desc("Do not emit code that uses the red zone."), |
| 1402 | llvm::cl::init(false)); |
| 1403 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1404 | /// ComputeTargetFeatures - Recompute the target feature list to only |
| 1405 | /// be the list of things that are enabled, based on the target cpu |
| 1406 | /// and feature list. |
| 1407 | static void ComputeFeatureMap(TargetInfo *Target, |
| 1408 | llvm::StringMap<bool> &Features) { |
| 1409 | assert(Features.empty() && "invalid map"); |
| 1410 | |
| 1411 | // Initialize the feature map based on the target. |
| 1412 | Target->getDefaultFeatures(TargetCPU, Features); |
| 1413 | |
| 1414 | // Apply the user specified deltas. |
| 1415 | for (llvm::cl::list<std::string>::iterator it = TargetFeatures.begin(), |
| 1416 | ie = TargetFeatures.end(); it != ie; ++it) { |
| 1417 | const char *Name = it->c_str(); |
| 1418 | |
| 1419 | // FIXME: Don't handle errors like this. |
| 1420 | if (Name[0] != '-' && Name[0] != '+') { |
| 1421 | fprintf(stderr, "error: clang-cc: invalid target feature string: %s\n", |
| 1422 | Name); |
| 1423 | exit(1); |
| 1424 | } |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1425 | if (!Target->setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) { |
| 1426 | fprintf(stderr, "error: clang-cc: invalid target feature name: %s\n", |
| 1427 | Name + 1); |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1428 | exit(1); |
| 1429 | } |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1430 | } |
| 1431 | } |
| 1432 | |
Chris Lattner | 7afae71 | 2009-03-16 18:41:18 +0000 | [diff] [blame] | 1433 | static void InitializeCompileOptions(CompileOptions &Opts, |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1434 | const LangOptions &LangOpts, |
| 1435 | const llvm::StringMap<bool> &Features) { |
Daniel Dunbar | 70f9243 | 2008-10-23 05:50:47 +0000 | [diff] [blame] | 1436 | Opts.OptimizeSize = OptSize; |
Chris Lattner | 2012604 | 2009-03-09 22:00:34 +0000 | [diff] [blame] | 1437 | Opts.DebugInfo = GenerateDebugInfo; |
Daniel Dunbar | 877db38 | 2009-06-02 22:07:45 +0000 | [diff] [blame] | 1438 | |
| 1439 | if (DisableLLVMOptimizations) { |
| 1440 | Opts.OptimizationLevel = 0; |
| 1441 | Opts.Inlining = CompileOptions::NoInlining; |
Daniel Dunbar | ac7ffe0 | 2008-10-29 07:56:11 +0000 | [diff] [blame] | 1442 | } else { |
Daniel Dunbar | 877db38 | 2009-06-02 22:07:45 +0000 | [diff] [blame] | 1443 | if (OptSize) { |
| 1444 | // -Os implies -O2 |
| 1445 | Opts.OptimizationLevel = 2; |
| 1446 | } else { |
| 1447 | Opts.OptimizationLevel = OptLevel; |
| 1448 | } |
| 1449 | |
| 1450 | // We must always run at least the always inlining pass. |
| 1451 | if (Opts.OptimizationLevel > 1) |
| 1452 | Opts.Inlining = CompileOptions::NormalInlining; |
| 1453 | else |
| 1454 | Opts.Inlining = CompileOptions::OnlyAlwaysInlining; |
Daniel Dunbar | ac7ffe0 | 2008-10-29 07:56:11 +0000 | [diff] [blame] | 1455 | } |
Daniel Dunbar | 8e8f3b7 | 2008-10-29 03:42:18 +0000 | [diff] [blame] | 1456 | |
| 1457 | // FIXME: There are llvm-gcc options to control these selectively. |
Daniel Dunbar | 8e8f3b7 | 2008-10-29 03:42:18 +0000 | [diff] [blame] | 1458 | Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize); |
Chris Lattner | 7afae71 | 2009-03-16 18:41:18 +0000 | [diff] [blame] | 1459 | Opts.SimplifyLibCalls = !LangOpts.NoBuiltin; |
Daniel Dunbar | dd913e5 | 2008-10-31 09:34:21 +0000 | [diff] [blame] | 1460 | |
| 1461 | #ifdef NDEBUG |
| 1462 | Opts.VerifyModule = 0; |
| 1463 | #endif |
Daniel Dunbar | a034ba8 | 2009-02-17 19:47:34 +0000 | [diff] [blame] | 1464 | |
| 1465 | Opts.CPU = TargetCPU; |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1466 | Opts.Features.clear(); |
| 1467 | for (llvm::StringMap<bool>::const_iterator it = Features.begin(), |
| 1468 | ie = Features.end(); it != ie; ++it) { |
| 1469 | // FIXME: If we are completely confident that we have the right |
| 1470 | // set, we only need to pass the minuses. |
| 1471 | std::string Name(it->second ? "+" : "-"); |
| 1472 | Name += it->first(); |
| 1473 | Opts.Features.push_back(Name); |
| 1474 | } |
Chris Lattner | 4450266 | 2009-02-18 01:23:44 +0000 | [diff] [blame] | 1475 | |
Chris Lattner | bd36064 | 2009-03-26 05:00:52 +0000 | [diff] [blame] | 1476 | Opts.NoCommon = NoCommon | LangOpts.CPlusPlus; |
| 1477 | |
Chris Lattner | 4450266 | 2009-02-18 01:23:44 +0000 | [diff] [blame] | 1478 | // Handle -ftime-report. |
| 1479 | Opts.TimePasses = TimeReport; |
Devang Patel | 24095da | 2009-06-04 23:32:02 +0000 | [diff] [blame^] | 1480 | |
| 1481 | Opts.DisableRedZone = DisableRedZone; |
Daniel Dunbar | 70f9243 | 2008-10-23 05:50:47 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 26df2f0 | 2009-04-02 19:05:20 +0000 | [diff] [blame] | 1485 | // Fix-It Options |
| 1486 | //===----------------------------------------------------------------------===// |
| 1487 | static llvm::cl::list<ParsedSourceLocation> |
| 1488 | FixItAtLocations("fixit-at", llvm::cl::value_desc("source-location"), |
| 1489 | llvm::cl::desc("Perform Fix-It modifications at the given source location")); |
| 1490 | |
| 1491 | //===----------------------------------------------------------------------===// |
Eli Friedman | c6d656e | 2009-05-18 22:39:16 +0000 | [diff] [blame] | 1492 | // ObjC Rewriter Options |
| 1493 | //===----------------------------------------------------------------------===// |
| 1494 | static llvm::cl::opt<bool> |
| 1495 | SilenceRewriteMacroWarning("Wno-rewrite-macros", llvm::cl::init(false), |
| 1496 | llvm::cl::desc("Silence ObjC rewriting warnings")); |
| 1497 | |
| 1498 | //===----------------------------------------------------------------------===// |
Eli Friedman | 0eeb86e | 2009-05-19 01:17:04 +0000 | [diff] [blame] | 1499 | // Warning Options |
| 1500 | //===----------------------------------------------------------------------===// |
| 1501 | |
| 1502 | // This gets all -W options, including -Werror, -W[no-]system-headers, etc. The |
| 1503 | // driver has stripped off -Wa,foo etc. The driver has also translated -W to |
| 1504 | // -Wextra, so we don't need to worry about it. |
| 1505 | static llvm::cl::list<std::string> |
| 1506 | OptWarnings("W", llvm::cl::Prefix, llvm::cl::ValueOptional); |
| 1507 | |
| 1508 | static llvm::cl::opt<bool> OptPedantic("pedantic"); |
| 1509 | static llvm::cl::opt<bool> OptPedanticErrors("pedantic-errors"); |
| 1510 | static llvm::cl::opt<bool> OptNoWarnings("w"); |
| 1511 | |
| 1512 | //===----------------------------------------------------------------------===// |
Eli Friedman | 12d3b1d | 2009-05-19 03:06:47 +0000 | [diff] [blame] | 1513 | // Preprocessing (-E mode) Options |
| 1514 | //===----------------------------------------------------------------------===// |
| 1515 | static llvm::cl::opt<bool> |
| 1516 | DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode")); |
| 1517 | static llvm::cl::opt<bool> |
| 1518 | EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode")); |
| 1519 | static llvm::cl::opt<bool> |
| 1520 | EnableMacroCommentOutput("CC", |
| 1521 | llvm::cl::desc("Enable comment output in -E mode, " |
| 1522 | "even from macro expansions")); |
| 1523 | static llvm::cl::opt<bool> |
| 1524 | DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of" |
| 1525 | " normal output")); |
| 1526 | static llvm::cl::opt<bool> |
| 1527 | DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in " |
| 1528 | "addition to normal output")); |
Eli Friedman | b5c8f8b | 2009-05-19 03:35:57 +0000 | [diff] [blame] | 1529 | |
| 1530 | //===----------------------------------------------------------------------===// |
| 1531 | // Dependency file options |
| 1532 | //===----------------------------------------------------------------------===// |
| 1533 | static llvm::cl::opt<std::string> |
| 1534 | DependencyFile("dependency-file", |
| 1535 | llvm::cl::desc("Filename (or -) to write dependency output to")); |
| 1536 | |
| 1537 | static llvm::cl::opt<bool> |
| 1538 | DependenciesIncludeSystemHeaders("sys-header-deps", |
| 1539 | llvm::cl::desc("Include system headers in dependency output")); |
| 1540 | |
| 1541 | static llvm::cl::list<std::string> |
| 1542 | DependencyTargets("MT", |
| 1543 | llvm::cl::desc("Specify target for dependency")); |
| 1544 | |
| 1545 | // FIXME: Implement feature |
| 1546 | static llvm::cl::opt<bool> |
| 1547 | PhonyDependencyTarget("MP", |
| 1548 | llvm::cl::desc("Create phony target for each dependency " |
| 1549 | "(other than main file)")); |
| 1550 | |
Eli Friedman | 12d3b1d | 2009-05-19 03:06:47 +0000 | [diff] [blame] | 1551 | //===----------------------------------------------------------------------===// |
Eli Friedman | e71b85f | 2009-05-19 10:18:02 +0000 | [diff] [blame] | 1552 | // Analysis options |
| 1553 | //===----------------------------------------------------------------------===// |
| 1554 | |
| 1555 | static llvm::cl::list<Analyses> |
| 1556 | AnalysisList(llvm::cl::desc("Source Code Analysis - Checks and Analyses"), |
| 1557 | llvm::cl::values( |
| 1558 | #define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE)\ |
| 1559 | clEnumValN(NAME, CMDFLAG, DESC), |
Eli Friedman | 0ec78fa | 2009-05-19 21:10:40 +0000 | [diff] [blame] | 1560 | #include "clang/Frontend/Analyses.def" |
Eli Friedman | e71b85f | 2009-05-19 10:18:02 +0000 | [diff] [blame] | 1561 | clEnumValEnd)); |
| 1562 | |
| 1563 | static llvm::cl::opt<AnalysisStores> |
| 1564 | AnalysisStoreOpt("analyzer-store", |
| 1565 | llvm::cl::desc("Source Code Analysis - Abstract Memory Store Models"), |
| 1566 | llvm::cl::init(BasicStoreModel), |
| 1567 | llvm::cl::values( |
| 1568 | #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN)\ |
| 1569 | clEnumValN(NAME##Model, CMDFLAG, DESC), |
Eli Friedman | 0ec78fa | 2009-05-19 21:10:40 +0000 | [diff] [blame] | 1570 | #include "clang/Frontend/Analyses.def" |
Eli Friedman | e71b85f | 2009-05-19 10:18:02 +0000 | [diff] [blame] | 1571 | clEnumValEnd)); |
| 1572 | |
| 1573 | static llvm::cl::opt<AnalysisConstraints> |
| 1574 | AnalysisConstraintsOpt("analyzer-constraints", |
| 1575 | llvm::cl::desc("Source Code Analysis - Symbolic Constraint Engines"), |
| 1576 | llvm::cl::init(RangeConstraintsModel), |
| 1577 | llvm::cl::values( |
| 1578 | #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN)\ |
| 1579 | clEnumValN(NAME##Model, CMDFLAG, DESC), |
Eli Friedman | 0ec78fa | 2009-05-19 21:10:40 +0000 | [diff] [blame] | 1580 | #include "clang/Frontend/Analyses.def" |
Eli Friedman | e71b85f | 2009-05-19 10:18:02 +0000 | [diff] [blame] | 1581 | clEnumValEnd)); |
| 1582 | |
| 1583 | static llvm::cl::opt<AnalysisDiagClients> |
| 1584 | AnalysisDiagOpt("analyzer-output", |
| 1585 | llvm::cl::desc("Source Code Analysis - Output Options"), |
| 1586 | llvm::cl::init(PD_HTML), |
| 1587 | llvm::cl::values( |
| 1588 | #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREATE)\ |
| 1589 | clEnumValN(PD_##NAME, CMDFLAG, DESC), |
Eli Friedman | 0ec78fa | 2009-05-19 21:10:40 +0000 | [diff] [blame] | 1590 | #include "clang/Frontend/Analyses.def" |
Eli Friedman | e71b85f | 2009-05-19 10:18:02 +0000 | [diff] [blame] | 1591 | clEnumValEnd)); |
| 1592 | |
| 1593 | static llvm::cl::opt<bool> |
| 1594 | VisualizeEGDot("analyzer-viz-egraph-graphviz", |
| 1595 | llvm::cl::desc("Display exploded graph using GraphViz")); |
| 1596 | |
| 1597 | static llvm::cl::opt<bool> |
| 1598 | VisualizeEGUbi("analyzer-viz-egraph-ubigraph", |
| 1599 | llvm::cl::desc("Display exploded graph using Ubigraph")); |
| 1600 | |
| 1601 | static llvm::cl::opt<bool> |
| 1602 | AnalyzeAll("analyzer-opt-analyze-headers", |
| 1603 | llvm::cl::desc("Force the static analyzer to analyze " |
| 1604 | "functions defined in header files")); |
| 1605 | |
| 1606 | static llvm::cl::opt<bool> |
| 1607 | AnalyzerDisplayProgress("analyzer-display-progress", |
| 1608 | llvm::cl::desc("Emit verbose output about the analyzer's progress.")); |
| 1609 | |
| 1610 | static llvm::cl::opt<bool> |
| 1611 | PurgeDead("analyzer-purge-dead", |
| 1612 | llvm::cl::init(true), |
| 1613 | llvm::cl::desc("Remove dead symbols, bindings, and constraints before" |
| 1614 | " processing a statement.")); |
| 1615 | |
| 1616 | static llvm::cl::opt<bool> |
| 1617 | EagerlyAssume("analyzer-eagerly-assume", |
| 1618 | llvm::cl::init(false), |
| 1619 | llvm::cl::desc("Eagerly assume the truth/falseness of some " |
| 1620 | "symbolic constraints.")); |
| 1621 | |
| 1622 | static llvm::cl::opt<std::string> |
| 1623 | AnalyzeSpecificFunction("analyze-function", |
| 1624 | llvm::cl::desc("Run analysis on specific function")); |
| 1625 | |
| 1626 | static llvm::cl::opt<bool> |
| 1627 | TrimGraph("trim-egraph", |
| 1628 | llvm::cl::desc("Only show error-related paths in the analysis graph")); |
| 1629 | |
| 1630 | static AnalyzerOptions ReadAnalyzerOptions() { |
| 1631 | AnalyzerOptions Opts; |
| 1632 | Opts.AnalysisList = AnalysisList; |
| 1633 | Opts.AnalysisStoreOpt = AnalysisStoreOpt; |
| 1634 | Opts.AnalysisConstraintsOpt = AnalysisConstraintsOpt; |
| 1635 | Opts.AnalysisDiagOpt = AnalysisDiagOpt; |
| 1636 | Opts.VisualizeEGDot = VisualizeEGDot; |
| 1637 | Opts.VisualizeEGUbi = VisualizeEGUbi; |
| 1638 | Opts.AnalyzeAll = AnalyzeAll; |
| 1639 | Opts.AnalyzerDisplayProgress = AnalyzerDisplayProgress; |
| 1640 | Opts.PurgeDead = PurgeDead; |
| 1641 | Opts.EagerlyAssume = EagerlyAssume; |
| 1642 | Opts.AnalyzeSpecificFunction = AnalyzeSpecificFunction; |
| 1643 | Opts.TrimGraph = TrimGraph; |
| 1644 | return Opts; |
| 1645 | } |
| 1646 | |
| 1647 | //===----------------------------------------------------------------------===// |
Chris Lattner | 75a97cb | 2009-04-17 21:05:01 +0000 | [diff] [blame] | 1648 | // -dump-build-information Stuff |
| 1649 | //===----------------------------------------------------------------------===// |
| 1650 | |
| 1651 | static llvm::cl::opt<std::string> |
| 1652 | DumpBuildInformation("dump-build-information", |
| 1653 | llvm::cl::value_desc("filename"), |
| 1654 | llvm::cl::desc("output a dump of some build information to a file")); |
| 1655 | |
| 1656 | static llvm::raw_ostream *BuildLogFile = 0; |
| 1657 | |
| 1658 | /// LoggingDiagnosticClient - This is a simple diagnostic client that forwards |
| 1659 | /// all diagnostics to both BuildLogFile and a chained DiagnosticClient. |
| 1660 | namespace { |
| 1661 | class LoggingDiagnosticClient : public DiagnosticClient { |
| 1662 | llvm::OwningPtr<DiagnosticClient> Chain1; |
| 1663 | llvm::OwningPtr<DiagnosticClient> Chain2; |
| 1664 | public: |
| 1665 | |
| 1666 | LoggingDiagnosticClient(DiagnosticClient *Normal) { |
| 1667 | // Output diags both where requested... |
| 1668 | Chain1.reset(Normal); |
| 1669 | // .. and to our log file. |
| 1670 | Chain2.reset(new TextDiagnosticPrinter(*BuildLogFile, |
| 1671 | !NoShowColumn, |
| 1672 | !NoCaretDiagnostics, |
| 1673 | !NoShowLocation, |
| 1674 | PrintSourceRangeInfo, |
Chris Lattner | aa5bf2e | 2009-04-19 07:44:08 +0000 | [diff] [blame] | 1675 | PrintDiagnosticOption, |
Douglas Gregor | fffd93f | 2009-05-01 21:53:04 +0000 | [diff] [blame] | 1676 | !NoDiagnosticsFixIt, |
| 1677 | MessageLength)); |
Chris Lattner | 75a97cb | 2009-04-17 21:05:01 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | virtual void setLangOptions(const LangOptions *LO) { |
| 1681 | Chain1->setLangOptions(LO); |
| 1682 | Chain2->setLangOptions(LO); |
| 1683 | } |
| 1684 | |
| 1685 | virtual bool IncludeInDiagnosticCounts() const { |
| 1686 | return Chain1->IncludeInDiagnosticCounts(); |
| 1687 | } |
| 1688 | |
| 1689 | virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, |
| 1690 | const DiagnosticInfo &Info) { |
| 1691 | Chain1->HandleDiagnostic(DiagLevel, Info); |
| 1692 | Chain2->HandleDiagnostic(DiagLevel, Info); |
| 1693 | } |
| 1694 | }; |
| 1695 | } // end anonymous namespace. |
| 1696 | |
| 1697 | static void SetUpBuildDumpLog(unsigned argc, char **argv, |
| 1698 | llvm::OwningPtr<DiagnosticClient> &DiagClient) { |
| 1699 | |
| 1700 | std::string ErrorInfo; |
| 1701 | BuildLogFile = new llvm::raw_fd_ostream(DumpBuildInformation.c_str(), false, |
| 1702 | ErrorInfo); |
| 1703 | |
| 1704 | if (!ErrorInfo.empty()) { |
| 1705 | llvm::errs() << "error opening -dump-build-information file '" |
| 1706 | << DumpBuildInformation << "', option ignored!\n"; |
| 1707 | delete BuildLogFile; |
| 1708 | BuildLogFile = 0; |
| 1709 | DumpBuildInformation = ""; |
| 1710 | return; |
| 1711 | } |
| 1712 | |
| 1713 | (*BuildLogFile) << "clang-cc command line arguments: "; |
| 1714 | for (unsigned i = 0; i != argc; ++i) |
| 1715 | (*BuildLogFile) << argv[i] << ' '; |
| 1716 | (*BuildLogFile) << '\n'; |
| 1717 | |
| 1718 | // LoggingDiagnosticClient - Insert a new logging diagnostic client in between |
| 1719 | // the diagnostic producers and the normal receiver. |
| 1720 | DiagClient.reset(new LoggingDiagnosticClient(DiagClient.take())); |
| 1721 | } |
| 1722 | |
| 1723 | |
| 1724 | |
| 1725 | //===----------------------------------------------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1726 | // Main driver |
| 1727 | //===----------------------------------------------------------------------===// |
| 1728 | |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1729 | static llvm::raw_ostream* ComputeOutFile(const std::string& InFile, |
| 1730 | const char* Extension, |
| 1731 | bool Binary, |
| 1732 | llvm::sys::Path& OutPath) { |
| 1733 | llvm::raw_ostream* Ret; |
| 1734 | bool UseStdout = false; |
| 1735 | std::string OutFile; |
| 1736 | if (OutputFile == "-" || (OutputFile.empty() && InFile == "-")) { |
| 1737 | UseStdout = true; |
| 1738 | } else if (!OutputFile.empty()) { |
| 1739 | OutFile = OutputFile; |
| 1740 | } else if (Extension) { |
| 1741 | llvm::sys::Path Path(InFile); |
| 1742 | Path.eraseSuffix(); |
| 1743 | Path.appendSuffix(Extension); |
| 1744 | OutFile = Path.toString(); |
| 1745 | } else { |
| 1746 | UseStdout = true; |
Chris Lattner | 8a5c809 | 2009-02-18 01:20:05 +0000 | [diff] [blame] | 1747 | } |
Seo Sanghyeon | fe947ad | 2007-12-24 01:52:34 +0000 | [diff] [blame] | 1748 | |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1749 | if (UseStdout) { |
| 1750 | Ret = new llvm::raw_stdout_ostream(); |
| 1751 | if (Binary) |
| 1752 | llvm::sys::Program::ChangeStdoutToBinary(); |
| 1753 | } else { |
| 1754 | std::string Error; |
| 1755 | Ret = new llvm::raw_fd_ostream(OutFile.c_str(), Binary, Error); |
| 1756 | if (!Error.empty()) { |
| 1757 | // FIXME: Don't fail this way. |
| 1758 | llvm::cerr << "ERROR: " << Error << "\n"; |
| 1759 | ::exit(1); |
| 1760 | } |
| 1761 | OutPath = OutFile; |
Ted Kremenek | db094a2 | 2007-12-05 18:27:04 +0000 | [diff] [blame] | 1762 | } |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1763 | |
| 1764 | return Ret; |
Ted Kremenek | db094a2 | 2007-12-05 18:27:04 +0000 | [diff] [blame] | 1765 | } |
| 1766 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1767 | /// ProcessInputFile - Process a single input file with the specified state. |
| 1768 | /// |
Ted Kremenek | 339b9c2 | 2008-04-17 22:31:54 +0000 | [diff] [blame] | 1769 | static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF, |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1770 | const std::string &InFile, ProgActions PA, |
| 1771 | const llvm::StringMap<bool> &Features) { |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1772 | llvm::OwningPtr<llvm::raw_ostream> OS; |
Ted Kremenek | 7e7e625 | 2008-08-08 02:46:37 +0000 | [diff] [blame] | 1773 | llvm::OwningPtr<ASTConsumer> Consumer; |
Chris Lattner | bd24776 | 2007-07-22 06:05:44 +0000 | [diff] [blame] | 1774 | bool ClearSourceMgr = false; |
Douglas Gregor | 558cb56 | 2009-04-02 01:08:08 +0000 | [diff] [blame] | 1775 | FixItRewriter *FixItRewrite = 0; |
Douglas Gregor | f807fe0 | 2009-04-14 16:27:31 +0000 | [diff] [blame] | 1776 | bool CompleteTranslationUnit = true; |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1777 | llvm::sys::Path OutPath; |
Douglas Gregor | 558cb56 | 2009-04-02 01:08:08 +0000 | [diff] [blame] | 1778 | |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 1779 | switch (PA) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1780 | default: |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1781 | fprintf(stderr, "Unexpected program action!\n"); |
| 1782 | HadErrors = true; |
| 1783 | return; |
| 1784 | |
| 1785 | case ASTPrint: |
| 1786 | OS.reset(ComputeOutFile(InFile, 0, false, OutPath)); |
| 1787 | Consumer.reset(CreateASTPrinter(OS.get())); |
| 1788 | break; |
Ted Kremenek | db094a2 | 2007-12-05 18:27:04 +0000 | [diff] [blame] | 1789 | |
Douglas Gregor | ee75c05 | 2009-05-21 20:55:50 +0000 | [diff] [blame] | 1790 | case ASTPrintXML: |
| 1791 | OS.reset(ComputeOutFile(InFile, "xml", false, OutPath)); |
| 1792 | Consumer.reset(CreateASTPrinterXML(OS.get())); |
| 1793 | break; |
| 1794 | |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1795 | case ASTDump: |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1796 | Consumer.reset(CreateASTDumper()); |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1797 | break; |
| 1798 | |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1799 | case ASTView: |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1800 | Consumer.reset(CreateASTViewer()); |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1801 | break; |
| 1802 | |
| 1803 | case PrintDeclContext: |
| 1804 | Consumer.reset(CreateDeclContextPrinter()); |
| 1805 | break; |
| 1806 | |
| 1807 | case EmitHTML: |
| 1808 | OS.reset(ComputeOutFile(InFile, 0, true, OutPath)); |
| 1809 | Consumer.reset(CreateHTMLPrinter(OS.get(), PP.getDiagnostics(), &PP, &PPF)); |
| 1810 | break; |
| 1811 | |
| 1812 | case InheritanceView: |
| 1813 | Consumer.reset(CreateInheritanceViewer(InheritanceViewCls)); |
| 1814 | break; |
| 1815 | |
| 1816 | case EmitAssembly: |
| 1817 | case EmitLLVM: |
| 1818 | case EmitBC: |
| 1819 | case EmitLLVMOnly: { |
| 1820 | BackendAction Act; |
| 1821 | if (ProgAction == EmitAssembly) { |
| 1822 | Act = Backend_EmitAssembly; |
| 1823 | OS.reset(ComputeOutFile(InFile, "s", true, OutPath)); |
| 1824 | } else if (ProgAction == EmitLLVM) { |
| 1825 | Act = Backend_EmitLL; |
| 1826 | OS.reset(ComputeOutFile(InFile, "ll", true, OutPath)); |
| 1827 | } else if (ProgAction == EmitLLVMOnly) { |
| 1828 | Act = Backend_EmitNothing; |
| 1829 | } else { |
| 1830 | Act = Backend_EmitBC; |
| 1831 | OS.reset(ComputeOutFile(InFile, "bc", true, OutPath)); |
Ted Kremenek | db094a2 | 2007-12-05 18:27:04 +0000 | [diff] [blame] | 1832 | } |
Ted Kremenek | fdfc198 | 2007-12-19 22:24:34 +0000 | [diff] [blame] | 1833 | |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1834 | CompileOptions Opts; |
| 1835 | InitializeCompileOptions(Opts, PP.getLangOptions(), Features); |
| 1836 | Consumer.reset(CreateBackendConsumer(Act, PP.getDiagnostics(), |
| 1837 | PP.getLangOptions(), Opts, InFile, |
| 1838 | OS.get())); |
Ted Kremenek | db094a2 | 2007-12-05 18:27:04 +0000 | [diff] [blame] | 1839 | break; |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | case GeneratePCH: |
| 1843 | OS.reset(ComputeOutFile(InFile, 0, true, OutPath)); |
| 1844 | Consumer.reset(CreatePCHGenerator(PP, OS.get())); |
| 1845 | CompleteTranslationUnit = false; |
| 1846 | break; |
| 1847 | |
| 1848 | case RewriteObjC: |
| 1849 | OS.reset(ComputeOutFile(InFile, "cpp", true, OutPath)); |
Eli Friedman | bce831b | 2009-05-18 22:29:17 +0000 | [diff] [blame] | 1850 | Consumer.reset(CreateObjCRewriter(InFile, OS.get(), PP.getDiagnostics(), |
Eli Friedman | c6d656e | 2009-05-18 22:39:16 +0000 | [diff] [blame] | 1851 | PP.getLangOptions(), |
| 1852 | SilenceRewriteMacroWarning)); |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1853 | break; |
| 1854 | |
| 1855 | case RewriteBlocks: |
| 1856 | Consumer.reset(CreateBlockRewriter(InFile, PP.getDiagnostics(), |
| 1857 | PP.getLangOptions())); |
| 1858 | break; |
| 1859 | |
Eli Friedman | e71b85f | 2009-05-19 10:18:02 +0000 | [diff] [blame] | 1860 | case RunAnalysis: { |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1861 | Consumer.reset(CreateAnalysisConsumer(PP.getDiagnostics(), &PP, &PPF, |
Eli Friedman | e71b85f | 2009-05-19 10:18:02 +0000 | [diff] [blame] | 1862 | PP.getLangOptions(), OutputFile, |
| 1863 | ReadAnalyzerOptions())); |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1864 | break; |
Eli Friedman | e71b85f | 2009-05-19 10:18:02 +0000 | [diff] [blame] | 1865 | } |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 1866 | |
Chris Lattner | c106c10 | 2008-10-12 05:03:36 +0000 | [diff] [blame] | 1867 | case DumpRawTokens: { |
Chris Lattner | 4709974 | 2009-02-18 01:51:21 +0000 | [diff] [blame] | 1868 | llvm::TimeRegion Timer(ClangFrontendTimer); |
Chris Lattner | c106c10 | 2008-10-12 05:03:36 +0000 | [diff] [blame] | 1869 | SourceManager &SM = PP.getSourceManager(); |
Chris Lattner | c106c10 | 2008-10-12 05:03:36 +0000 | [diff] [blame] | 1870 | // Start lexing the specified input file. |
Chris Lattner | 025c3a6 | 2009-01-17 07:35:14 +0000 | [diff] [blame] | 1871 | Lexer RawLex(SM.getMainFileID(), SM, PP.getLangOptions()); |
Chris Lattner | c106c10 | 2008-10-12 05:03:36 +0000 | [diff] [blame] | 1872 | RawLex.SetKeepWhitespaceMode(true); |
| 1873 | |
| 1874 | Token RawTok; |
Chris Lattner | c106c10 | 2008-10-12 05:03:36 +0000 | [diff] [blame] | 1875 | RawLex.LexFromRawLexer(RawTok); |
| 1876 | while (RawTok.isNot(tok::eof)) { |
| 1877 | PP.DumpToken(RawTok, true); |
| 1878 | fprintf(stderr, "\n"); |
| 1879 | RawLex.LexFromRawLexer(RawTok); |
| 1880 | } |
| 1881 | ClearSourceMgr = true; |
| 1882 | break; |
| 1883 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1884 | case DumpTokens: { // Token dump mode. |
Chris Lattner | 4709974 | 2009-02-18 01:51:21 +0000 | [diff] [blame] | 1885 | llvm::TimeRegion Timer(ClangFrontendTimer); |
Chris Lattner | d217773 | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 1886 | Token Tok; |
Chris Lattner | c106c10 | 2008-10-12 05:03:36 +0000 | [diff] [blame] | 1887 | // Start preprocessing the specified input file. |
Ted Kremenek | 95041a2 | 2007-12-19 22:51:13 +0000 | [diff] [blame] | 1888 | PP.EnterMainSourceFile(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1889 | do { |
| 1890 | PP.Lex(Tok); |
| 1891 | PP.DumpToken(Tok, true); |
| 1892 | fprintf(stderr, "\n"); |
Chris Lattner | 057aaf6 | 2007-10-09 18:03:42 +0000 | [diff] [blame] | 1893 | } while (Tok.isNot(tok::eof)); |
Chris Lattner | bd24776 | 2007-07-22 06:05:44 +0000 | [diff] [blame] | 1894 | ClearSourceMgr = true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1895 | break; |
| 1896 | } |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1897 | case RunPreprocessorOnly: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1898 | break; |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 1899 | |
Douglas Gregor | bf1bd6e | 2009-04-02 23:43:50 +0000 | [diff] [blame] | 1900 | case GeneratePTH: { |
Chris Lattner | 4709974 | 2009-02-18 01:51:21 +0000 | [diff] [blame] | 1901 | llvm::TimeRegion Timer(ClangFrontendTimer); |
Eli Friedman | f54fce8 | 2009-05-19 01:02:07 +0000 | [diff] [blame] | 1902 | if (OutputFile.empty() || OutputFile == "-") { |
| 1903 | // FIXME: Don't fail this way. |
| 1904 | // FIXME: Verify that we can actually seek in the given file. |
| 1905 | llvm::cerr << "ERROR: PTH requires an seekable file for output!\n"; |
| 1906 | ::exit(1); |
| 1907 | } |
| 1908 | OS.reset(ComputeOutFile(InFile, 0, true, OutPath)); |
| 1909 | CacheTokens(PP, static_cast<llvm::raw_fd_ostream*>(OS.get())); |
Ted Kremenek | 8588896 | 2008-10-21 00:54:44 +0000 | [diff] [blame] | 1910 | ClearSourceMgr = true; |
| 1911 | break; |
| 1912 | } |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 1913 | |
Chris Lattner | cc7dea8 | 2009-04-27 22:02:30 +0000 | [diff] [blame] | 1914 | case PrintPreprocessedInput: |
Eli Friedman | f54fce8 | 2009-05-19 01:02:07 +0000 | [diff] [blame] | 1915 | OS.reset(ComputeOutFile(InFile, 0, true, OutPath)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1916 | break; |
Chris Lattner | b57e3d4 | 2008-05-08 06:52:13 +0000 | [diff] [blame] | 1917 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1918 | case ParseNoop: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1919 | break; |
| 1920 | |
Chris Lattner | 4709974 | 2009-02-18 01:51:21 +0000 | [diff] [blame] | 1921 | case ParsePrintCallbacks: { |
| 1922 | llvm::TimeRegion Timer(ClangFrontendTimer); |
Eli Friedman | f54fce8 | 2009-05-19 01:02:07 +0000 | [diff] [blame] | 1923 | OS.reset(ComputeOutFile(InFile, 0, true, OutPath)); |
| 1924 | ParseFile(PP, CreatePrintParserActionsAction(PP, OS.get())); |
Chris Lattner | bd24776 | 2007-07-22 06:05:44 +0000 | [diff] [blame] | 1925 | ClearSourceMgr = true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1926 | break; |
Chris Lattner | 4709974 | 2009-02-18 01:51:21 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | case ParseSyntaxOnly: { // -fsyntax-only |
| 1930 | llvm::TimeRegion Timer(ClangFrontendTimer); |
Ted Kremenek | 7e7e625 | 2008-08-08 02:46:37 +0000 | [diff] [blame] | 1931 | Consumer.reset(new ASTConsumer()); |
Ted Kremenek | 2bf5514 | 2007-09-17 20:49:30 +0000 | [diff] [blame] | 1932 | break; |
Chris Lattner | 4709974 | 2009-02-18 01:51:21 +0000 | [diff] [blame] | 1933 | } |
Chris Lattner | b57e3d4 | 2008-05-08 06:52:13 +0000 | [diff] [blame] | 1934 | |
| 1935 | case RewriteMacros: |
Eli Friedman | f54fce8 | 2009-05-19 01:02:07 +0000 | [diff] [blame] | 1936 | OS.reset(ComputeOutFile(InFile, 0, true, OutPath)); |
| 1937 | RewriteMacrosInInput(PP, OS.get()); |
Chris Lattner | b57e3d4 | 2008-05-08 06:52:13 +0000 | [diff] [blame] | 1938 | ClearSourceMgr = true; |
| 1939 | break; |
Chris Lattner | b13c5ee | 2008-10-12 05:29:20 +0000 | [diff] [blame] | 1940 | |
Eli Friedman | f54fce8 | 2009-05-19 01:02:07 +0000 | [diff] [blame] | 1941 | case RewriteTest: |
| 1942 | OS.reset(ComputeOutFile(InFile, 0, true, OutPath)); |
| 1943 | DoRewriteTest(PP, OS.get()); |
Chris Lattner | b13c5ee | 2008-10-12 05:29:20 +0000 | [diff] [blame] | 1944 | ClearSourceMgr = true; |
| 1945 | break; |
Douglas Gregor | 558cb56 | 2009-04-02 01:08:08 +0000 | [diff] [blame] | 1946 | |
| 1947 | case FixIt: |
| 1948 | llvm::TimeRegion Timer(ClangFrontendTimer); |
| 1949 | Consumer.reset(new ASTConsumer()); |
Douglas Gregor | de4bf6a | 2009-04-02 17:13:00 +0000 | [diff] [blame] | 1950 | FixItRewrite = new FixItRewriter(PP.getDiagnostics(), |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1951 | PP.getSourceManager(), |
| 1952 | PP.getLangOptions()); |
Douglas Gregor | 558cb56 | 2009-04-02 01:08:08 +0000 | [diff] [blame] | 1953 | break; |
Chris Lattner | 4709974 | 2009-02-18 01:51:21 +0000 | [diff] [blame] | 1954 | } |
Ted Kremenek | 46157b5 | 2009-01-28 04:29:29 +0000 | [diff] [blame] | 1955 | |
Chris Lattner | 1aee61a | 2009-04-27 21:25:27 +0000 | [diff] [blame] | 1956 | if (FixItAtLocations.size() > 0) { |
| 1957 | // Even without the "-fixit" flag, with may have some specific |
| 1958 | // locations where the user has requested fixes. Process those |
| 1959 | // locations now. |
| 1960 | if (!FixItRewrite) |
| 1961 | FixItRewrite = new FixItRewriter(PP.getDiagnostics(), |
| 1962 | PP.getSourceManager(), |
| 1963 | PP.getLangOptions()); |
Chris Lattner | 9ecd26a | 2009-03-28 01:37:17 +0000 | [diff] [blame] | 1964 | |
Chris Lattner | 1aee61a | 2009-04-27 21:25:27 +0000 | [diff] [blame] | 1965 | bool AddedFixitLocation = false; |
| 1966 | for (unsigned Idx = 0, Last = FixItAtLocations.size(); |
| 1967 | Idx != Last; ++Idx) { |
| 1968 | RequestedSourceLocation Requested; |
| 1969 | if (FixItAtLocations[Idx].ResolveLocation(PP.getFileManager(), |
| 1970 | Requested)) { |
| 1971 | fprintf(stderr, "FIX-IT could not find file \"%s\"\n", |
| 1972 | FixItAtLocations[Idx].FileName.c_str()); |
| 1973 | } else { |
| 1974 | FixItRewrite->addFixItLocation(Requested); |
| 1975 | AddedFixitLocation = true; |
Douglas Gregor | 26df2f0 | 2009-04-02 19:05:20 +0000 | [diff] [blame] | 1976 | } |
| 1977 | } |
| 1978 | |
Chris Lattner | 1aee61a | 2009-04-27 21:25:27 +0000 | [diff] [blame] | 1979 | if (!AddedFixitLocation) { |
| 1980 | // All of the fix-it locations were bad. Don't fix anything. |
| 1981 | delete FixItRewrite; |
| 1982 | FixItRewrite = 0; |
| 1983 | } |
| 1984 | } |
| 1985 | |
| 1986 | llvm::OwningPtr<ASTContext> ContextOwner; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1987 | if (Consumer) |
Chris Lattner | 9ecd26a | 2009-03-28 01:37:17 +0000 | [diff] [blame] | 1988 | ContextOwner.reset(new ASTContext(PP.getLangOptions(), |
| 1989 | PP.getSourceManager(), |
| 1990 | PP.getTargetInfo(), |
| 1991 | PP.getIdentifierTable(), |
| 1992 | PP.getSelectorTable(), |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 1993 | /* FreeMemory = */ !DisableFree, |
| 1994 | /* size_reserve = */0, |
| 1995 | /* InitializeBuiltins = */ImplicitIncludePCH.empty())); |
Chris Lattner | cc7dea8 | 2009-04-27 22:02:30 +0000 | [diff] [blame] | 1996 | llvm::OwningPtr<PCHReader> Reader; |
| 1997 | llvm::OwningPtr<ExternalASTSource> Source; |
| 1998 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 1999 | if (!ImplicitIncludePCH.empty()) { |
Chris Lattner | cc7dea8 | 2009-04-27 22:02:30 +0000 | [diff] [blame] | 2000 | Reader.reset(new PCHReader(PP, ContextOwner.get())); |
| 2001 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2002 | // The user has asked us to include a precompiled header. Load |
| 2003 | // the precompiled header into the AST context. |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2004 | switch (Reader->ReadPCH(ImplicitIncludePCH)) { |
| 2005 | case PCHReader::Success: { |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 2006 | // Set the predefines buffer as suggested by the PCH |
| 2007 | // reader. Typically, the predefines buffer will be empty. |
| 2008 | PP.setPredefines(Reader->getSuggestedPredefines()); |
| 2009 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2010 | // Attach the PCH reader to the AST context as an external AST |
| 2011 | // source, so that declarations will be deserialized from the |
| 2012 | // PCH file as needed. |
Chris Lattner | cc7dea8 | 2009-04-27 22:02:30 +0000 | [diff] [blame] | 2013 | if (ContextOwner) { |
| 2014 | Source.reset(Reader.take()); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2015 | ContextOwner->setExternalSource(Source); |
Chris Lattner | cc7dea8 | 2009-04-27 22:02:30 +0000 | [diff] [blame] | 2016 | } |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2017 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2018 | } |
| 2019 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2020 | case PCHReader::Failure: |
| 2021 | // Unrecoverable failure: don't even try to process the input |
| 2022 | // file. |
| 2023 | return; |
| 2024 | |
| 2025 | case PCHReader::IgnorePCH: |
Douglas Gregor | 1ab86ac | 2009-04-28 22:01:16 +0000 | [diff] [blame] | 2026 | // No suitable PCH file could be found. Return an error. |
| 2027 | return; |
| 2028 | |
| 2029 | #if 0 |
| 2030 | // FIXME: We can recover from failed attempts to load PCH |
| 2031 | // files. This code will do so, if we ever want to enable it. |
| 2032 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2033 | // We delayed the initialization of builtins in the hope of |
| 2034 | // loading the PCH file. Since the PCH file could not be |
| 2035 | // loaded, initialize builtins now. |
| 2036 | if (ContextOwner) |
| 2037 | ContextOwner->InitializeBuiltins(PP.getIdentifierTable()); |
Douglas Gregor | 1ab86ac | 2009-04-28 22:01:16 +0000 | [diff] [blame] | 2038 | #endif |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | // Finish preprocessor initialization. We do this now (rather |
| 2042 | // than earlier) because this initialization creates new source |
| 2043 | // location entries in the source manager, which must come after |
| 2044 | // the source location entries for the PCH file. |
| 2045 | if (InitializeSourceManager(PP, InFile)) |
| 2046 | return; |
Ted Kremenek | 46157b5 | 2009-01-28 04:29:29 +0000 | [diff] [blame] | 2047 | } |
Daniel Dunbar | 879c3ea | 2008-10-27 22:03:52 +0000 | [diff] [blame] | 2048 | |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2049 | |
| 2050 | // If we have an ASTConsumer, run the parser with it. |
| 2051 | if (Consumer) |
| 2052 | ParseAST(PP, Consumer.get(), *ContextOwner.get(), Stats, |
| 2053 | CompleteTranslationUnit); |
| 2054 | |
| 2055 | if (PA == RunPreprocessorOnly) { // Just lex as fast as we can, no output. |
| 2056 | llvm::TimeRegion Timer(ClangFrontendTimer); |
| 2057 | Token Tok; |
| 2058 | // Start parsing the specified input file. |
| 2059 | PP.EnterMainSourceFile(); |
| 2060 | do { |
| 2061 | PP.Lex(Tok); |
| 2062 | } while (Tok.isNot(tok::eof)); |
| 2063 | ClearSourceMgr = true; |
| 2064 | } else if (PA == ParseNoop) { // -parse-noop |
| 2065 | llvm::TimeRegion Timer(ClangFrontendTimer); |
| 2066 | ParseFile(PP, new MinimalAction(PP)); |
| 2067 | ClearSourceMgr = true; |
Chris Lattner | cc7dea8 | 2009-04-27 22:02:30 +0000 | [diff] [blame] | 2068 | } else if (PA == PrintPreprocessedInput){ // -E mode. |
| 2069 | llvm::TimeRegion Timer(ClangFrontendTimer); |
Eli Friedman | 12d3b1d | 2009-05-19 03:06:47 +0000 | [diff] [blame] | 2070 | if (DumpMacros) |
| 2071 | DoPrintMacros(PP, OS.get()); |
| 2072 | else |
| 2073 | DoPrintPreprocessedInput(PP, OS.get(), EnableCommentOutput, |
| 2074 | EnableMacroCommentOutput, |
| 2075 | DisableLineMarkers, DumpDefines); |
Chris Lattner | cc7dea8 | 2009-04-27 22:02:30 +0000 | [diff] [blame] | 2076 | ClearSourceMgr = true; |
Chris Lattner | d1d64a0 | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
Chris Lattner | 1aee61a | 2009-04-27 21:25:27 +0000 | [diff] [blame] | 2079 | if (FixItRewrite) |
| 2080 | FixItRewrite->WriteFixedFile(InFile, OutputFile); |
| 2081 | |
| 2082 | // If in -disable-free mode, don't deallocate ASTContext. |
| 2083 | if (DisableFree) |
| 2084 | ContextOwner.take(); |
| 2085 | else |
| 2086 | ContextOwner.reset(); // Delete ASTContext |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 2087 | |
Daniel Dunbar | 879c3ea | 2008-10-27 22:03:52 +0000 | [diff] [blame] | 2088 | if (VerifyDiagnostics) |
Daniel Dunbar | 276373d | 2008-10-27 22:10:13 +0000 | [diff] [blame] | 2089 | if (CheckDiagnostics(PP)) |
| 2090 | exit(1); |
Chris Lattner | e66b65c | 2008-02-06 01:42:25 +0000 | [diff] [blame] | 2091 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2092 | if (Stats) { |
Ted Kremenek | fdfc198 | 2007-12-19 22:24:34 +0000 | [diff] [blame] | 2093 | fprintf(stderr, "\nSTATISTICS FOR '%s':\n", InFile.c_str()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2094 | PP.PrintStats(); |
| 2095 | PP.getIdentifierTable().PrintStats(); |
Chris Lattner | dee7359 | 2007-12-15 20:48:40 +0000 | [diff] [blame] | 2096 | PP.getHeaderSearchInfo().PrintStats(); |
Ted Kremenek | 1b95a65 | 2009-01-09 18:20:21 +0000 | [diff] [blame] | 2097 | PP.getSourceManager().PrintStats(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2098 | fprintf(stderr, "\n"); |
| 2099 | } |
Chris Lattner | bd24776 | 2007-07-22 06:05:44 +0000 | [diff] [blame] | 2100 | |
| 2101 | // For a multi-file compilation, some things are ok with nuking the source |
| 2102 | // manager tables, other require stable fileid/macroid's across multiple |
| 2103 | // files. |
Chris Lattner | dee7359 | 2007-12-15 20:48:40 +0000 | [diff] [blame] | 2104 | if (ClearSourceMgr) |
| 2105 | PP.getSourceManager().clearIDTables(); |
Daniel Dunbar | d68ba0e | 2008-11-11 06:35:39 +0000 | [diff] [blame] | 2106 | |
| 2107 | if (DisableFree) |
| 2108 | Consumer.take(); |
Eli Friedman | 66d6f04 | 2009-05-18 22:20:00 +0000 | [diff] [blame] | 2109 | else |
| 2110 | Consumer.reset(); |
| 2111 | |
| 2112 | // Always delete the output stream because we don't want to leak file |
| 2113 | // handles. Also, we don't want to try to erase an open file. |
| 2114 | OS.reset(); |
| 2115 | |
| 2116 | if ((HadErrors || (PP.getDiagnostics().getNumErrors() != 0)) && |
| 2117 | !OutPath.isEmpty()) { |
| 2118 | // If we had errors, try to erase the output file. |
| 2119 | OutPath.eraseFromDisk(); |
| 2120 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | static llvm::cl::list<std::string> |
| 2124 | InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>")); |
| 2125 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2126 | int main(int argc, char **argv) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2127 | llvm::sys::PrintStackTraceOnErrorSignal(); |
Chris Lattner | 09e94a3 | 2009-03-04 21:41:39 +0000 | [diff] [blame] | 2128 | llvm::PrettyStackTraceProgram X(argc, argv); |
Chris Lattner | dc76310 | 2009-03-06 05:38:04 +0000 | [diff] [blame] | 2129 | llvm::cl::ParseCommandLineOptions(argc, argv, |
Chris Lattner | 110e478 | 2009-03-06 05:38:25 +0000 | [diff] [blame] | 2130 | "LLVM 'Clang' Compiler: http://clang.llvm.org\n"); |
Daniel Dunbar | 08e6dc6 | 2009-05-28 16:37:33 +0000 | [diff] [blame] | 2131 | |
Chris Lattner | 4709974 | 2009-02-18 01:51:21 +0000 | [diff] [blame] | 2132 | if (TimeReport) |
| 2133 | ClangFrontendTimer = new llvm::Timer("Clang front-end time"); |
| 2134 | |
Daniel Dunbar | 08e6dc6 | 2009-05-28 16:37:33 +0000 | [diff] [blame] | 2135 | if (Verbose) |
| 2136 | fprintf(stderr, "clang-cc version 1.0 based upon " PACKAGE_STRING |
| 2137 | " hosted on " LLVM_HOSTTRIPLE "\n"); |
| 2138 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2139 | // If no input was specified, read from stdin. |
| 2140 | if (InputFilenames.empty()) |
| 2141 | InputFilenames.push_back("-"); |
Douglas Gregor | 68a0d78 | 2009-05-02 00:03:46 +0000 | [diff] [blame] | 2142 | |
Ted Kremenek | 31e703b | 2007-12-11 23:28:38 +0000 | [diff] [blame] | 2143 | // Create the diagnostic client for reporting errors or for |
| 2144 | // implementing -verify. |
Chris Lattner | 409d4e7 | 2009-04-17 20:40:01 +0000 | [diff] [blame] | 2145 | llvm::OwningPtr<DiagnosticClient> DiagClient; |
| 2146 | if (VerifyDiagnostics) { |
| 2147 | // When checking diagnostics, just buffer them up. |
| 2148 | DiagClient.reset(new TextDiagnosticBuffer()); |
| 2149 | if (InputFilenames.size() != 1) { |
| 2150 | fprintf(stderr, "-verify only works on single input files for now.\n"); |
| 2151 | return 1; |
| 2152 | } |
| 2153 | if (!HTMLDiag.empty()) { |
| 2154 | fprintf(stderr, "-verify and -html-diags don't work together\n"); |
| 2155 | return 1; |
| 2156 | } |
| 2157 | } else if (HTMLDiag.empty()) { |
Ted Kremenek | b4398aa | 2008-08-07 17:49:57 +0000 | [diff] [blame] | 2158 | // Print diagnostics to stderr by default. |
Douglas Gregor | 68a0d78 | 2009-05-02 00:03:46 +0000 | [diff] [blame] | 2159 | |
| 2160 | // If -fmessage-length=N was not specified, determine whether this |
| 2161 | // is a terminal and, if so, implicitly define -fmessage-length |
| 2162 | // appropriately. |
| 2163 | if (MessageLength.getNumOccurrences() == 0) |
Douglas Gregor | 67187ce | 2009-05-11 18:06:49 +0000 | [diff] [blame] | 2164 | MessageLength.setValue(llvm::sys::Process::StandardErrColumns()); |
Douglas Gregor | 68a0d78 | 2009-05-02 00:03:46 +0000 | [diff] [blame] | 2165 | |
Torok Edwin | 603fca7 | 2009-06-04 07:18:23 +0000 | [diff] [blame] | 2166 | if (!NoColorDiagnostic) { |
| 2167 | NoColorDiagnostic.setValue(!llvm::sys::Process::StandardErrHasColors()); |
| 2168 | } |
| 2169 | |
Chris Lattner | 409d4e7 | 2009-04-17 20:40:01 +0000 | [diff] [blame] | 2170 | DiagClient.reset(new TextDiagnosticPrinter(llvm::errs(), |
Chris Lattner | a03a5b5 | 2008-11-19 06:56:25 +0000 | [diff] [blame] | 2171 | !NoShowColumn, |
Chris Lattner | 65f5e64 | 2009-01-30 19:01:41 +0000 | [diff] [blame] | 2172 | !NoCaretDiagnostics, |
Chris Lattner | 1fbee5d | 2009-03-13 01:08:23 +0000 | [diff] [blame] | 2173 | !NoShowLocation, |
Chris Lattner | d51d74a | 2009-04-16 05:44:38 +0000 | [diff] [blame] | 2174 | PrintSourceRangeInfo, |
Chris Lattner | aa5bf2e | 2009-04-19 07:44:08 +0000 | [diff] [blame] | 2175 | PrintDiagnosticOption, |
Douglas Gregor | fffd93f | 2009-05-01 21:53:04 +0000 | [diff] [blame] | 2176 | !NoDiagnosticsFixIt, |
Torok Edwin | 603fca7 | 2009-06-04 07:18:23 +0000 | [diff] [blame] | 2177 | MessageLength, |
| 2178 | !NoColorDiagnostic)); |
Ted Kremenek | b4398aa | 2008-08-07 17:49:57 +0000 | [diff] [blame] | 2179 | } else { |
Chris Lattner | 409d4e7 | 2009-04-17 20:40:01 +0000 | [diff] [blame] | 2180 | DiagClient.reset(CreateHTMLDiagnosticClient(HTMLDiag)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2181 | } |
Chris Lattner | 75a97cb | 2009-04-17 21:05:01 +0000 | [diff] [blame] | 2182 | |
| 2183 | if (!DumpBuildInformation.empty()) { |
| 2184 | if (!HTMLDiag.empty()) { |
| 2185 | fprintf(stderr, |
| 2186 | "-dump-build-information and -html-diags don't work together\n"); |
| 2187 | return 1; |
| 2188 | } |
| 2189 | |
| 2190 | SetUpBuildDumpLog(argc, argv, DiagClient); |
| 2191 | } |
| 2192 | |
Ted Kremenek | b4398aa | 2008-08-07 17:49:57 +0000 | [diff] [blame] | 2193 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2194 | // Configure our handling of diagnostics. |
Ted Kremenek | b4398aa | 2008-08-07 17:49:57 +0000 | [diff] [blame] | 2195 | Diagnostic Diags(DiagClient.get()); |
Eli Friedman | 0eeb86e | 2009-05-19 01:17:04 +0000 | [diff] [blame] | 2196 | if (ProcessWarningOptions(Diags, OptWarnings, OptPedantic, OptPedanticErrors, |
| 2197 | OptNoWarnings)) |
Sebastian Redl | 63a9e0f | 2009-03-06 17:41:35 +0000 | [diff] [blame] | 2198 | return 1; |
Ted Kremenek | 31e703b | 2007-12-11 23:28:38 +0000 | [diff] [blame] | 2199 | |
Chris Lattner | 4f03783 | 2007-12-05 23:24:17 +0000 | [diff] [blame] | 2200 | // -I- is a deprecated GCC feature, scan for it and reject it. |
| 2201 | for (unsigned i = 0, e = I_dirs.size(); i != e; ++i) { |
| 2202 | if (I_dirs[i] == "-") { |
Chris Lattner | 5917fe1 | 2008-11-18 05:05:28 +0000 | [diff] [blame] | 2203 | Diags.Report(FullSourceLoc(), diag::err_pp_I_dash_not_supported); |
Chris Lattner | 4f03783 | 2007-12-05 23:24:17 +0000 | [diff] [blame] | 2204 | I_dirs.erase(I_dirs.begin()+i); |
| 2205 | --i; |
| 2206 | } |
| 2207 | } |
Chris Lattner | 1121519 | 2008-03-14 06:12:05 +0000 | [diff] [blame] | 2208 | |
| 2209 | // Get information about the target being compiled for. |
| 2210 | std::string Triple = CreateTargetTriple(); |
Ted Kremenek | 7a08e28 | 2008-08-07 18:13:12 +0000 | [diff] [blame] | 2211 | llvm::OwningPtr<TargetInfo> Target(TargetInfo::CreateTargetInfo(Triple)); |
| 2212 | |
Chris Lattner | 1121519 | 2008-03-14 06:12:05 +0000 | [diff] [blame] | 2213 | if (Target == 0) { |
Daniel Dunbar | 50f4f46 | 2009-03-12 10:14:16 +0000 | [diff] [blame] | 2214 | Diags.Report(FullSourceLoc(), diag::err_fe_unknown_triple) |
| 2215 | << Triple.c_str(); |
Sebastian Redl | c5613db | 2009-03-07 12:09:25 +0000 | [diff] [blame] | 2216 | return 1; |
Chris Lattner | 1121519 | 2008-03-14 06:12:05 +0000 | [diff] [blame] | 2217 | } |
Chris Lattner | 4f03783 | 2007-12-05 23:24:17 +0000 | [diff] [blame] | 2218 | |
Daniel Dunbar | d427023 | 2009-01-20 23:17:32 +0000 | [diff] [blame] | 2219 | if (!InheritanceViewCls.empty()) // C++ visualization? |
Ted Kremenek | 7cae2f6 | 2008-10-23 23:36:29 +0000 | [diff] [blame] | 2220 | ProgAction = InheritanceView; |
Ted Kremenek | b4398aa | 2008-08-07 17:49:57 +0000 | [diff] [blame] | 2221 | |
Ted Kremenek | c0c03bc | 2008-06-06 22:42:39 +0000 | [diff] [blame] | 2222 | llvm::OwningPtr<SourceManager> SourceMgr; |
| 2223 | |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 2224 | // Create a file manager object to provide access to and cache the filesystem. |
| 2225 | FileManager FileMgr; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2226 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 2227 | // Compute the feature set, unfortunately this effects the language! |
| 2228 | llvm::StringMap<bool> Features; |
| 2229 | ComputeFeatureMap(Target.get(), Features); |
| 2230 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2231 | for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) { |
Ted Kremenek | 31e703b | 2007-12-11 23:28:38 +0000 | [diff] [blame] | 2232 | const std::string &InFile = InputFilenames[i]; |
Ted Kremenek | 31e703b | 2007-12-11 23:28:38 +0000 | [diff] [blame] | 2233 | |
Chris Lattner | f63aea3 | 2009-03-04 21:40:56 +0000 | [diff] [blame] | 2234 | /// Create a SourceManager object. This tracks and owns all the file |
| 2235 | /// buffers allocated to a translation unit. |
| 2236 | if (!SourceMgr) |
| 2237 | SourceMgr.reset(new SourceManager()); |
| 2238 | else |
| 2239 | SourceMgr->clearIDTables(); |
| 2240 | |
| 2241 | // Initialize language options, inferring file types from input filenames. |
| 2242 | LangOptions LangInfo; |
Chris Lattner | 409d4e7 | 2009-04-17 20:40:01 +0000 | [diff] [blame] | 2243 | DiagClient->setLangOptions(&LangInfo); |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 2244 | |
Chris Lattner | f63aea3 | 2009-03-04 21:40:56 +0000 | [diff] [blame] | 2245 | InitializeBaseLanguage(); |
| 2246 | LangKind LK = GetLanguage(InFile); |
Daniel Dunbar | 0b5b0da | 2009-04-01 05:09:09 +0000 | [diff] [blame] | 2247 | InitializeLangOptions(LangInfo, LK); |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 2248 | InitializeLanguageStandard(LangInfo, LK, Target.get(), Features); |
Chris Lattner | f63aea3 | 2009-03-04 21:40:56 +0000 | [diff] [blame] | 2249 | |
| 2250 | // Process the -I options and set them in the HeaderInfo. |
| 2251 | HeaderSearch HeaderInfo(FileMgr); |
| 2252 | |
Chris Lattner | 2c78b87 | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 2253 | |
Chris Lattner | f63aea3 | 2009-03-04 21:40:56 +0000 | [diff] [blame] | 2254 | InitializeIncludePaths(argv[0], HeaderInfo, FileMgr, LangInfo); |
| 2255 | |
| 2256 | // Set up the preprocessor with these options. |
Eli Friedman | f086e3b | 2009-05-18 07:39:39 +0000 | [diff] [blame] | 2257 | DriverPreprocessorFactory PPFactory(Diags, LangInfo, *Target, |
Chris Lattner | f63aea3 | 2009-03-04 21:40:56 +0000 | [diff] [blame] | 2258 | *SourceMgr.get(), HeaderInfo); |
| 2259 | |
| 2260 | llvm::OwningPtr<Preprocessor> PP(PPFactory.CreatePreprocessor()); |
| 2261 | |
| 2262 | if (!PP) |
| 2263 | continue; |
Ted Kremenek | b4398aa | 2008-08-07 17:49:57 +0000 | [diff] [blame] | 2264 | |
Eli Friedman | b5c8f8b | 2009-05-19 03:35:57 +0000 | [diff] [blame] | 2265 | // Handle generating dependencies, if requested |
| 2266 | if (!DependencyFile.empty()) { |
| 2267 | llvm::raw_ostream *DependencyOS; |
| 2268 | if (DependencyTargets.empty()) { |
| 2269 | // FIXME: Use a proper diagnostic |
| 2270 | llvm::cerr << "-dependency-file requires at least one -MT option\n"; |
| 2271 | HadErrors = true; |
| 2272 | continue; |
| 2273 | } |
| 2274 | std::string ErrStr; |
| 2275 | DependencyOS = |
| 2276 | new llvm::raw_fd_ostream(DependencyFile.c_str(), false, ErrStr); |
| 2277 | if (!ErrStr.empty()) { |
| 2278 | // FIXME: Use a proper diagnostic |
| 2279 | llvm::cerr << "unable to open dependency file: " + ErrStr; |
| 2280 | HadErrors = true; |
| 2281 | continue; |
| 2282 | } |
| 2283 | |
| 2284 | AttachDependencyFileGen(PP.get(), DependencyOS, DependencyTargets, |
| 2285 | DependenciesIncludeSystemHeaders, |
| 2286 | PhonyDependencyTarget); |
| 2287 | } |
| 2288 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2289 | if (ImplicitIncludePCH.empty() && |
| 2290 | InitializeSourceManager(*PP.get(), InFile)) |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2291 | continue; |
| 2292 | |
Chris Lattner | 409d4e7 | 2009-04-17 20:40:01 +0000 | [diff] [blame] | 2293 | if (!HTMLDiag.empty()) |
| 2294 | ((PathDiagnosticClient*)DiagClient.get())->SetPreprocessor(PP.get()); |
Chris Lattner | f63aea3 | 2009-03-04 21:40:56 +0000 | [diff] [blame] | 2295 | |
| 2296 | // Process the source file. |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 2297 | ProcessInputFile(*PP, PPFactory, InFile, ProgAction, Features); |
Chris Lattner | f63aea3 | 2009-03-04 21:40:56 +0000 | [diff] [blame] | 2298 | |
Chris Lattner | 4046965 | 2009-04-17 20:16:08 +0000 | [diff] [blame] | 2299 | HeaderInfo.ClearFileInfo(); |
Chris Lattner | 409d4e7 | 2009-04-17 20:40:01 +0000 | [diff] [blame] | 2300 | DiagClient->setLangOptions(0); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2301 | } |
Chris Lattner | 1121519 | 2008-03-14 06:12:05 +0000 | [diff] [blame] | 2302 | |
Mike Stump | fc0fed3 | 2009-04-28 01:19:10 +0000 | [diff] [blame] | 2303 | if (!NoCaretDiagnostics) |
| 2304 | if (unsigned NumDiagnostics = Diags.getNumDiagnostics()) |
| 2305 | fprintf(stderr, "%d diagnostic%s generated.\n", NumDiagnostics, |
| 2306 | (NumDiagnostics == 1 ? "" : "s")); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2307 | |
| 2308 | if (Stats) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2309 | FileMgr.PrintStats(); |
| 2310 | fprintf(stderr, "\n"); |
| 2311 | } |
Chris Lattner | 75a97cb | 2009-04-17 21:05:01 +0000 | [diff] [blame] | 2312 | |
| 2313 | delete ClangFrontendTimer; |
| 2314 | delete BuildLogFile; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2315 | |
Daniel Dunbar | 276373d | 2008-10-27 22:10:13 +0000 | [diff] [blame] | 2316 | // If verifying diagnostics and we reached here, all is well. |
| 2317 | if (VerifyDiagnostics) |
| 2318 | return 0; |
Chris Lattner | 4709974 | 2009-02-18 01:51:21 +0000 | [diff] [blame] | 2319 | |
Daniel Dunbar | 524b86f | 2008-10-28 00:38:08 +0000 | [diff] [blame] | 2320 | // Managed static deconstruction. Useful for making things like |
| 2321 | // -time-passes usable. |
| 2322 | llvm::llvm_shutdown(); |
| 2323 | |
Daniel Dunbar | b0adbba | 2008-10-04 23:42:49 +0000 | [diff] [blame] | 2324 | return HadErrors || (Diags.getNumErrors() != 0); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2325 | } |