virtual void HandleTranslationUnit(ASTContext &C) { { PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); if (llvm::TimePassesIsEnabled) LLVMIRGeneration.startTimer(); Gen->HandleTranslationUnit(C); if (llvm::TimePassesIsEnabled) LLVMIRGeneration.stopTimer(); } // Silently ignore if we weren't initialized for some reason. if (!TheModule) return; // Make sure IR generation is happy with the module. This is released by // the module provider. llvm::Module *M = Gen->ReleaseModule(); if (!M) { // The module has been released by IR gen on failures, do not double // free. TheModule.take(); return; } assert(TheModule.get() == M && "Unexpected module change during IR generation"); // Link LinkModule into this module if present, preserving its validity. if (LinkModule) { std::string ErrorMsg; if (Linker::LinkModules(M, LinkModule.get(), Linker::PreserveSource, &ErrorMsg)) { Diags.Report(diag::err_fe_cannot_link_module) << LinkModule->getModuleIdentifier() << ErrorMsg; return; } } // Install an inline asm handler so that diagnostics get printed through // our diagnostics hooks. LLVMContext &Ctx = TheModule->getContext(); LLVMContext::InlineAsmDiagHandlerTy OldHandler = Ctx.getInlineAsmDiagnosticHandler(); void *OldContext = Ctx.getInlineAsmDiagnosticContext(); Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this); EmitBackendOutput(Diags, CodeGenOpts, TargetOpts, LangOpts, TheModule.get(), Action, AsmOutStream); Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext); }