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