diff options
author | Jonathan D. Turner <jonathan.d.turner@gmail.com> | 2011-08-02 17:40:32 +0000 |
---|---|---|
committer | Jonathan D. Turner <jonathan.d.turner@gmail.com> | 2011-08-02 17:40:32 +0000 |
commit | db1c9e3226abc139bc6ace74f36955a3c05bcaf3 (patch) | |
tree | 1ecab800311db6410bbaa4842023bba22107056e /clang/lib/Serialization/ASTReader.cpp | |
parent | c3e320a7a0ccf754bd9e4ec0cac252845d5a24d2 (diff) | |
download | bcm5719-llvm-db1c9e3226abc139bc6ace74f36955a3c05bcaf3.tar.gz bcm5719-llvm-db1c9e3226abc139bc6ace74f36955a3c05bcaf3.zip |
Following up the earlier refactoring/cleanup work by fixing up how we manage the virtual files the ASTReader has to handle. Specifically, this occurs when the reader is reading AST files that were created in memory and not written to disk. For example, when a user creates a chained PCH using command line flags. These virtual files are stored in MemoryBuffers in ChainIncludeSource.cpp, and then read back in by the ASTReader. This patch moves the management of these buffers into the ModuleManager, so that it becomes the authority on where these buffers are located.
llvm-svn: 136697
Diffstat (limited to 'clang/lib/Serialization/ASTReader.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 0241b22f9e3..1b351a30dc8 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2764,9 +2764,8 @@ ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, if (CurrentDir.empty()) CurrentDir = "."; } - if (!ASTBuffers.empty()) { - F.Buffer.reset(ASTBuffers.back()); - ASTBuffers.pop_back(); + if (llvm::MemoryBuffer *Buffer = ModuleMgr.lookupBuffer(FileName)) { + F.Buffer.reset(Buffer); assert(F.Buffer && "Passed null buffer"); } else { // Open the AST file. @@ -5586,6 +5585,11 @@ Module *ModuleManager::lookup(StringRef Name) { return Modules[Entry]; } +llvm::MemoryBuffer *ModuleManager::lookupBuffer(StringRef Name) { + const FileEntry *Entry = FileMgr.getFile(Name); + return InMemoryBuffers[Entry]; +} + /// \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(); @@ -5605,6 +5609,13 @@ Module &ModuleManager::addModule(StringRef FileName, ModuleKind Type) { return *Current; } +void ModuleManager::addInMemoryBuffer(StringRef FileName, + llvm::MemoryBuffer *Buffer) { + + const FileEntry *Entry = FileMgr.getVirtualFile(FileName, + Buffer->getBufferSize(), 0); + InMemoryBuffers[Entry] = Buffer; +} /// \brief Exports the list of loaded modules with their corresponding names void ModuleManager::exportLookup(SmallVector<ModuleOffset, 16> &Target) { Target.reserve(size()); |