diff options
author | Zachary Turner <zturner@google.com> | 2016-06-10 05:10:19 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-06-10 05:10:19 +0000 |
commit | b84faa8baa8276da1ea3fb7f8c61d98439729c14 (patch) | |
tree | 7be2c547b9012da55c03275138bb5ccea51c98dc /llvm/lib/DebugInfo/PDB/Raw/RawSession.cpp | |
parent | 5acb4ac6d7989e5f59dd6bc035cc1110b2c830dd (diff) | |
download | llvm-b84faa8baa8276da1ea3fb7f8c61d98439729c14.zip llvm-b84faa8baa8276da1ea3fb7f8c61d98439729c14.tar.gz llvm-b84faa8baa8276da1ea3fb7f8c61d98439729c14.tar.bz2 |
Make PDBFile take a StreamInterface instead of a MemBuffer.
This is the next step towards being able to write PDBs.
MemoryBuffer is immutable, and StreamInterface is our replacement
which can be any combination of read-only, read-write, or write-only
depending on the particular implementation.
The one place where we were creating a PDBFile (in RawSession) is
updated to subclass ByteStream with a simple adapter that holds
a MemoryBuffer, and initializes the superclass with the buffer's
array, so that all the functionality of ByteStream works
transparently.
llvm-svn: 272370
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Raw/RawSession.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/RawSession.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Raw/RawSession.cpp b/llvm/lib/DebugInfo/PDB/Raw/RawSession.cpp index cc3a744..458c17a 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/RawSession.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/RawSession.cpp @@ -9,6 +9,8 @@ #include "llvm/DebugInfo/PDB/Raw/RawSession.h" +#include "llvm/DebugInfo/CodeView/ByteStream.h" +#include "llvm/DebugInfo/CodeView/StreamInterface.h" #include "llvm/DebugInfo/PDB/GenericError.h" #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" @@ -23,6 +25,21 @@ using namespace llvm; using namespace llvm::pdb; +namespace { +// We need a class which behaves like an immutable ByteStream, but whose data +// is backed by an llvm::MemoryBuffer. It also needs to own the underlying +// MemoryBuffer, so this simple adapter is a good way to achieve that. +class InputByteStream : public codeview::ByteStream<false> { +public: + explicit InputByteStream(std::unique_ptr<MemoryBuffer> Buffer) + : ByteStream(ArrayRef<uint8_t>(Buffer->getBuffer().bytes_begin(), + Buffer->getBuffer().bytes_end())), + MemBuffer(std::move(Buffer)) {} + + std::unique_ptr<MemoryBuffer> MemBuffer; +}; +} + RawSession::RawSession(std::unique_ptr<PDBFile> PdbFile) : Pdb(std::move(PdbFile)) {} @@ -35,12 +52,10 @@ Error RawSession::createFromPdb(StringRef Path, MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1, /*RequiresNullTerminator=*/false); - if (ErrorOrBuffer.getError()) - return make_error<GenericError>(generic_error_code::invalid_path, Path); - - std::unique_ptr<MemoryBuffer> &Buffer = ErrorOrBuffer.get(); + std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer); + auto Stream = llvm::make_unique<InputByteStream>(std::move(Buffer)); - std::unique_ptr<PDBFile> File(new PDBFile(std::move(Buffer))); + std::unique_ptr<PDBFile> File(new PDBFile(std::move(Stream))); if (auto EC = File->parseFileHeaders()) return EC; if (auto EC = File->parseStreamData()) |