Serialization: Let ASTWriter return the signature of the written module.

NFC

llvm-svn: 248344
This commit is contained in:
Adrian Prantl 2015-09-22 23:26:31 +00:00
parent 040975472c
commit adbd2b1f32
2 changed files with 34 additions and 26 deletions

View File

@ -505,10 +505,9 @@ private:
llvm::DenseSet<Stmt *> &ParentStmts); llvm::DenseSet<Stmt *> &ParentStmts);
void WriteBlockInfoBlock(); void WriteBlockInfoBlock();
void WriteControlBlock(Preprocessor &PP, ASTContext &Context, uint64_t WriteControlBlock(Preprocessor &PP, ASTContext &Context,
StringRef isysroot, const std::string &OutputFile); StringRef isysroot, const std::string &OutputFile);
void WriteInputFiles(SourceManager &SourceMgr, void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts,
HeaderSearchOptions &HSOpts,
bool Modules); bool Modules);
void WriteSourceManagerBlock(SourceManager &SourceMgr, void WriteSourceManagerBlock(SourceManager &SourceMgr,
const Preprocessor &PP); const Preprocessor &PP);
@ -572,7 +571,7 @@ private:
void WriteDecl(ASTContext &Context, Decl *D); void WriteDecl(ASTContext &Context, Decl *D);
void AddFunctionDefinition(const FunctionDecl *FD, RecordData &Record); void AddFunctionDefinition(const FunctionDecl *FD, RecordData &Record);
void WriteASTCore(Sema &SemaRef, uint64_t WriteASTCore(Sema &SemaRef,
StringRef isysroot, const std::string &OutputFile, StringRef isysroot, const std::string &OutputFile,
Module *WritingModule); Module *WritingModule);
@ -600,8 +599,10 @@ public:
/// \param isysroot if non-empty, write a relocatable file whose headers /// \param isysroot if non-empty, write a relocatable file whose headers
/// are relative to the given system root. If we're writing a module, its /// are relative to the given system root. If we're writing a module, its
/// build directory will be used in preference to this if both are available. /// build directory will be used in preference to this if both are available.
void WriteAST(Sema &SemaRef, ///
const std::string &OutputFile, /// \return the module signature, which eventually will be a hash of
/// the module but currently is merely a random 32-bit number.
uint64_t WriteAST(Sema &SemaRef, const std::string &OutputFile,
Module *WritingModule, StringRef isysroot, Module *WritingModule, StringRef isysroot,
bool hasErrors = false); bool hasErrors = false);

View File

@ -1166,9 +1166,12 @@ static ASTFileSignature getSignature() {
} }
/// \brief Write the control block. /// \brief Write the control block.
void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, uint64_t ASTWriter::WriteControlBlock(Preprocessor &PP,
ASTContext &Context,
StringRef isysroot, StringRef isysroot,
const std::string &OutputFile) { const std::string &OutputFile) {
ASTFileSignature Signature = 0;
using namespace llvm; using namespace llvm;
Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); Stream.EnterSubblock(CONTROL_BLOCK_ID, 5);
RecordData Record; RecordData Record;
@ -1201,7 +1204,8 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
// is non-deterministic. // is non-deterministic.
// FIXME: Remove this when output is deterministic. // FIXME: Remove this when output is deterministic.
if (Context.getLangOpts().ImplicitModules) { if (Context.getLangOpts().ImplicitModules) {
RecordData::value_type Record[] = {getSignature()}; Signature = getSignature();
RecordData::value_type Record[] = {Signature};
Stream.EmitRecord(SIGNATURE, Record); Stream.EmitRecord(SIGNATURE, Record);
} }
@ -1468,6 +1472,7 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
PP.getHeaderSearchInfo().getHeaderSearchOpts(), PP.getHeaderSearchInfo().getHeaderSearchOpts(),
PP.getLangOpts().Modules); PP.getLangOpts().Modules);
Stream.ExitBlock(); Stream.ExitBlock();
return Signature;
} }
namespace { namespace {
@ -4012,8 +4017,7 @@ time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const {
return IncludeTimestamps ? E->getModificationTime() : 0; return IncludeTimestamps ? E->getModificationTime() : 0;
} }
void ASTWriter::WriteAST(Sema &SemaRef, uint64_t ASTWriter::WriteAST(Sema &SemaRef, const std::string &OutputFile,
const std::string &OutputFile,
Module *WritingModule, StringRef isysroot, Module *WritingModule, StringRef isysroot,
bool hasErrors) { bool hasErrors) {
WritingAST = true; WritingAST = true;
@ -4031,6 +4035,7 @@ void ASTWriter::WriteAST(Sema &SemaRef,
Context = &SemaRef.Context; Context = &SemaRef.Context;
PP = &SemaRef.PP; PP = &SemaRef.PP;
this->WritingModule = WritingModule; this->WritingModule = WritingModule;
ASTFileSignature Signature =
WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule);
Context = nullptr; Context = nullptr;
PP = nullptr; PP = nullptr;
@ -4038,6 +4043,7 @@ void ASTWriter::WriteAST(Sema &SemaRef,
this->BaseDirectory.clear(); this->BaseDirectory.clear();
WritingAST = false; WritingAST = false;
return Signature;
} }
template<typename Vector> template<typename Vector>
@ -4049,8 +4055,7 @@ static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec,
} }
} }
void ASTWriter::WriteASTCore(Sema &SemaRef, uint64_t ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
StringRef isysroot,
const std::string &OutputFile, const std::string &OutputFile,
Module *WritingModule) { Module *WritingModule) {
using namespace llvm; using namespace llvm;
@ -4197,7 +4202,7 @@ void ASTWriter::WriteASTCore(Sema &SemaRef,
} }
// Write the control block // Write the control block
WriteControlBlock(PP, Context, isysroot, OutputFile); uint64_t Signature = WriteControlBlock(PP, Context, isysroot, OutputFile);
// Write the remaining AST contents. // Write the remaining AST contents.
Stream.EnterSubblock(AST_BLOCK_ID, 5); Stream.EnterSubblock(AST_BLOCK_ID, 5);
@ -4527,6 +4532,8 @@ void ASTWriter::WriteASTCore(Sema &SemaRef,
NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts}; NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts};
Stream.EmitRecord(STATISTICS, Record); Stream.EmitRecord(STATISTICS, Record);
Stream.ExitBlock(); Stream.ExitBlock();
return Signature;
} }
void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) {