21#include "llvm/Bitstream/BitstreamWriter.h"
27 StringRef isysroot, std::shared_ptr<PCHBuffer> Buffer,
29 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
30 bool AllowASTWithErrors,
bool IncludeTimestamps,
31 bool BuildingImplicitModule,
bool ShouldCacheASTInMemory,
32 bool GeneratingReducedBMI)
33 : PP(PP), Subject(&PP), OutputFile(OutputFile), isysroot(isysroot.str()),
34 Buffer(
std::move(Buffer)), Stream(this->Buffer->
Data),
35 Writer(Stream, this->Buffer->
Data, ModCache, CodeGenOpts, Extensions,
36 IncludeTimestamps, BuildingImplicitModule, GeneratingReducedBMI),
37 AllowASTWithErrors(AllowASTWithErrors),
38 ShouldCacheASTInMemory(ShouldCacheASTInMemory) {
39 this->Buffer->IsComplete =
false;
48 if (PP.getLangOpts().isCompilingModule()) {
49 M = PP.getHeaderSearchInfo().lookupModule(PP.getLangOpts().CurrentModule,
53 assert(PP.getDiagnostics().hasErrorOccurred() &&
54 "emitting module but current module doesn't exist");
61 return PP.getDiagnostics();
65 if (!PP.getHeaderSearchInfo()
66 .getHeaderSearchOpts()
67 .ModulesSerializeOnlyPreprocessor)
73 if (PP.getModuleLoader().HadFatalFailure)
77 if (hasErrors && !AllowASTWithErrors)
84 if (AllowASTWithErrors)
85 PP.getDiagnostics().getClient()->clear();
87 Buffer->Signature = Writer.WriteAST(Subject, OutputFile,
Module, isysroot,
88 ShouldCacheASTInMemory);
90 Buffer->IsComplete =
true;
101void PCHGenerator::anchor() {}
105 StringRef OutputFile,
107 bool GeneratingReducedBMI,
108 bool AllowASTWithErrors)
110 PP, ModCache, OutputFile,
llvm::StringRef(),
113 AllowASTWithErrors,
false,
115 GeneratingReducedBMI) {}
120 "CXX20ModulesGenerator should only be used with C++20 Named modules.");
131 auto OS = std::make_unique<llvm::raw_fd_ostream>(
getOutputFile(), EC);
142void CXX20ModulesGenerator::anchor() {}
144void ReducedBMIGenerator::anchor() {}
Defines the clang::ASTContext interface.
Defines the clang::Preprocessor interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Module * getCurrentNamedModule() const
Get module under construction, nullptr if this is not a C++20 module.
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
CXX20ModulesGenerator(Preprocessor &PP, ModuleCache &ModCache, StringRef OutputFile, const CodeGenOptions &CodeGenOpts, bool GeneratingReducedBMI, bool AllowASTWithErrors)
void HandleTranslationUnit(ASTContext &Ctx) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
virtual Module * getEmittingModule(ASTContext &Ctx) override
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
bool hasErrorOccurred() const
The module cache used for compiling modules implicitly.
An abstract superclass that describes a custom extension to the module/precompiled header file format...
Describes a module or submodule.
bool isNamedModuleUnit() const
Is this a C++20 named module unit.
ASTMutationListener * GetASTMutationListener() override
If the consumer is interested in entities getting modified after their initial creation,...
void InitializeSema(Sema &S) override
Initialize the semantic consumer with the Sema instance being used to perform semantic analysis on th...
PCHBuffer * getBufferPtr()
virtual Module * getEmittingModule(ASTContext &Ctx)
StringRef getOutputFile() const
PCHGenerator(Preprocessor &PP, ModuleCache &ModCache, StringRef OutputFile, StringRef isysroot, std::shared_ptr< PCHBuffer > Buffer, const CodeGenOptions &CodeGenOpts, ArrayRef< std::shared_ptr< ModuleFileExtension > > Extensions, bool AllowASTWithErrors=false, bool IncludeTimestamps=true, bool BuildingImplicitModule=false, bool ShouldCacheASTInMemory=false, bool GeneratingReducedBMI=false)
ASTDeserializationListener * GetASTDeserializationListener() override
If the consumer is interested in entities being deserialized from AST files, it should return a point...
void HandleTranslationUnit(ASTContext &Ctx) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
DiagnosticsEngine & getDiagnostics() const
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Sema - This implements semantic analysis and AST building for C.
DiagnosticsEngine & getDiagnostics() const
Encodes a location in the source.
The JSON file list parser is used to communicate input to InstallAPI.
Diagnostic wrappers for TextAPI types for error reporting.
llvm::SmallVector< char, 0 > Data