bool RewriteIncludesAction::BeginSourceFileAction(CompilerInstance &CI) { if (!OutputStream) { OutputStream = CI.createDefaultOutputFile(true, getCurrentFileOrBufferName()); if (!OutputStream) return false; } auto &OS = *OutputStream; // If we're preprocessing a module map, start by dumping the contents of the // module itself before switching to the input buffer. auto &Input = getCurrentInput(); if (Input.getKind().getFormat() == InputKind::ModuleMap) { if (Input.isFile()) { OS << "# 1 \""; OS.write_escaped(Input.getFile()); OS << "\"\n"; } getCurrentModule()->print(OS); OS << "#pragma clang module contents\n"; } // If we're rewriting imports, set up a listener to track when we import // module files. if (CI.getPreprocessorOutputOpts().RewriteImports) { CI.createModuleManager(); CI.getModuleManager()->addListener( llvm::make_unique<RewriteImportsListener>(CI, OutputStream)); } return true; }
std::unique_ptr<ASTConsumer> HTMLPrintAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { if (std::unique_ptr<raw_ostream> OS = CI.createDefaultOutputFile(false, InFile)) return CreateHTMLPrinter(std::move(OS), CI.getPreprocessor()); return nullptr; }
std::unique_ptr<ASTConsumer> ASTPrintAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { if (std::unique_ptr<raw_ostream> OS = CI.createDefaultOutputFile(false, InFile)) return CreateASTPrinter(std::move(OS), CI.getFrontendOpts().ASTDumpFilter); return nullptr; }
static std::unique_ptr<raw_pwrite_stream> GetOutputStream(CompilerInstance &CI, StringRef InFile, BackendAction Action) { switch (Action) { case Backend_EmitAssembly: return CI.createDefaultOutputFile(false, InFile, "s"); case Backend_EmitLL: return CI.createDefaultOutputFile(false, InFile, "ll"); case Backend_EmitBC: return CI.createDefaultOutputFile(true, InFile, "bc"); case Backend_EmitNothing: return nullptr; case Backend_EmitMCNull: return CI.createNullOutputFile(); case Backend_EmitObj: return CI.createDefaultOutputFile(true, InFile, "o"); } llvm_unreachable("Invalid action!"); }
std::unique_ptr<ASTConsumer> RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { if (std::unique_ptr<raw_ostream> OS = CI.createDefaultOutputFile(false, InFile, "cpp")) { if (CI.getLangOpts().ObjCRuntime.isNonFragile()) return CreateModernObjCRewriter( InFile, std::move(OS), CI.getDiagnostics(), CI.getLangOpts(), CI.getDiagnosticOpts().NoRewriteMacros, (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo)); return CreateObjCRewriter(InFile, std::move(OS), CI.getDiagnostics(), CI.getLangOpts(), CI.getDiagnosticOpts().NoRewriteMacros); } return nullptr; }
bool GeneratePCHAction::ComputeASTConsumerArguments(CompilerInstance &CI, llvm::StringRef InFile, std::string &Sysroot, llvm::raw_ostream *&OS, bool &Chaining) { Sysroot = CI.getHeaderSearchOpts().Sysroot; if (CI.getFrontendOpts().RelocatablePCH && Sysroot.empty()) { CI.getDiagnostics().Report(diag::err_relocatable_without_without_isysroot); return true; } OS = CI.createDefaultOutputFile(true, InFile); if (!OS) return true; Chaining = CI.getInvocation().getFrontendOpts().ChainedPCH && !CI.getPreprocessorOpts().ImplicitPCHInclude.empty(); return false; }
std::unique_ptr<raw_pwrite_stream> GenerateHeaderModuleAction::CreateOutputFile(CompilerInstance &CI, StringRef InFile) { return CI.createDefaultOutputFile(/*Binary=*/true, InFile, "pcm"); }