aboutsummaryrefslogtreecommitdiff
path: root/lib/Serialization/ASTWriter.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-12-06 01:10:29 +0000
committerDouglas Gregor <dgregor@apple.com>2011-12-06 01:10:29 +0000
commite209e5026892cb07294f733c72bd51359c0f0e72 (patch)
treeba7b04ead00a1068a2ff130d38cc6b4b24a48d53 /lib/Serialization/ASTWriter.cpp
parent19efa3ee5a7f2232884f9cca6871329ffe85653c (diff)
Implement inferred submodules support, which (when requested)
implicitly generates submodules corresponding to the headers that fall within a module. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145887 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ASTWriter.cpp')
-rw-r--r--lib/Serialization/ASTWriter.cpp39
1 files changed, 26 insertions, 13 deletions
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index d31eef9e19..946bc76c40 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -1845,6 +1845,14 @@ void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) {
}
}
+unsigned ASTWriter::getSubmoduleID(Module *Mod) {
+ llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod);
+ if (Known != SubmoduleIDs.end())
+ return Known->second;
+
+ return SubmoduleIDs[Mod] = NextSubmoduleID++;
+}
+
/// \brief Compute the number of modules within the given tree (including the
/// given module).
static unsigned getNumberOfModules(Module *Mod) {
@@ -1881,6 +1889,7 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
using namespace llvm;
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION));
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit
@@ -1912,12 +1921,12 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
while (!Q.empty()) {
Module *Mod = Q.front();
Q.pop();
- assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end());
- SubmoduleIDs[Mod] = NextSubmoduleID++;
+ unsigned ID = getSubmoduleID(Mod);
// Emit the definition of the block.
Record.clear();
Record.push_back(SUBMODULE_DEFINITION);
+ Record.push_back(ID);
if (Mod->Parent) {
assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?");
Record.push_back(SubmoduleIDs[Mod->Parent]);
@@ -1988,11 +1997,14 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
}
Stream.ExitBlock();
+
+ assert((NextSubmoduleID - FirstSubmoduleID
+ == getNumberOfModules(WritingModule)) && "Wrong # of submodules");
}
serialization::SubmoduleID
ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) {
- if (Loc.isInvalid() || SubmoduleIDs.empty())
+ if (Loc.isInvalid() || !WritingModule)
return 0; // No submodule
// Find the module that owns this location.
@@ -2002,13 +2014,11 @@ ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) {
if (!OwningMod)
return 0;
- // Check whether we known about this submodule.
- llvm::DenseMap<Module *, unsigned>::iterator Known
- = SubmoduleIDs.find(OwningMod);
- if (Known == SubmoduleIDs.end())
+ // Check whether this submodule is part of our own module.
+ if (WritingModule != OwningMod && !OwningMod->isSubModuleOf(WritingModule))
return 0;
- return Known->second;
+ return getSubmoduleID(OwningMod);
}
void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag) {
@@ -2933,7 +2943,8 @@ void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) {
}
ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream)
- : Stream(Stream), Context(0), PP(0), Chain(0), WritingAST(false),
+ : Stream(Stream), Context(0), PP(0), Chain(0), WritingModule(0),
+ WritingAST(false),
FirstDeclID(NUM_PREDEF_DECL_IDS), NextDeclID(FirstDeclID),
FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID),
FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID),
@@ -2975,9 +2986,11 @@ void ASTWriter::WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls,
Context = &SemaRef.Context;
PP = &SemaRef.PP;
+ this->WritingModule = WritingModule;
WriteASTCore(SemaRef, StatCalls, isysroot, OutputFile, WritingModule);
Context = 0;
PP = 0;
+ this->WritingModule = 0;
WritingAST = false;
}
@@ -3201,10 +3214,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes);
AddTypeRef(Context.getucontext_tType(), SpecialTypes);
- // If we're emitting a module, write out the submodule information.
- if (WritingModule)
- WriteSubmodules(WritingModule);
-
// Keep writing types and declarations until all types and
// declarations have been written.
Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE);
@@ -3282,6 +3291,10 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
WriteCXXBaseSpecifiersOffsets();
+ // If we're emitting a module, write out the submodule information.
+ if (WritingModule)
+ WriteSubmodules(WritingModule);
+
Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes);
/// Build a record containing first declarations from a chained PCH and the