diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-12-02 18:58:38 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-12-02 18:58:38 +0000 |
commit | af13bfc3b40aa4a46f4e71d200ecfb10f45297fc (patch) | |
tree | 165d634ec08b0322c2a9966d40b8f944a512791d /lib | |
parent | a015cab273705d1198d13e8389c2f4775f539a8b (diff) |
Implement (de-)serialization of the set of exported modules in a
module map.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145695 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Basic/Module.cpp | 25 | ||||
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 37 | ||||
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 15 |
3 files changed, 76 insertions, 1 deletions
diff --git a/lib/Basic/Module.cpp b/lib/Basic/Module.cpp index 04f9befd1a..6bca55c754 100644 --- a/lib/Basic/Module.cpp +++ b/lib/Basic/Module.cpp @@ -53,6 +53,14 @@ StringRef Module::getTopLevelModuleName() const { return Top->Name; } +static void printModuleId(llvm::raw_ostream &OS, const ModuleId &Id) { + for (unsigned I = 0, N = Id.size(); I != N; ++I) { + if (I) + OS << "."; + OS << Id[I].first; + } +} + void Module::print(llvm::raw_ostream &OS, unsigned Indent) const { OS.indent(Indent); if (IsFramework) @@ -80,6 +88,23 @@ void Module::print(llvm::raw_ostream &OS, unsigned Indent) const { MI != MIEnd; ++MI) MI->getValue()->print(OS, Indent + 2); + for (unsigned I = 0, N = Exports.size(); I != N; ++I) { + OS.indent(Indent + 2); + OS << "export " << Exports[I].getPointer()->getFullModuleName(); + if (Exports[I].getInt()) + OS << ".*"; + OS << "\n"; + } + + for (unsigned I = 0, N = UnresolvedExports.size(); I != N; ++I) { + OS.indent(Indent + 2); + OS << "export "; + printModuleId(OS, UnresolvedExports[I].Id); + if (UnresolvedExports[I].Wildcard) + OS << ".*"; + OS << "\n"; + } + OS.indent(Indent); OS << "}\n"; } diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index d8fb3113d5..26fca2290e 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2533,6 +2533,19 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, Id != IdEnd; ++Id) Id->second->setOutOfDate(true); + // Resolve any unresolved module exports. + for (unsigned I = 0, N = UnresolvedModuleExports.size(); I != N; ++I) { + UnresolvedModuleExport &Unresolved = UnresolvedModuleExports[I]; + SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File, + Unresolved.ExportedID); + if (Module *Exported = getSubmodule(GlobalID)) { + Module *Exportee = Unresolved.ModuleAndWildcard.getPointer(); + bool Wildcard = Unresolved.ModuleAndWildcard.getInt(); + Exportee->Exports.push_back(Module::ExportDecl(Exported, Wildcard)); + } + } + UnresolvedModuleExports.clear(); + InitializeContext(); if (DeserializationListener) @@ -3050,6 +3063,30 @@ ASTReader::ASTReadResult ASTReader::ReadSubmoduleBlock(ModuleFile &F) { } break; } + + case SUBMODULE_EXPORTS: { + if (First) { + Error("missing submodule metadata record at beginning of block"); + return Failure; + } + + if (!CurrentModule) + break; + + for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) { + UnresolvedModuleExport Unresolved; + Unresolved.File = &F; + Unresolved.ModuleAndWildcard.setPointer(CurrentModule); + Unresolved.ModuleAndWildcard.setInt(Record[Idx + 1]); + Unresolved.ExportedID = Record[Idx]; + UnresolvedModuleExports.push_back(Unresolved); + } + + // Once we've loaded the set of exports, there's no reason to keep + // the parsed, unresolved exports around. + CurrentModule->UnresolvedExports.clear(); + break; + } } } diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 6d51dbce3e..00dbfabb45 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1893,6 +1893,7 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) { while (!Q.empty()) { Module *Mod = Q.front(); Q.pop(); + assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); SubmoduleIDs[Mod] = NextSubmoduleID++; // Emit the definition of the block. @@ -1924,6 +1925,18 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) { Mod->Headers[I]->getName()); } + // Emit the exports. + if (!Mod->Exports.empty()) { + Record.clear(); + for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) { + unsigned ExportedID = SubmoduleIDs[Mod->Exports[I].getPointer()]; + assert(ExportedID && "Unknown submodule!"); + Record.push_back(ExportedID); + Record.push_back(Mod->Exports[I].getInt()); + } + Stream.EmitRecord(SUBMODULE_EXPORTS, Record); + } + // Queue up the submodules of this module. llvm::SmallVector<StringRef, 2> SubModules; @@ -3214,7 +3227,7 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, { llvm::raw_svector_ostream Out(Buffer); for (ModuleManager::ModuleConstIterator M = Chain->ModuleMgr.begin(), - MEnd = Chain->ModuleMgr.end(); + MEnd = Chain->ModuleMgr.end(); M != MEnd; ++M) { StringRef FileName = (*M)->FileName; io::Emit16(Out, FileName.size()); |