diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-08-18 04:12:04 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-08-18 04:12:04 +0000 |
commit | 10bc00fd45824f9b5cd139d63af8b0f6d28aadda (patch) | |
tree | feebae845b9bbbe1782000ac5f70535b2c733b6f /lib/Serialization/ASTReader.cpp | |
parent | 1cb4f664fd4f72a65a145e9ff8a7e2540ab09156 (diff) |
Keep track of which modules have been loaded directly (e.g., via
-import-module) vs. loaded because some other module depends on
them. As part of doing this, pass down the module that caused a module
to be loaded directly, rather than assuming that we're loading a
chain. Finally, write out all of the directly-loaded modules when
serializing an AST file (using the new IMPORTS record), so that an AST
file can depend on more than one other AST file, all of which will be
loaded when that AST file is loaded. This allows us to form and load a
tree of modules, but we can't yet load a DAG of modules.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137923 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ASTReader.cpp')
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 1d7ea1346f..d81e9d8a36 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2045,7 +2045,7 @@ ASTReader::ReadASTBlock(Module &F) { Idx += Length; // Load the AST file. - switch(ReadASTCore(ImportedFile, ImportedKind)) { + switch(ReadASTCore(ImportedFile, ImportedKind, &F)) { case Failure: return Failure; // If we have to ignore the dependency, we'll have to ignore this too. case IgnorePCH: return IgnorePCH; @@ -2724,7 +2724,7 @@ ASTReader::ASTReadResult ASTReader::validateFileEntries() { ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, ModuleKind Type) { - switch(ReadASTCore(FileName, Type)) { + switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0)) { case Failure: return Failure; case IgnorePCH: return IgnorePCH; case Success: break; @@ -2829,8 +2829,9 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, } ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, - ModuleKind Type) { - Module &F = ModuleMgr.addModule(FileName, Type); + ModuleKind Type, + Module *ImportedBy) { + Module &F = ModuleMgr.addModule(FileName, Type, ImportedBy); if (FileName != "-") { CurrentDir = llvm::sys::path::parent_path(FileName); @@ -5610,7 +5611,8 @@ ASTReader::~ASTReader() { } Module::Module(ModuleKind Kind) - : Kind(Kind), SizeInBits(0), LocalNumSLocEntries(0), SLocEntryBaseID(0), + : Kind(Kind), DirectlyImported(false), SizeInBits(0), + LocalNumSLocEntries(0), SLocEntryBaseID(0), SLocEntryBaseOffset(0), SLocEntryOffsets(0), SLocFileOffsets(0), LocalNumIdentifiers(0), IdentifierOffsets(0), BaseIdentifierID(0), IdentifierTableData(0), @@ -5708,19 +5710,21 @@ llvm::MemoryBuffer *ModuleManager::lookupBuffer(StringRef Name) { } /// \brief Creates a new module and adds it to the list of known modules -Module &ModuleManager::addModule(StringRef FileName, ModuleKind Type) { - Module *Prev = !size() ? 0 : &getLastModule(); +Module &ModuleManager::addModule(StringRef FileName, ModuleKind Type, + Module *ImportedBy) { Module *Current = new Module(Type); - Current->FileName = FileName.str(); - Chain.push_back(Current); + const FileEntry *Entry = FileMgr.getFile(FileName); + // FIXME: Check whether we already loaded this module, before Modules[Entry] = Current; - if (Prev) { - Current->ImportedBy.insert(Prev); - Prev->Imports.insert(Current); + if (ImportedBy) { + Current->ImportedBy.insert(ImportedBy); + ImportedBy->Imports.insert(Current); + } else { + Current->DirectlyImported = true; } return *Current; |