diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2019-03-09 17:33:56 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2019-03-09 17:33:56 +0000 |
commit | d28cf14aed192f83a38af4a07e6c14af97946947 (patch) | |
tree | ddb49b094b52b90d98ffefb1474cbc11ded3dfc7 /lib/Serialization/InMemoryModuleCache.cpp | |
parent | 3a47836eebc2c0f1c5b69d5c9e189244cb9283ae (diff) | |
download | clang-d28cf14aed192f83a38af4a07e6c14af97946947.tar.gz |
Modules: Rename MemoryBufferCache to InMemoryModuleCache
Change MemoryBufferCache to InMemoryModuleCache, moving it from Basic to
Serialization. Another patch will start using it to manage module build
more explicitly, but this is split out because it's mostly mechanical.
Because of the move to Serialization we can no longer abuse the
Preprocessor to forward it to the ASTReader. Besides the rename and
file move, that means Preprocessor::Preprocessor has one fewer parameter
and ASTReader::ASTReader has one more.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355777 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/InMemoryModuleCache.cpp')
-rw-r--r-- | lib/Serialization/InMemoryModuleCache.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/Serialization/InMemoryModuleCache.cpp b/lib/Serialization/InMemoryModuleCache.cpp new file mode 100644 index 0000000000..130ece0150 --- /dev/null +++ b/lib/Serialization/InMemoryModuleCache.cpp @@ -0,0 +1,49 @@ +//===- InMemoryModuleCache.cpp - Cache for loaded memory buffers ----------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "clang/Serialization/InMemoryModuleCache.h" +#include "llvm/Support/MemoryBuffer.h" + +using namespace clang; + +llvm::MemoryBuffer & +InMemoryModuleCache::addBuffer(llvm::StringRef Filename, + std::unique_ptr<llvm::MemoryBuffer> Buffer) { + auto Insertion = PCMs.insert({Filename, PCM{std::move(Buffer), NextIndex++}}); + assert(Insertion.second && "Already has a buffer"); + return *Insertion.first->second.Buffer; +} + +llvm::MemoryBuffer * +InMemoryModuleCache::lookupBuffer(llvm::StringRef Filename) { + auto I = PCMs.find(Filename); + if (I == PCMs.end()) + return nullptr; + return I->second.Buffer.get(); +} + +bool InMemoryModuleCache::isBufferFinal(llvm::StringRef Filename) { + auto I = PCMs.find(Filename); + if (I == PCMs.end()) + return false; + return I->second.Index < FirstRemovableIndex; +} + +bool InMemoryModuleCache::tryToRemoveBuffer(llvm::StringRef Filename) { + auto I = PCMs.find(Filename); + assert(I != PCMs.end() && "No buffer to remove..."); + if (I->second.Index < FirstRemovableIndex) + return true; + + PCMs.erase(I); + return false; +} + +void InMemoryModuleCache::finalizeCurrentBuffers() { + FirstRemovableIndex = NextIndex; +} |