From c638952f596846c2fb99789f26e666b8b28da126 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 4 Dec 2007 19:39:02 +0000 Subject: [PATCH] Implemented serialization of SrcMgr::ContentCache. llvm-svn: 44578 --- clang/Basic/SourceManager.cpp | 54 +++++++++++++++++++++++ clang/include/clang/Basic/SourceManager.h | 8 ++++ 2 files changed, 62 insertions(+) diff --git a/clang/Basic/SourceManager.cpp b/clang/Basic/SourceManager.cpp index 03fa203b2e5e..0b3af9853fbb 100644 --- a/clang/Basic/SourceManager.cpp +++ b/clang/Basic/SourceManager.cpp @@ -406,3 +406,57 @@ void SourceManager::PrintStats() const { std::cerr << NumFileBytesMapped << " bytes of files mapped, " << NumLineNumsComputed << " files with line #'s computed.\n"; } + +//===----------------------------------------------------------------------===// +// Serialization. +//===----------------------------------------------------------------------===// + +void SrcMgr::ContentCache::Emit(llvm::Serializer& S, + bool StoreBufferName, + bool StoreBufferContents) const { + S.FlushRecord(); + S.EmitPtr(this); + + if (StoreBufferName) + S.EmitCStr(Buffer->getBufferIdentifier()); + + if (StoreBufferContents) { + // Emit the contents of the memory buffer. + // FIXME: use abbreviations to optimize this. + S.FlushRecord(); + + const char* p = Buffer->getBufferStart(); + const char* e = Buffer->getBufferEnd(); + + S.EmitInt(p-e); + + for ( ; p != e; ++p) + S.EmitInt(*p); + + S.FlushRecord(); + } +} + +void SrcMgr::ContentCache::Read(llvm::Deserializer& D, + std::vector* BufferNameBuf, + bool ReadBufferContents) { + D.RegisterPtr(this); + const char* BufferName = ""; + + if (BufferNameBuf) { + D.ReadCStr(*BufferNameBuf); + BufferName = &(*BufferNameBuf)[0]; + } + + if (ReadBufferContents) { + char *BufferName = D.ReadCStr(); + unsigned Size = D.ReadInt(); + Buffer = MemoryBuffer::getNewUninitMemBuffer(Size,BufferName); + char* p = const_cast(Buffer->getBufferStart()); + const char* e = Buffer->getBufferEnd(); + for ( ; p != e ; ++p ) + *p = (char) D.ReadInt(); + } + else + Buffer = MemoryBuffer::getNewUninitMemBuffer(0,BufferName); +} diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 6798a21200c9..e019f0ecf49b 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -71,6 +71,14 @@ namespace SrcMgr { NumLines = RHS.NumLines; } + /// Emit - Emit this ContentCache to Bitcode. + void Emit(llvm::Serializer& S, bool StoreBufferName, + bool StoreBufferContents) const; + + /// Read - Reconstitute a ContentCache from Bitcode. + void Read(llvm::Deserializer& D, std::vector* BufferNameBuf, + bool ReadBufferContents); + private: // Disable assignments. ContentCache& operator=(const ContentCache& RHS);