diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2010-07-14 23:45:08 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2010-07-14 23:45:08 +0000 |
commit | 30c514c225342844700ed4640ec6d90ddf0e12b2 (patch) | |
tree | 8f0ef19b1f52439d2b379642ed858f3e94eedea3 /lib/Frontend/GeneratePCH.cpp | |
parent | dacf9dda17346c628fdd8c5df53c681738db0dc5 (diff) |
Add a callback interface that allows interested parties to get notified whenever PCHReader deserializes a type or decl (and possibly other things in the future). Have PCHWriter implement these callbacks as noops and register to receive them if we're chaining PCHs. This will allow PCHWriter to track the IDs of these things, which it needs to write the dependent files. WIP
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108383 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/GeneratePCH.cpp')
-rw-r--r-- | lib/Frontend/GeneratePCH.cpp | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/lib/Frontend/GeneratePCH.cpp b/lib/Frontend/GeneratePCH.cpp index 9be103e06e..2f3df9479d 100644 --- a/lib/Frontend/GeneratePCH.cpp +++ b/lib/Frontend/GeneratePCH.cpp @@ -28,28 +28,28 @@ using namespace clang; namespace { class PCHGenerator : public SemaConsumer { const Preprocessor &PP; - const PCHReader *Chain; const char *isysroot; llvm::raw_ostream *Out; Sema *SemaPtr; MemorizeStatCalls *StatCalls; // owned by the FileManager + std::vector<unsigned char> Buffer; + llvm::BitstreamWriter Stream; + PCHWriter Writer; public: - explicit PCHGenerator(const Preprocessor &PP, - const PCHReader *Chain, - const char *isysroot, - llvm::raw_ostream *Out); + PCHGenerator(const Preprocessor &PP, PCHReader *Chain, + const char *isysroot, llvm::raw_ostream *Out); virtual void InitializeSema(Sema &S) { SemaPtr = &S; } virtual void HandleTranslationUnit(ASTContext &Ctx); }; } PCHGenerator::PCHGenerator(const Preprocessor &PP, - const PCHReader *Chain, + PCHReader *Chain, const char *isysroot, llvm::raw_ostream *OS) - : PP(PP), Chain(Chain), isysroot(isysroot), Out(OS), SemaPtr(0), - StatCalls(0) { + : PP(PP), isysroot(isysroot), Out(OS), SemaPtr(0), StatCalls(0), + Stream(Buffer), Writer(Stream, Chain) { // Install a stat() listener to keep track of all of the stat() // calls. @@ -61,25 +61,23 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) { if (PP.getDiagnostics().hasErrorOccurred()) return; - // Write the PCH contents into a buffer - std::vector<unsigned char> Buffer; - llvm::BitstreamWriter Stream(Buffer); - PCHWriter Writer(Stream); - // Emit the PCH file assert(SemaPtr && "No Sema?"); - Writer.WritePCH(*SemaPtr, StatCalls, Chain, isysroot); + Writer.WritePCH(*SemaPtr, StatCalls, isysroot); // Write the generated bitstream to "Out". Out->write((char *)&Buffer.front(), Buffer.size()); // Make sure it hits disk now. Out->flush(); + + // Free up some memory, in case the process is kept alive. + Buffer.clear(); } ASTConsumer *clang::CreatePCHGenerator(const Preprocessor &PP, llvm::raw_ostream *OS, - const PCHReader *Chain, + PCHReader *Chain, const char *isysroot) { return new PCHGenerator(PP, Chain, isysroot, OS); } |