зеркало из https://github.com/microsoft/clang-1.git
Modifed the test serialization driver to...
(1) serialize out top-level decls BEFORE serializing out translation unit structures like ASTContext. (2) deserialize out translation unit structures like ASTContext before top-level decls by first skipping the decls in the bitstream, deserializing ASTContext and friends, and then jumping back to the bitstream block with the decls and then deserializing them. Change (1) allows us to utilize the pointer-tracking system in the Serializer to only serialize out metadata that is actually referenced by the ASTS. Change (2) allows us to deserialize the metadata first as before, which signficantly reduces the amount of pointer backpatching the deserializer would have to do if the decls were deserialized first. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43974 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
18807d2bfb
Коммит
7a1f4dbb9c
|
@ -101,6 +101,19 @@ void SerializationTest::Serialize(llvm::sys::Path& Filename) {
|
|||
// Create serializer.
|
||||
llvm::Serializer Sezr(Stream);
|
||||
|
||||
// ===---------------------------------------------------===/
|
||||
// Serialize the top-level decls.
|
||||
// ===---------------------------------------------------===/
|
||||
|
||||
Sezr.EnterBlock(DeclBlock);
|
||||
|
||||
for (std::list<Decl*>::iterator I=Decls.begin(), E=Decls.end(); I!=E; ++I) {
|
||||
llvm::cerr << "Serializing: Decl.\n";
|
||||
Sezr.EmitOwnedPtr(*I);
|
||||
}
|
||||
|
||||
Sezr.ExitBlock();
|
||||
|
||||
// ===---------------------------------------------------===/
|
||||
// Serialize the "Translation Unit" metadata.
|
||||
// ===---------------------------------------------------===/
|
||||
|
@ -129,19 +142,6 @@ void SerializationTest::Serialize(llvm::sys::Path& Filename) {
|
|||
|
||||
Sezr.ExitBlock();
|
||||
|
||||
// ===---------------------------------------------------===/
|
||||
// Serialize the top-level decls.
|
||||
// ===---------------------------------------------------===/
|
||||
|
||||
Sezr.EnterBlock(DeclBlock);
|
||||
|
||||
for (std::list<Decl*>::iterator I=Decls.begin(), E=Decls.end(); I!=E; ++I) {
|
||||
llvm::cerr << "Serializing: Decl.\n";
|
||||
Sezr.EmitOwnedPtr(*I);
|
||||
}
|
||||
|
||||
Sezr.ExitBlock();
|
||||
|
||||
// ===---------------------------------------------------===/
|
||||
// Finalize serialization: write the bits to disk.
|
||||
// ===---------------------------------------------------===/
|
||||
|
@ -191,15 +191,19 @@ void SerializationTest::Deserialize(llvm::sys::Path& Filename) {
|
|||
if (ReadPreamble(Stream)) {
|
||||
llvm::cerr << "ERROR: Invalid AST-bitcode signature.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the Dezr.
|
||||
}
|
||||
|
||||
// Create the deserializer.
|
||||
llvm::Deserializer Dezr(Stream);
|
||||
|
||||
// ===---------------------------------------------------===/
|
||||
// Deserialize the "Translation Unit" metadata.
|
||||
// ===---------------------------------------------------===/
|
||||
|
||||
// Skip to the block that has the SourceManager, etc.
|
||||
bool FoundBlock = Dezr.SkipToBlock(ContextBlock);
|
||||
assert (FoundBlock);
|
||||
|
||||
// "Fake" read the SourceManager.
|
||||
llvm::cerr << "Faux-Deserializing: SourceManager.\n";
|
||||
Dezr.RegisterPtr(&Context->SourceMgr);
|
||||
|
@ -224,8 +228,14 @@ void SerializationTest::Deserialize(llvm::sys::Path& Filename) {
|
|||
ASTConsumer* Printer = CreateASTPrinter();
|
||||
Janitor<ASTConsumer> PrinterJanitor(Printer);
|
||||
|
||||
// "Rewind" the stream. Find the block with the serialized top-level decls.
|
||||
Dezr.Rewind();
|
||||
FoundBlock = Dezr.SkipToBlock(DeclBlock);
|
||||
assert (FoundBlock);
|
||||
llvm::Deserializer::Location DeclBlockLoc = Dezr.getCurrentBlockLocation();
|
||||
|
||||
// The remaining objects in the file are top-level decls.
|
||||
while (!Dezr.AtEnd()) {
|
||||
while (!Dezr.FinishedBlock(DeclBlockLoc)) {
|
||||
llvm::cerr << "Deserializing: Decl.\n";
|
||||
Decl* decl = Dezr.ReadOwnedPtr<Decl>();
|
||||
Printer->HandleTopLevelDecl(decl);
|
||||
|
|
Загрузка…
Ссылка в новой задаче