mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-22 04:55:50 -04:00

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
50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
//===- 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;
|
|
}
|