forked from OSchip/llvm-project
parent
6d7b456184
commit
09844adc41
|
@ -17,6 +17,8 @@
|
||||||
#include "clang/Basic/LLVM.h"
|
#include "clang/Basic/LLVM.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class MemoryBuffer;
|
class MemoryBuffer;
|
||||||
}
|
}
|
||||||
|
@ -34,15 +36,12 @@ class HeaderMap {
|
||||||
HeaderMap(const HeaderMap &) LLVM_DELETED_FUNCTION;
|
HeaderMap(const HeaderMap &) LLVM_DELETED_FUNCTION;
|
||||||
void operator=(const HeaderMap &) LLVM_DELETED_FUNCTION;
|
void operator=(const HeaderMap &) LLVM_DELETED_FUNCTION;
|
||||||
|
|
||||||
const llvm::MemoryBuffer *FileBuffer;
|
std::unique_ptr<const llvm::MemoryBuffer> FileBuffer;
|
||||||
bool NeedsBSwap;
|
bool NeedsBSwap;
|
||||||
|
|
||||||
HeaderMap(const llvm::MemoryBuffer *File, bool BSwap)
|
HeaderMap(std::unique_ptr<const llvm::MemoryBuffer> File, bool BSwap)
|
||||||
: FileBuffer(File), NeedsBSwap(BSwap) {
|
: FileBuffer(std::move(File)), NeedsBSwap(BSwap) {}
|
||||||
}
|
|
||||||
public:
|
public:
|
||||||
~HeaderMap();
|
|
||||||
|
|
||||||
/// HeaderMap::Create - This attempts to load the specified file as a header
|
/// HeaderMap::Create - This attempts to load the specified file as a header
|
||||||
/// map. If it doesn't look like a HeaderMap, it gives up and returns null.
|
/// map. If it doesn't look like a HeaderMap, it gives up and returns null.
|
||||||
static const HeaderMap *Create(const FileEntry *FE, FileManager &FM);
|
static const HeaderMap *Create(const FileEntry *FE, FileManager &FM);
|
||||||
|
|
|
@ -81,7 +81,8 @@ const HeaderMap *HeaderMap::Create(const FileEntry *FE, FileManager &FM) {
|
||||||
unsigned FileSize = FE->getSize();
|
unsigned FileSize = FE->getSize();
|
||||||
if (FileSize <= sizeof(HMapHeader)) return nullptr;
|
if (FileSize <= sizeof(HMapHeader)) return nullptr;
|
||||||
|
|
||||||
std::unique_ptr<const llvm::MemoryBuffer> FileBuffer(FM.getBufferForFile(FE));
|
std::unique_ptr<const llvm::MemoryBuffer> FileBuffer =
|
||||||
|
FM.getBufferForFile(FE);
|
||||||
if (!FileBuffer) return nullptr; // Unreadable file?
|
if (!FileBuffer) return nullptr; // Unreadable file?
|
||||||
const char *FileStart = FileBuffer->getBufferStart();
|
const char *FileStart = FileBuffer->getBufferStart();
|
||||||
|
|
||||||
|
@ -103,11 +104,7 @@ const HeaderMap *HeaderMap::Create(const FileEntry *FE, FileManager &FM) {
|
||||||
if (Header->Reserved != 0) return nullptr;
|
if (Header->Reserved != 0) return nullptr;
|
||||||
|
|
||||||
// Okay, everything looks good, create the header map.
|
// Okay, everything looks good, create the header map.
|
||||||
return new HeaderMap(FileBuffer.release(), NeedsByteSwap);
|
return new HeaderMap(std::move(FileBuffer), NeedsByteSwap);
|
||||||
}
|
|
||||||
|
|
||||||
HeaderMap::~HeaderMap() {
|
|
||||||
delete FileBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
Loading…
Reference in New Issue