summaryrefslogtreecommitdiffstats
path: root/clang/lib/Serialization/InMemoryModuleCache.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2019-03-09 17:33:56 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2019-03-09 17:33:56 +0000
commit8bef5cd49a8bb66b777cc3c51f9fb31bffeaa580 (patch)
tree670f325f1bfdb3dc3ebcc977f185d212ce6e31de /clang/lib/Serialization/InMemoryModuleCache.cpp
parent506c1aba4d0d02b97c3097bd422f813f21f5fd10 (diff)
downloadbcm5719-llvm-8bef5cd49a8bb66b777cc3c51f9fb31bffeaa580.tar.gz
bcm5719-llvm-8bef5cd49a8bb66b777cc3c51f9fb31bffeaa580.zip
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. llvm-svn: 355777
Diffstat (limited to 'clang/lib/Serialization/InMemoryModuleCache.cpp')
-rw-r--r--clang/lib/Serialization/InMemoryModuleCache.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/clang/lib/Serialization/InMemoryModuleCache.cpp b/clang/lib/Serialization/InMemoryModuleCache.cpp
new file mode 100644
index 00000000000..130ece01504
--- /dev/null
+++ b/clang/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;
+}
OpenPOWER on IntegriCloud