void *Stored;
bool IsType;
};
-
+
/// \brief The declarations and types to emit.
std::queue<DeclOrType> DeclTypesToEmit;
-
+
+ /// \brief The first ID number we can use for our own declarations.
+ pch::DeclID FirstDeclID;
+
/// \brief Map that provides the ID numbers of each declaration within
- /// the output stream.
+ /// the output stream, as well as those deserialized from a chained PCH.
///
/// The ID numbers of declarations are consecutive (in order of
/// discovery) and start at 2. 1 is reserved for the translation
/// the declaration's ID.
std::vector<uint32_t> DeclOffsets;
+ /// \brief The first ID number we can use for our own types.
+ pch::TypeID FirstTypeID;
+
/// \brief Map that provides the ID numbers of each type within the
- /// output stream.
+ /// output stream, plus those deserialized from a chained PCH.
///
/// The ID numbers of types are consecutive (in order of discovery)
/// and start at 1. 0 is reserved for NULL. When types are actually
void WriteType(QualType T);
uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC);
-
+ void WriteTypeDeclOffsets();
void WriteMethodPool(Sema &SemaRef);
void WriteIdentifierTable(Preprocessor &PP);
void WriteAttributeRecord(const Attr *Attr);
return Offset;
}
+void PCHWriter::WriteTypeDeclOffsets() {
+ using namespace llvm;
+ RecordData Record;
+
+ // Write the type offsets array
+ BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
+ Abbrev->Add(BitCodeAbbrevOp(pch::TYPE_OFFSET));
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block
+ unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev);
+ Record.clear();
+ Record.push_back(pch::TYPE_OFFSET);
+ Record.push_back(TypeOffsets.size());
+ Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record,
+ (const char *)&TypeOffsets.front(),
+ TypeOffsets.size() * sizeof(TypeOffsets[0]));
+
+ // Write the declaration offsets array
+ Abbrev = new BitCodeAbbrev();
+ Abbrev->Add(BitCodeAbbrevOp(pch::DECL_OFFSET));
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block
+ unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev);
+ Record.clear();
+ Record.push_back(pch::DECL_OFFSET);
+ Record.push_back(DeclOffsets.size());
+ Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record,
+ (const char *)&DeclOffsets.front(),
+ DeclOffsets.size() * sizeof(DeclOffsets[0]));
+}
+
//===----------------------------------------------------------------------===//
// Global Method Pool and Selector Serialization
//===----------------------------------------------------------------------===//
}
PCHWriter::PCHWriter(llvm::BitstreamWriter &Stream, PCHReader *Chain)
- : Stream(Stream), Chain(Chain), NextTypeID(pch::NUM_PREDEF_TYPE_IDS),
+ : Stream(Stream), Chain(Chain), FirstDeclID(1),
+ FirstTypeID(pch::NUM_PREDEF_TYPE_IDS),
CollectedStmts(&StmtsToEmit), NumStatements(0), NumMacros(0),
NumLexicalDeclContexts(0), NumVisibleDeclContexts(0) {
- if (Chain)
+ if (Chain) {
Chain->setDeserializationListener(this);
+ FirstDeclID += Chain->getTotalNumDecls();
+ FirstTypeID += Chain->getTotalNumTypes();
+ }
+ NextTypeID = FirstTypeID;
}
void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls,
WriteMethodPool(SemaRef);
WriteIdentifierTable(PP);
- // Write the type offsets array
- BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
- Abbrev->Add(BitCodeAbbrevOp(pch::TYPE_OFFSET));
- Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types
- Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block
- unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev);
- Record.clear();
- Record.push_back(pch::TYPE_OFFSET);
- Record.push_back(TypeOffsets.size());
- Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record,
- (const char *)&TypeOffsets.front(),
- TypeOffsets.size() * sizeof(TypeOffsets[0]));
-
- // Write the declaration offsets array
- Abbrev = new BitCodeAbbrev();
- Abbrev->Add(BitCodeAbbrevOp(pch::DECL_OFFSET));
- Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations
- Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block
- unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev);
- Record.clear();
- Record.push_back(pch::DECL_OFFSET);
- Record.push_back(DeclOffsets.size());
- Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record,
- (const char *)&DeclOffsets.front(),
- DeclOffsets.size() * sizeof(DeclOffsets[0]));
+ WriteTypeDeclOffsets();
// Write the record containing external, unnamed definitions.
if (!ExternalDefinitions.empty())
ASTContext &Context = SemaRef.Context;
Preprocessor &PP = SemaRef.PP;
(void)PP;
-
+
RecordData Record;
Stream.EnterSubblock(pch::PCH_BLOCK_ID, 5);
WriteMetadata(Context, isysroot);
- // FIXME: StatCache
- // FIXME: Source manager block
+ if (StatCalls && !isysroot)
+ WriteStatCache(*StatCalls);
+ // FIXME: Source manager block should only write new stuff, which could be
+ // done by tracking the largest ID in the chain
+ WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot);
// The special types are in the chained PCH.
for (DeclContext::decl_iterator I = TU->decls_begin(), E = TU->decls_end();
I != E; ++I) {
if ((*I)->getPCHLevel() == 0) {
- (*I)->dump();
DeclTypesToEmit.push(*I);
}
}
// FIXME: Preprocessor
// FIXME: Method pool
// FIXME: Identifier table
- // FIXME: Type offsets
- // FIXME: Declaration offsets
+ WriteTypeDeclOffsets();
// FIXME: External unnamed definitions
// FIXME: Tentative definitions
// FIXME: Unused static functions
}
void PCHWriter::TypeRead(pch::TypeID ID, QualType T) {
+ TypeIDs[T] = ID;
}
void PCHWriter::DeclRead(pch::DeclID ID, const Decl *D) {
+ DeclIDs[D] = ID;
}