Daniel Dunbar | 41b5b17 | 2010-05-20 17:49:16 +0000 | [diff] [blame] | 1 | //===-- cc1_main.cpp - Clang CC1 Compiler Frontend ------------------------===// |
Daniel Dunbar | 217acbf | 2009-11-19 07:37:51 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 10 | // This is the entry point to the clang -cc1 functionality, which implements the |
| 11 | // core compiler functionality along with a number of additional tools for |
| 12 | // demonstration and testing purposes. |
Daniel Dunbar | 217acbf | 2009-11-19 07:37:51 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 16 | #include "clang/Basic/Diagnostic.h" |
Daniel Dunbar | 9b414d3 | 2010-06-15 17:48:49 +0000 | [diff] [blame] | 17 | #include "clang/Checker/FrontendActions.h" |
| 18 | #include "clang/CodeGen/CodeGenAction.h" |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 19 | #include "clang/Driver/Arg.h" |
| 20 | #include "clang/Driver/ArgList.h" |
| 21 | #include "clang/Driver/CC1Options.h" |
| 22 | #include "clang/Driver/DriverDiagnostic.h" |
| 23 | #include "clang/Driver/OptTable.h" |
| 24 | #include "clang/Frontend/CompilerInstance.h" |
| 25 | #include "clang/Frontend/CompilerInvocation.h" |
| 26 | #include "clang/Frontend/FrontendActions.h" |
| 27 | #include "clang/Frontend/FrontendDiagnostic.h" |
| 28 | #include "clang/Frontend/FrontendPluginRegistry.h" |
| 29 | #include "clang/Frontend/TextDiagnosticBuffer.h" |
| 30 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
Daniel Dunbar | 9b414d3 | 2010-06-15 17:48:49 +0000 | [diff] [blame] | 31 | #include "clang/Rewrite/FrontendActions.h" |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 32 | #include "llvm/LLVMContext.h" |
| 33 | #include "llvm/ADT/OwningPtr.h" |
Douglas Gregor | 95dd558 | 2010-03-30 17:33:59 +0000 | [diff] [blame] | 34 | #include "llvm/ADT/Statistic.h" |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 35 | #include "llvm/Support/ErrorHandling.h" |
| 36 | #include "llvm/Support/ManagedStatic.h" |
Chris Lattner | 30bc7e8 | 2010-03-30 05:39:52 +0000 | [diff] [blame] | 37 | #include "llvm/Support/Timer.h" |
Daniel Dunbar | 217acbf | 2009-11-19 07:37:51 +0000 | [diff] [blame] | 38 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 39 | #include "llvm/System/DynamicLibrary.h" |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 40 | #include "llvm/Target/TargetSelect.h" |
| 41 | #include <cstdio> |
| 42 | using namespace clang; |
Daniel Dunbar | 217acbf | 2009-11-19 07:37:51 +0000 | [diff] [blame] | 43 | |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 44 | //===----------------------------------------------------------------------===// |
| 45 | // Main driver |
| 46 | //===----------------------------------------------------------------------===// |
| 47 | |
Daniel Dunbar | 41b5b17 | 2010-05-20 17:49:16 +0000 | [diff] [blame] | 48 | static void LLVMErrorHandler(void *UserData, const std::string &Message) { |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 49 | Diagnostic &Diags = *static_cast<Diagnostic*>(UserData); |
| 50 | |
| 51 | Diags.Report(diag::err_fe_error_backend) << Message; |
| 52 | |
| 53 | // We cannot recover from llvm errors. |
| 54 | exit(1); |
| 55 | } |
| 56 | |
Douglas Gregor | 9bed879 | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 57 | static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) { |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 58 | using namespace clang::frontend; |
| 59 | |
| 60 | switch (CI.getFrontendOpts().ProgramAction) { |
| 61 | default: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 62 | llvm_unreachable("Invalid program action!"); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 63 | |
| 64 | case ASTDump: return new ASTDumpAction(); |
| 65 | case ASTPrint: return new ASTPrintAction(); |
| 66 | case ASTPrintXML: return new ASTPrintXMLAction(); |
| 67 | case ASTView: return new ASTViewAction(); |
Douglas Gregor | f78cc43 | 2010-05-07 15:41:56 +0000 | [diff] [blame] | 68 | case BoostCon: return new BoostConAction(); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 69 | case DumpRawTokens: return new DumpRawTokensAction(); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 70 | case DumpTokens: return new DumpTokensAction(); |
| 71 | case EmitAssembly: return new EmitAssemblyAction(); |
| 72 | case EmitBC: return new EmitBCAction(); |
| 73 | case EmitHTML: return new HTMLPrintAction(); |
| 74 | case EmitLLVM: return new EmitLLVMAction(); |
| 75 | case EmitLLVMOnly: return new EmitLLVMOnlyAction(); |
Daniel Dunbar | 32148ce | 2010-05-25 18:41:01 +0000 | [diff] [blame] | 76 | case EmitCodeGenOnly: return new EmitCodeGenOnlyAction(); |
Daniel Dunbar | da1573f | 2010-02-03 01:18:43 +0000 | [diff] [blame] | 77 | case EmitObj: return new EmitObjAction(); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 78 | case FixIt: return new FixItAction(); |
| 79 | case GeneratePCH: return new GeneratePCHAction(); |
| 80 | case GeneratePTH: return new GeneratePTHAction(); |
| 81 | case InheritanceView: return new InheritanceViewAction(); |
Daniel Dunbar | 2758595 | 2010-03-19 19:44:04 +0000 | [diff] [blame] | 82 | case InitOnly: return new InitOnlyAction(); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 83 | case ParseSyntaxOnly: return new SyntaxOnlyAction(); |
| 84 | |
| 85 | case PluginAction: { |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 86 | for (FrontendPluginRegistry::iterator it = |
| 87 | FrontendPluginRegistry::begin(), ie = FrontendPluginRegistry::end(); |
| 88 | it != ie; ++it) { |
Daniel Dunbar | 3177aae | 2010-06-16 16:59:23 +0000 | [diff] [blame] | 89 | if (it->getName() == CI.getFrontendOpts().ActionName) { |
Daniel Dunbar | f56a488 | 2010-08-02 15:31:28 +0000 | [diff] [blame^] | 90 | llvm::OwningPtr<PluginASTAction> P(it->instantiate()); |
| 91 | if (!P->ParseArgs(CI, CI.getFrontendOpts().PluginArgs)) |
| 92 | return 0; |
| 93 | return P.take(); |
Daniel Dunbar | 3177aae | 2010-06-16 16:59:23 +0000 | [diff] [blame] | 94 | } |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | CI.getDiagnostics().Report(diag::err_fe_invalid_plugin_name) |
| 98 | << CI.getFrontendOpts().ActionName; |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | case PrintDeclContext: return new DeclContextPrintAction(); |
Douglas Gregor | f033f1d | 2010-07-20 20:18:03 +0000 | [diff] [blame] | 103 | case PrintPreamble: return new PrintPreambleAction(); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 104 | case PrintPreprocessedInput: return new PrintPreprocessedAction(); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 105 | case RewriteMacros: return new RewriteMacrosAction(); |
| 106 | case RewriteObjC: return new RewriteObjCAction(); |
| 107 | case RewriteTest: return new RewriteTestAction(); |
| 108 | case RunAnalysis: return new AnalysisAction(); |
| 109 | case RunPreprocessorOnly: return new PreprocessOnlyAction(); |
| 110 | } |
| 111 | } |
| 112 | |
Douglas Gregor | 9bed879 | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 113 | static FrontendAction *CreateFrontendAction(CompilerInstance &CI) { |
| 114 | // Create the underlying action. |
| 115 | FrontendAction *Act = CreateFrontendBaseAction(CI); |
| 116 | if (!Act) |
| 117 | return 0; |
| 118 | |
| 119 | // If there are any AST files to merge, create a frontend action |
| 120 | // adaptor to perform the merge. |
| 121 | if (!CI.getFrontendOpts().ASTMergeFiles.empty()) |
| 122 | Act = new ASTMergeAction(Act, &CI.getFrontendOpts().ASTMergeFiles[0], |
| 123 | CI.getFrontendOpts().ASTMergeFiles.size()); |
| 124 | |
| 125 | return Act; |
| 126 | } |
| 127 | |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 128 | // FIXME: Define the need for this testing away. |
| 129 | static int cc1_test(Diagnostic &Diags, |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 130 | const char **ArgBegin, const char **ArgEnd) { |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 131 | using namespace clang::driver; |
| 132 | |
Daniel Dunbar | 217acbf | 2009-11-19 07:37:51 +0000 | [diff] [blame] | 133 | llvm::errs() << "cc1 argv:"; |
| 134 | for (const char **i = ArgBegin; i != ArgEnd; ++i) |
| 135 | llvm::errs() << " \"" << *i << '"'; |
| 136 | llvm::errs() << "\n"; |
| 137 | |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 138 | // Parse the arguments. |
| 139 | OptTable *Opts = createCC1OptTable(); |
| 140 | unsigned MissingArgIndex, MissingArgCount; |
| 141 | InputArgList *Args = Opts->ParseArgs(ArgBegin, ArgEnd, |
| 142 | MissingArgIndex, MissingArgCount); |
| 143 | |
| 144 | // Check for missing argument error. |
| 145 | if (MissingArgCount) |
| 146 | Diags.Report(clang::diag::err_drv_missing_argument) |
| 147 | << Args->getArgString(MissingArgIndex) << MissingArgCount; |
| 148 | |
| 149 | // Dump the parsed arguments. |
| 150 | llvm::errs() << "cc1 parsed options:\n"; |
| 151 | for (ArgList::const_iterator it = Args->begin(), ie = Args->end(); |
| 152 | it != ie; ++it) |
| 153 | (*it)->dump(); |
| 154 | |
| 155 | // Create a compiler invocation. |
| 156 | llvm::errs() << "cc1 creating invocation.\n"; |
| 157 | CompilerInvocation Invocation; |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 158 | CompilerInvocation::CreateFromArgs(Invocation, ArgBegin, ArgEnd, Diags); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 159 | |
| 160 | // Convert the invocation back to argument strings. |
| 161 | std::vector<std::string> InvocationArgs; |
| 162 | Invocation.toArgs(InvocationArgs); |
| 163 | |
| 164 | // Dump the converted arguments. |
| 165 | llvm::SmallVector<const char*, 32> Invocation2Args; |
| 166 | llvm::errs() << "invocation argv :"; |
| 167 | for (unsigned i = 0, e = InvocationArgs.size(); i != e; ++i) { |
| 168 | Invocation2Args.push_back(InvocationArgs[i].c_str()); |
| 169 | llvm::errs() << " \"" << InvocationArgs[i] << '"'; |
| 170 | } |
| 171 | llvm::errs() << "\n"; |
| 172 | |
| 173 | // Convert those arguments to another invocation, and check that we got the |
| 174 | // same thing. |
| 175 | CompilerInvocation Invocation2; |
| 176 | CompilerInvocation::CreateFromArgs(Invocation2, Invocation2Args.begin(), |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 177 | Invocation2Args.end(), Diags); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 178 | |
| 179 | // FIXME: Implement CompilerInvocation comparison. |
| 180 | if (true) { |
| 181 | //llvm::errs() << "warning: Invocations differ!\n"; |
| 182 | |
| 183 | std::vector<std::string> Invocation2Args; |
| 184 | Invocation2.toArgs(Invocation2Args); |
| 185 | llvm::errs() << "invocation2 argv:"; |
| 186 | for (unsigned i = 0, e = Invocation2Args.size(); i != e; ++i) |
| 187 | llvm::errs() << " \"" << Invocation2Args[i] << '"'; |
| 188 | llvm::errs() << "\n"; |
| 189 | } |
| 190 | |
Daniel Dunbar | 217acbf | 2009-11-19 07:37:51 +0000 | [diff] [blame] | 191 | return 0; |
| 192 | } |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 193 | |
| 194 | int cc1_main(const char **ArgBegin, const char **ArgEnd, |
| 195 | const char *Argv0, void *MainAddr) { |
Daniel Dunbar | 42444fb | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 196 | llvm::OwningPtr<CompilerInstance> Clang(new CompilerInstance()); |
Daniel Dunbar | 42e9f8e4 | 2010-02-16 01:54:47 +0000 | [diff] [blame] | 197 | |
Chris Lattner | cabae68 | 2010-04-06 17:52:14 +0000 | [diff] [blame] | 198 | Clang->setLLVMContext(new llvm::LLVMContext()); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 199 | |
| 200 | // Run clang -cc1 test. |
| 201 | if (ArgBegin != ArgEnd && llvm::StringRef(ArgBegin[0]) == "-cc1test") { |
| 202 | TextDiagnosticPrinter DiagClient(llvm::errs(), DiagnosticOptions()); |
| 203 | Diagnostic Diags(&DiagClient); |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 204 | return cc1_test(Diags, ArgBegin + 1, ArgEnd); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | // Initialize targets first, so that --version shows registered targets. |
| 208 | llvm::InitializeAllTargets(); |
| 209 | llvm::InitializeAllAsmPrinters(); |
Chris Lattner | 01ae93f | 2010-04-05 23:33:20 +0000 | [diff] [blame] | 210 | llvm::InitializeAllAsmParsers(); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 211 | |
| 212 | // Buffer diagnostics from argument parsing so that we can output them using a |
| 213 | // well formed diagnostic object. |
| 214 | TextDiagnosticBuffer DiagsBuffer; |
| 215 | Diagnostic Diags(&DiagsBuffer); |
Daniel Dunbar | 42444fb | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 216 | CompilerInvocation::CreateFromArgs(Clang->getInvocation(), ArgBegin, ArgEnd, |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 217 | Diags); |
| 218 | |
| 219 | // Infer the builtin include path if unspecified. |
Daniel Dunbar | 42444fb | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 220 | if (Clang->getHeaderSearchOpts().UseBuiltinIncludes && |
| 221 | Clang->getHeaderSearchOpts().ResourceDir.empty()) |
| 222 | Clang->getHeaderSearchOpts().ResourceDir = |
Daniel Dunbar | 8b9adfe | 2009-12-15 00:06:45 +0000 | [diff] [blame] | 223 | CompilerInvocation::GetResourcesPath(Argv0, MainAddr); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 224 | |
| 225 | // Honor -help. |
Daniel Dunbar | 42444fb | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 226 | if (Clang->getFrontendOpts().ShowHelp) { |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 227 | llvm::OwningPtr<driver::OptTable> Opts(driver::createCC1OptTable()); |
| 228 | Opts->PrintHelp(llvm::outs(), "clang -cc1", |
| 229 | "LLVM 'Clang' Compiler: http://clang.llvm.org"); |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | // Honor -version. |
| 234 | // |
| 235 | // FIXME: Use a better -version message? |
Daniel Dunbar | 42444fb | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 236 | if (Clang->getFrontendOpts().ShowVersion) { |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 237 | llvm::cl::PrintVersionMessage(); |
| 238 | return 0; |
| 239 | } |
| 240 | |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 241 | // Honor -mllvm. |
| 242 | // |
| 243 | // FIXME: Remove this, one day. |
| 244 | if (!Clang->getFrontendOpts().LLVMArgs.empty()) { |
| 245 | unsigned NumArgs = Clang->getFrontendOpts().LLVMArgs.size(); |
| 246 | const char **Args = new const char*[NumArgs + 2]; |
| 247 | Args[0] = "clang (LLVM option parsing)"; |
| 248 | for (unsigned i = 0; i != NumArgs; ++i) |
| 249 | Args[i + 1] = Clang->getFrontendOpts().LLVMArgs[i].c_str(); |
| 250 | Args[NumArgs + 1] = 0; |
Dan Gohman | cb421fa | 2010-04-19 16:39:44 +0000 | [diff] [blame] | 251 | llvm::cl::ParseCommandLineOptions(NumArgs + 1, const_cast<char **>(Args)); |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 254 | // Create the actual diagnostics engine. |
Daniel Dunbar | 42444fb | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 255 | Clang->createDiagnostics(ArgEnd - ArgBegin, const_cast<char**>(ArgBegin)); |
| 256 | if (!Clang->hasDiagnostics()) |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 257 | return 1; |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 258 | |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 259 | // Set an error handler, so that any LLVM backend diagnostics go through our |
| 260 | // error handler. |
Chris Lattner | 1e3c6f4 | 2010-04-07 23:12:35 +0000 | [diff] [blame] | 261 | llvm::install_fatal_error_handler(LLVMErrorHandler, |
Daniel Dunbar | 42444fb | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 262 | static_cast<void*>(&Clang->getDiagnostics())); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 263 | |
Daniel Dunbar | 42444fb | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 264 | DiagsBuffer.FlushDiagnostics(Clang->getDiagnostics()); |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 265 | |
| 266 | // Load any requested plugins. |
| 267 | for (unsigned i = 0, |
Daniel Dunbar | 42444fb | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 268 | e = Clang->getFrontendOpts().Plugins.size(); i != e; ++i) { |
| 269 | const std::string &Path = Clang->getFrontendOpts().Plugins[i]; |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 270 | std::string Error; |
| 271 | if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error)) |
| 272 | Diags.Report(diag::err_fe_unable_to_load_plugin) << Path << Error; |
| 273 | } |
| 274 | |
Daniel Dunbar | 0397af2 | 2010-01-13 00:48:06 +0000 | [diff] [blame] | 275 | // If there were errors in processing arguments, don't do anything else. |
| 276 | bool Success = false; |
Daniel Dunbar | 42444fb | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 277 | if (!Clang->getDiagnostics().getNumErrors()) { |
Daniel Dunbar | 0397af2 | 2010-01-13 00:48:06 +0000 | [diff] [blame] | 278 | // Create and execute the frontend action. |
Daniel Dunbar | 42444fb | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 279 | llvm::OwningPtr<FrontendAction> Act(CreateFrontendAction(*Clang)); |
| 280 | if (Act) { |
| 281 | Success = Clang->ExecuteAction(*Act); |
| 282 | if (Clang->getFrontendOpts().DisableFree) |
| 283 | Act.take(); |
| 284 | } |
| 285 | } |
| 286 | |
Chris Lattner | 30bc7e8 | 2010-03-30 05:39:52 +0000 | [diff] [blame] | 287 | // If any timers were active but haven't been destroyed yet, print their |
| 288 | // results now. This happens in -disable-free mode. |
| 289 | llvm::TimerGroup::printAll(llvm::errs()); |
Daniel Dunbar | f56a488 | 2010-08-02 15:31:28 +0000 | [diff] [blame^] | 290 | |
Daniel Dunbar | 42444fb | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 291 | // When running with -disable-free, don't do any destruction or shutdown. |
| 292 | if (Clang->getFrontendOpts().DisableFree) { |
Douglas Gregor | 95dd558 | 2010-03-30 17:33:59 +0000 | [diff] [blame] | 293 | if (Clang->getFrontendOpts().ShowStats) |
| 294 | llvm::PrintStatistics(); |
Daniel Dunbar | 42444fb | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 295 | Clang.take(); |
| 296 | return !Success; |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 299 | // Managed static deconstruction. Useful for making things like |
| 300 | // -time-passes usable. |
| 301 | llvm::llvm_shutdown(); |
| 302 | |
Daniel Dunbar | 0397af2 | 2010-01-13 00:48:06 +0000 | [diff] [blame] | 303 | return !Success; |
Daniel Dunbar | 2108577 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 304 | } |