Skip to content

[clang][serialization] Enable ASTWriter to work with Preprocessor only #115237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions clang/include/clang/Serialization/ASTWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ class ASTWriter : public ASTDeserializationListener,
void WriteHeaderSearch(const HeaderSearch &HS);
void WritePreprocessorDetail(PreprocessingRecord &PPRec,
uint64_t MacroOffsetsBase);
void WriteSubmodules(Module *WritingModule, ASTContext &Context);
void WriteSubmodules(Module *WritingModule, ASTContext *Context);

void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
bool isModule);
Expand All @@ -582,7 +582,7 @@ class ASTWriter : public ASTDeserializationListener,
void WriteComments(ASTContext &Context);
void WriteSelectors(Sema &SemaRef);
void WriteReferencedSelectorsPool(Sema &SemaRef);
void WriteIdentifierTable(Preprocessor &PP, IdentifierResolver &IdResolver,
void WriteIdentifierTable(Preprocessor &PP, IdentifierResolver *IdResolver,
bool IsModule);
void WriteDeclAndTypes(ASTContext &Context);
void PrepareWritingSpecialDecls(Sema &SemaRef);
Expand Down Expand Up @@ -639,7 +639,7 @@ class ASTWriter : public ASTDeserializationListener,
void WriteDeclAbbrevs();
void WriteDecl(ASTContext &Context, Decl *D);

ASTFileSignature WriteASTCore(Sema &SemaRef, StringRef isysroot,
ASTFileSignature WriteASTCore(Sema *SemaPtr, StringRef isysroot,
Module *WritingModule);

public:
Expand All @@ -659,10 +659,13 @@ class ASTWriter : public ASTDeserializationListener,
/// include timestamps in the output file.
time_t getTimestampForOutput(const FileEntry *E) const;

/// Write a precompiled header for the given semantic analysis.
/// Write a precompiled header or a module with the AST produced by the
/// \c Sema object, or a dependency scanner module with the preprocessor state
/// produced by the \c Preprocessor object.
///
/// \param SemaRef a reference to the semantic analysis object that processed
/// the AST to be written into the precompiled header.
/// \param Subject The \c Sema object that processed the AST to be written, or
/// in the case of a dependency scanner module the \c Preprocessor that holds
/// the state.
///
/// \param WritingModule The module that we are writing. If null, we are
/// writing a precompiled header.
Expand All @@ -673,8 +676,9 @@ class ASTWriter : public ASTDeserializationListener,
///
/// \return the module signature, which eventually will be a hash of
/// the module but currently is merely a random 32-bit number.
ASTFileSignature WriteAST(Sema &SemaRef, StringRef OutputFile,
Module *WritingModule, StringRef isysroot,
ASTFileSignature WriteAST(llvm::PointerUnion<Sema *, Preprocessor *> Subject,
StringRef OutputFile, Module *WritingModule,
StringRef isysroot,
bool ShouldCacheASTInMemory = false);

/// Emit a token.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/ASTUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2359,7 +2359,7 @@ bool ASTUnit::Save(StringRef File) {

static bool serializeUnit(ASTWriter &Writer, SmallVectorImpl<char> &Buffer,
Sema &S, raw_ostream &OS) {
Writer.WriteAST(S, std::string(), nullptr, "");
Writer.WriteAST(&S, std::string(), nullptr, "");

// Write the generated bitstream to "Out".
if (!Buffer.empty())
Expand Down
Loading
Loading