[cfe-commits] r44578 - in /cfe/trunk: Basic/SourceManager.cpp include/clang/Basic/SourceManager.h
Ted Kremenek
kremenek at apple.com
Tue Dec 4 11:39:03 PST 2007
Author: kremenek
Date: Tue Dec 4 13:39:02 2007
New Revision: 44578
URL: http://llvm.org/viewvc/llvm-project?rev=44578&view=rev
Log:
Implemented serialization of SrcMgr::ContentCache.
Modified:
cfe/trunk/Basic/SourceManager.cpp
cfe/trunk/include/clang/Basic/SourceManager.h
Modified: cfe/trunk/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Basic/SourceManager.cpp?rev=44578&r1=44577&r2=44578&view=diff
==============================================================================
--- cfe/trunk/Basic/SourceManager.cpp (original)
+++ cfe/trunk/Basic/SourceManager.cpp Tue Dec 4 13:39:02 2007
@@ -406,3 +406,57 @@
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<char>* 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<char*>(Buffer->getBufferStart());
+ const char* e = Buffer->getBufferEnd();
+ for ( ; p != e ; ++p )
+ *p = (char) D.ReadInt();
+ }
+ else
+ Buffer = MemoryBuffer::getNewUninitMemBuffer(0,BufferName);
+}
Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=44578&r1=44577&r2=44578&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Dec 4 13:39:02 2007
@@ -71,6 +71,14 @@
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<char>* BufferNameBuf,
+ bool ReadBufferContents);
+
private:
// Disable assignments.
ContentCache& operator=(const ContentCache& RHS);
More information about the cfe-commits
mailing list