From: Adrian Prantl Date: Tue, 22 Sep 2015 23:26:31 +0000 (+0000) Subject: Serialization: Let ASTWriter return the signature of the written module. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6a9f31e5e3de8998ad3f75d946e163976933114a;p=clang Serialization: Let ASTWriter return the signature of the written module. NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248344 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index d505bee6b0..700f44cd61 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -505,10 +505,9 @@ private: llvm::DenseSet &ParentStmts); void WriteBlockInfoBlock(); - void WriteControlBlock(Preprocessor &PP, ASTContext &Context, - StringRef isysroot, const std::string &OutputFile); - void WriteInputFiles(SourceManager &SourceMgr, - HeaderSearchOptions &HSOpts, + uint64_t WriteControlBlock(Preprocessor &PP, ASTContext &Context, + StringRef isysroot, const std::string &OutputFile); + void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts, bool Modules); void WriteSourceManagerBlock(SourceManager &SourceMgr, const Preprocessor &PP); @@ -572,9 +571,9 @@ private: void WriteDecl(ASTContext &Context, Decl *D); void AddFunctionDefinition(const FunctionDecl *FD, RecordData &Record); - void WriteASTCore(Sema &SemaRef, - StringRef isysroot, const std::string &OutputFile, - Module *WritingModule); + uint64_t WriteASTCore(Sema &SemaRef, + StringRef isysroot, const std::string &OutputFile, + Module *WritingModule); public: /// \brief Create a new precompiled header writer that outputs to @@ -600,10 +599,12 @@ public: /// \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 /// build directory will be used in preference to this if both are available. - void WriteAST(Sema &SemaRef, - const std::string &OutputFile, - Module *WritingModule, StringRef isysroot, - bool hasErrors = false); + /// + /// \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, + bool hasErrors = false); /// \brief Emit a token. void AddToken(const Token &Tok, RecordDataImpl &Record); diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index b582c3239d..95c1620fcb 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1166,9 +1166,12 @@ static ASTFileSignature getSignature() { } /// \brief Write the control block. -void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, - StringRef isysroot, - const std::string &OutputFile) { +uint64_t ASTWriter::WriteControlBlock(Preprocessor &PP, + ASTContext &Context, + StringRef isysroot, + const std::string &OutputFile) { + ASTFileSignature Signature = 0; + using namespace llvm; Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); RecordData Record; @@ -1201,7 +1204,8 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, // is non-deterministic. // FIXME: Remove this when output is deterministic. if (Context.getLangOpts().ImplicitModules) { - RecordData::value_type Record[] = {getSignature()}; + Signature = getSignature(); + RecordData::value_type Record[] = {Signature}; Stream.EmitRecord(SIGNATURE, Record); } @@ -1468,6 +1472,7 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, PP.getHeaderSearchInfo().getHeaderSearchOpts(), PP.getLangOpts().Modules); Stream.ExitBlock(); + return Signature; } namespace { @@ -4012,12 +4017,11 @@ time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { return IncludeTimestamps ? E->getModificationTime() : 0; } -void ASTWriter::WriteAST(Sema &SemaRef, - const std::string &OutputFile, - Module *WritingModule, StringRef isysroot, - bool hasErrors) { +uint64_t ASTWriter::WriteAST(Sema &SemaRef, const std::string &OutputFile, + Module *WritingModule, StringRef isysroot, + bool hasErrors) { WritingAST = true; - + ASTHasCompilerErrors = hasErrors; // Emit the file header. @@ -4031,13 +4035,15 @@ void ASTWriter::WriteAST(Sema &SemaRef, Context = &SemaRef.Context; PP = &SemaRef.PP; this->WritingModule = WritingModule; - WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); + ASTFileSignature Signature = + WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); Context = nullptr; PP = nullptr; this->WritingModule = nullptr; this->BaseDirectory.clear(); WritingAST = false; + return Signature; } template @@ -4049,10 +4055,9 @@ static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, } } -void ASTWriter::WriteASTCore(Sema &SemaRef, - StringRef isysroot, - const std::string &OutputFile, - Module *WritingModule) { +uint64_t ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, + const std::string &OutputFile, + Module *WritingModule) { using namespace llvm; bool isModule = WritingModule != nullptr; @@ -4197,7 +4202,7 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, } // Write the control block - WriteControlBlock(PP, Context, isysroot, OutputFile); + uint64_t Signature = WriteControlBlock(PP, Context, isysroot, OutputFile); // Write the remaining AST contents. Stream.EnterSubblock(AST_BLOCK_ID, 5); @@ -4527,6 +4532,8 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts}; Stream.EmitRecord(STATISTICS, Record); Stream.ExitBlock(); + + return Signature; } void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) {