clang: lib/Serialization/GeneratePCH.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
21#include "llvm/Bitstream/BitstreamWriter.h"
22
23using namespace clang;
24
27 StringRef isysroot, std::shared_ptr Buffer,
28 ArrayRef<std::shared_ptr> Extensions,
29 bool AllowASTWithErrors, bool IncludeTimestamps,
30 bool BuildingImplicitModule, bool ShouldCacheASTInMemory,
31 bool GeneratingReducedBMI)
32 : PP(PP), Subject(&PP), OutputFile(OutputFile), isysroot(isysroot.str()),
33 Buffer(std::move(Buffer)), Stream(this->Buffer->Data),
34 Writer(Stream, this->Buffer->Data, ModuleCache, Extensions,
35 IncludeTimestamps, BuildingImplicitModule, GeneratingReducedBMI),
36 AllowASTWithErrors(AllowASTWithErrors),
37 ShouldCacheASTInMemory(ShouldCacheASTInMemory) {
38 this->Buffer->IsComplete = false;
39}
40
42}
43
46
50 false);
51 if (!M)
53 "emitting module but current module doesn't exist");
54 }
55
56 return M;
57}
58
61}
62
67 Subject = &S;
68}
69
71
73 return;
74
76 if (hasErrors && !AllowASTWithErrors)
77 return;
78
80
81
82
83 if (AllowASTWithErrors)
85
86 Buffer->Signature = Writer.WriteAST(Subject, OutputFile, Module, isysroot,
87 ShouldCacheASTInMemory);
88
89 Buffer->IsComplete = true;
90}
91
93 return &Writer;
94}
95
97 return &Writer;
98}
99
100void PCHGenerator::anchor() {}
101
104 StringRef OutputFile,
105 bool GeneratingReducedBMI,
106 bool AllowASTWithErrors)
108 PP, ModuleCache, OutputFile, llvm::StringRef(),
111 AllowASTWithErrors, false,
113 GeneratingReducedBMI) {}
114
118 "CXX20ModulesGenerator should only be used with C++20 Named modules.");
119 return M;
120}
121
123
124
129
131
133 return;
134
135 std::error_code EC;
136 auto OS = std::make_uniquellvm::raw\_fd\_ostream(getOutputFile(), EC);
137 if (EC) {
140 return;
141 }
142
144 OS->flush();
145}
146
147void CXX20ModulesGenerator::anchor() {}
148
149void 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...
ASTFileSignature WriteAST(llvm::PointerUnion< Sema *, Preprocessor * > Subject, StringRef OutputFile, Module *WritingModule, StringRef isysroot, bool ShouldCacheASTInMemory=false)
Write a precompiled header or a module with the AST produced by the Sema object, or a dependency scan...
CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache, StringRef OutputFile, 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
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
DiagnosticConsumer * getClient()
In-memory cache for modules.
bool isCompilingModule() const
Are we compiling a module?
std::string CurrentModule
The name of the current module, of which the main source file is a part.
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.
AST and semantic-analysis consumer that generates a precompiled header from the parsed source code.
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()
Preprocessor & getPreprocessor()
virtual Module * getEmittingModule(ASTContext &Ctx)
StringRef getOutputFile() const
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...
PCHGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache, StringRef OutputFile, StringRef isysroot, std::shared_ptr< PCHBuffer > Buffer, ArrayRef< std::shared_ptr< ModuleFileExtension > > Extensions, bool AllowASTWithErrors=false, bool IncludeTimestamps=true, bool BuildingImplicitModule=false, bool ShouldCacheASTInMemory=false, bool GeneratingReducedBMI=false)
DiagnosticsEngine & getDiagnostics() const
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
ModuleLoader & getModuleLoader() const
Retrieve the module loader associated with this preprocessor.
HeaderSearch & getHeaderSearchInfo() const
const LangOptions & getLangOpts() const
DiagnosticsEngine & getDiagnostics() const
Sema - This implements semantic analysis and AST building for C.
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