Use a little binary header in serialized diagnostics to help the deserializer skip over noise in the stream

llvm-svn: 96641
This commit is contained in:
Douglas Gregor 2010-02-19 00:40:40 +00:00
parent d2d9252f35
commit 70127c1dcf
1 changed files with 26 additions and 3 deletions

View File

@ -978,6 +978,9 @@ void StoredDiagnostic::Serialize(llvm::raw_ostream &OS) const {
if (getLocation().isValid())
SM = &const_cast<SourceManager &>(getLocation().getManager());
// Write a short header to help identify diagnostics.
OS << (char)0x06 << (char)0x07;
// Write the diagnostic level and location.
WriteUnsigned(OS, (unsigned)Level);
WriteSourceLocation(OS, SM, getLocation());
@ -1086,8 +1089,28 @@ static bool ReadSourceLocation(FileManager &FM, SourceManager &SM,
StoredDiagnostic
StoredDiagnostic::Deserialize(FileManager &FM, SourceManager &SM,
const char *&Memory, const char *MemoryEnd) {
if (Memory == MemoryEnd)
return StoredDiagnostic();
while (true) {
if (Memory == MemoryEnd)
return StoredDiagnostic();
if (*Memory != 0x06) {
++Memory;
continue;
}
++Memory;
if (Memory == MemoryEnd)
return StoredDiagnostic();
if (*Memory != 0x07) {
++Memory;
continue;
}
// We found the header. We're done.
++Memory;
break;
}
// Read the severity level.
unsigned Level = 0;