aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/DebugInfo/MSF
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/DebugInfo/MSF')
-rw-r--r--include/llvm/DebugInfo/MSF/ByteStream.h169
-rw-r--r--include/llvm/DebugInfo/MSF/MappedBlockStream.h65
-rw-r--r--include/llvm/DebugInfo/MSF/SequencedItemStream.h93
-rw-r--r--include/llvm/DebugInfo/MSF/StreamArray.h304
-rw-r--r--include/llvm/DebugInfo/MSF/StreamInterface.h53
-rw-r--r--include/llvm/DebugInfo/MSF/StreamReader.h121
-rw-r--r--include/llvm/DebugInfo/MSF/StreamRef.h135
-rw-r--r--include/llvm/DebugInfo/MSF/StreamWriter.h92
8 files changed, 38 insertions, 994 deletions
diff --git a/include/llvm/DebugInfo/MSF/ByteStream.h b/include/llvm/DebugInfo/MSF/ByteStream.h
deleted file mode 100644
index 547844be5e5d..000000000000
--- a/include/llvm/DebugInfo/MSF/ByteStream.h
+++ /dev/null
@@ -1,169 +0,0 @@
-//===- ByteStream.h - Reads stream data from a byte sequence ----*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_DEBUGINFO_MSF_BYTESTREAM_H
-#define LLVM_DEBUGINFO_MSF_BYTESTREAM_H
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/DebugInfo/MSF/MSFError.h"
-#include "llvm/DebugInfo/MSF/StreamInterface.h"
-#include "llvm/Support/Error.h"
-#include "llvm/Support/FileOutputBuffer.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include <algorithm>
-#include <cstdint>
-#include <cstring>
-#include <memory>
-
-namespace llvm {
-namespace msf {
-
-class ByteStream : public ReadableStream {
-public:
- ByteStream() = default;
- explicit ByteStream(ArrayRef<uint8_t> Data) : Data(Data) {}
- explicit ByteStream(StringRef Data)
- : Data(Data.bytes_begin(), Data.bytes_end()) {}
-
- Error readBytes(uint32_t Offset, uint32_t Size,
- ArrayRef<uint8_t> &Buffer) const override {
- if (Offset > Data.size())
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
- if (Data.size() < Size + Offset)
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
- Buffer = Data.slice(Offset, Size);
- return Error::success();
- }
-
- Error readLongestContiguousChunk(uint32_t Offset,
- ArrayRef<uint8_t> &Buffer) const override {
- if (Offset >= Data.size())
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
- Buffer = Data.slice(Offset);
- return Error::success();
- }
-
- uint32_t getLength() const override { return Data.size(); }
-
- ArrayRef<uint8_t> data() const { return Data; }
-
- StringRef str() const {
- const char *CharData = reinterpret_cast<const char *>(Data.data());
- return StringRef(CharData, Data.size());
- }
-
-protected:
- ArrayRef<uint8_t> Data;
-};
-
-// MemoryBufferByteStream behaves like a read-only ByteStream, but has its data
-// backed by an llvm::MemoryBuffer. It also owns the underlying MemoryBuffer.
-class MemoryBufferByteStream : public ByteStream {
-public:
- explicit MemoryBufferByteStream(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;
-};
-
-class MutableByteStream : public WritableStream {
-public:
- MutableByteStream() = default;
- explicit MutableByteStream(MutableArrayRef<uint8_t> Data)
- : Data(Data), ImmutableStream(Data) {}
-
- Error readBytes(uint32_t Offset, uint32_t Size,
- ArrayRef<uint8_t> &Buffer) const override {
- return ImmutableStream.readBytes(Offset, Size, Buffer);
- }
-
- Error readLongestContiguousChunk(uint32_t Offset,
- ArrayRef<uint8_t> &Buffer) const override {
- return ImmutableStream.readLongestContiguousChunk(Offset, Buffer);
- }
-
- uint32_t getLength() const override { return ImmutableStream.getLength(); }
-
- Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Buffer) const override {
- if (Buffer.empty())
- return Error::success();
-
- if (Data.size() < Buffer.size())
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
- if (Offset > Buffer.size() - Data.size())
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
-
- uint8_t *DataPtr = const_cast<uint8_t *>(Data.data());
- ::memcpy(DataPtr + Offset, Buffer.data(), Buffer.size());
- return Error::success();
- }
-
- Error commit() const override { return Error::success(); }
-
- MutableArrayRef<uint8_t> data() const { return Data; }
-
-private:
- MutableArrayRef<uint8_t> Data;
- ByteStream ImmutableStream;
-};
-
-// A simple adapter that acts like a ByteStream but holds ownership over
-// and underlying FileOutputBuffer.
-class FileBufferByteStream : public WritableStream {
-private:
- class StreamImpl : public MutableByteStream {
- public:
- StreamImpl(std::unique_ptr<FileOutputBuffer> Buffer)
- : MutableByteStream(MutableArrayRef<uint8_t>(Buffer->getBufferStart(),
- Buffer->getBufferEnd())),
- FileBuffer(std::move(Buffer)) {}
-
- Error commit() const override {
- if (FileBuffer->commit())
- return llvm::make_error<MSFError>(msf_error_code::not_writable);
- return Error::success();
- }
-
- private:
- std::unique_ptr<FileOutputBuffer> FileBuffer;
- };
-
-public:
- explicit FileBufferByteStream(std::unique_ptr<FileOutputBuffer> Buffer)
- : Impl(std::move(Buffer)) {}
-
- Error readBytes(uint32_t Offset, uint32_t Size,
- ArrayRef<uint8_t> &Buffer) const override {
- return Impl.readBytes(Offset, Size, Buffer);
- }
-
- Error readLongestContiguousChunk(uint32_t Offset,
- ArrayRef<uint8_t> &Buffer) const override {
- return Impl.readLongestContiguousChunk(Offset, Buffer);
- }
-
- uint32_t getLength() const override { return Impl.getLength(); }
-
- Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Data) const override {
- return Impl.writeBytes(Offset, Data);
- }
-
- Error commit() const override { return Impl.commit(); }
-
-private:
- StreamImpl Impl;
-};
-
-} // end namespace msf
-} // end namespace llvm
-
-#endif // LLVM_DEBUGINFO_MSF_BYTESTREAM_H
diff --git a/include/llvm/DebugInfo/MSF/MappedBlockStream.h b/include/llvm/DebugInfo/MSF/MappedBlockStream.h
index fff4e9cecef5..c91f6f725c80 100644
--- a/include/llvm/DebugInfo/MSF/MappedBlockStream.h
+++ b/include/llvm/DebugInfo/MSF/MappedBlockStream.h
@@ -15,8 +15,10 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/DebugInfo/MSF/MSFStreamLayout.h"
-#include "llvm/DebugInfo/MSF/StreamInterface.h"
#include "llvm/Support/Allocator.h"
+#include "llvm/Support/BinaryStream.h"
+#include "llvm/Support/BinaryStream.h"
+#include "llvm/Support/BinaryStreamRef.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include <cstdint>
@@ -37,29 +39,33 @@ struct MSFLayout;
/// the MSF. MappedBlockStream provides methods for reading from and writing
/// to one of these streams transparently, as if it were a contiguous sequence
/// of bytes.
-class MappedBlockStream : public ReadableStream {
+class MappedBlockStream : public BinaryStream {
friend class WritableMappedBlockStream;
public:
static std::unique_ptr<MappedBlockStream>
createStream(uint32_t BlockSize, uint32_t NumBlocks,
- const MSFStreamLayout &Layout, const ReadableStream &MsfData);
+ const MSFStreamLayout &Layout, BinaryStreamRef MsfData);
static std::unique_ptr<MappedBlockStream>
- createIndexedStream(const MSFLayout &Layout, const ReadableStream &MsfData,
+ createIndexedStream(const MSFLayout &Layout, BinaryStreamRef MsfData,
uint32_t StreamIndex);
static std::unique_ptr<MappedBlockStream>
- createFpmStream(const MSFLayout &Layout, const ReadableStream &MsfData);
+ createFpmStream(const MSFLayout &Layout, BinaryStreamRef MsfData);
static std::unique_ptr<MappedBlockStream>
- createDirectoryStream(const MSFLayout &Layout, const ReadableStream &MsfData);
+ createDirectoryStream(const MSFLayout &Layout, BinaryStreamRef MsfData);
+
+ llvm::support::endianness getEndian() const override {
+ return llvm::support::little;
+ }
Error readBytes(uint32_t Offset, uint32_t Size,
- ArrayRef<uint8_t> &Buffer) const override;
+ ArrayRef<uint8_t> &Buffer) override;
Error readLongestContiguousChunk(uint32_t Offset,
- ArrayRef<uint8_t> &Buffer) const override;
+ ArrayRef<uint8_t> &Buffer) override;
- uint32_t getLength() const override;
+ uint32_t getLength() override;
uint32_t getNumBytesCopied() const;
@@ -74,51 +80,56 @@ public:
protected:
MappedBlockStream(uint32_t BlockSize, uint32_t NumBlocks,
const MSFStreamLayout &StreamLayout,
- const ReadableStream &MsfData);
+ BinaryStreamRef MsfData);
private:
const MSFStreamLayout &getStreamLayout() const { return StreamLayout; }
void fixCacheAfterWrite(uint32_t Offset, ArrayRef<uint8_t> Data) const;
- Error readBytes(uint32_t Offset, MutableArrayRef<uint8_t> Buffer) const;
+ Error readBytes(uint32_t Offset, MutableArrayRef<uint8_t> Buffer);
bool tryReadContiguously(uint32_t Offset, uint32_t Size,
- ArrayRef<uint8_t> &Buffer) const;
+ ArrayRef<uint8_t> &Buffer);
const uint32_t BlockSize;
const uint32_t NumBlocks;
const MSFStreamLayout StreamLayout;
- const ReadableStream &MsfData;
+ BinaryStreamRef MsfData;
typedef MutableArrayRef<uint8_t> CacheEntry;
- mutable llvm::BumpPtrAllocator Pool;
- mutable DenseMap<uint32_t, std::vector<CacheEntry>> CacheMap;
+ llvm::BumpPtrAllocator Pool;
+ DenseMap<uint32_t, std::vector<CacheEntry>> CacheMap;
};
-class WritableMappedBlockStream : public WritableStream {
+class WritableMappedBlockStream : public WritableBinaryStream {
public:
static std::unique_ptr<WritableMappedBlockStream>
createStream(uint32_t BlockSize, uint32_t NumBlocks,
- const MSFStreamLayout &Layout, const WritableStream &MsfData);
+ const MSFStreamLayout &Layout, WritableBinaryStreamRef MsfData);
static std::unique_ptr<WritableMappedBlockStream>
- createIndexedStream(const MSFLayout &Layout, const WritableStream &MsfData,
+ createIndexedStream(const MSFLayout &Layout, WritableBinaryStreamRef MsfData,
uint32_t StreamIndex);
static std::unique_ptr<WritableMappedBlockStream>
- createDirectoryStream(const MSFLayout &Layout, const WritableStream &MsfData);
+ createDirectoryStream(const MSFLayout &Layout,
+ WritableBinaryStreamRef MsfData);
static std::unique_ptr<WritableMappedBlockStream>
- createFpmStream(const MSFLayout &Layout, const WritableStream &MsfData);
+ createFpmStream(const MSFLayout &Layout, WritableBinaryStreamRef MsfData);
+
+ llvm::support::endianness getEndian() const override {
+ return llvm::support::little;
+ }
Error readBytes(uint32_t Offset, uint32_t Size,
- ArrayRef<uint8_t> &Buffer) const override;
+ ArrayRef<uint8_t> &Buffer) override;
Error readLongestContiguousChunk(uint32_t Offset,
- ArrayRef<uint8_t> &Buffer) const override;
- uint32_t getLength() const override;
+ ArrayRef<uint8_t> &Buffer) override;
+ uint32_t getLength() override;
- Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Buffer) const override;
+ Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Buffer) override;
- Error commit() const override;
+ Error commit() override;
const MSFStreamLayout &getStreamLayout() const {
return ReadInterface.getStreamLayout();
@@ -130,12 +141,12 @@ public:
protected:
WritableMappedBlockStream(uint32_t BlockSize, uint32_t NumBlocks,
const MSFStreamLayout &StreamLayout,
- const WritableStream &MsfData);
+ WritableBinaryStreamRef MsfData);
private:
MappedBlockStream ReadInterface;
- const WritableStream &WriteInterface;
+ WritableBinaryStreamRef WriteInterface;
};
} // end namespace pdb
diff --git a/include/llvm/DebugInfo/MSF/SequencedItemStream.h b/include/llvm/DebugInfo/MSF/SequencedItemStream.h
deleted file mode 100644
index 1949beef9fff..000000000000
--- a/include/llvm/DebugInfo/MSF/SequencedItemStream.h
+++ /dev/null
@@ -1,93 +0,0 @@
-//===- SequencedItemStream.h ------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_DEBUGINFO_MSF_SEQUENCEDITEMSTREAM_H
-#define LLVM_DEBUGINFO_MSF_SEQUENCEDITEMSTREAM_H
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/DebugInfo/MSF/MSFError.h"
-#include "llvm/DebugInfo/MSF/StreamInterface.h"
-#include "llvm/Support/Error.h"
-#include <cstddef>
-#include <cstdint>
-
-namespace llvm {
-namespace msf {
-
-template <typename T> struct SequencedItemTraits {
- static size_t length(const T &Item) = delete;
- static ArrayRef<uint8_t> bytes(const T &Item) = delete;
-};
-
-/// SequencedItemStream represents a sequence of objects stored in a
-/// standard container but for which it is useful to view as a stream of
-/// contiguous bytes. An example of this might be if you have a std::vector
-/// of TPI records, where each record contains a byte sequence that
-/// represents that one record serialized, but where each consecutive item
-/// might not be allocated immediately after the previous item. Using a
-/// SequencedItemStream, we can adapt the VarStreamArray class to trivially
-/// extract one item at a time, allowing the data to be used anywhere a
-/// VarStreamArray could be used.
-template <typename T, typename Traits = SequencedItemTraits<T>>
-class SequencedItemStream : public ReadableStream {
-public:
- SequencedItemStream() = default;
-
- Error readBytes(uint32_t Offset, uint32_t Size,
- ArrayRef<uint8_t> &Buffer) const override {
- auto ExpectedIndex = translateOffsetIndex(Offset);
- if (!ExpectedIndex)
- return ExpectedIndex.takeError();
- const auto &Item = Items[*ExpectedIndex];
- if (Size > Traits::length(Item))
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
- Buffer = Traits::bytes(Item).take_front(Size);
- return Error::success();
- }
-
- Error readLongestContiguousChunk(uint32_t Offset,
- ArrayRef<uint8_t> &Buffer) const override {
- auto ExpectedIndex = translateOffsetIndex(Offset);
- if (!ExpectedIndex)
- return ExpectedIndex.takeError();
- Buffer = Traits::bytes(Items[*ExpectedIndex]);
- return Error::success();
- }
-
- void setItems(ArrayRef<T> ItemArray) { Items = ItemArray; }
-
- uint32_t getLength() const override {
- uint32_t Size = 0;
- for (const auto &Item : Items)
- Size += Traits::length(Item);
- return Size;
- }
-
-private:
- Expected<uint32_t> translateOffsetIndex(uint32_t Offset) const {
- uint32_t CurrentOffset = 0;
- uint32_t CurrentIndex = 0;
- for (const auto &Item : Items) {
- if (CurrentOffset >= Offset)
- break;
- CurrentOffset += Traits::length(Item);
- ++CurrentIndex;
- }
- if (CurrentOffset != Offset)
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
- return CurrentIndex;
- }
-
- ArrayRef<T> Items;
-};
-
-} // end namespace msf
-} // end namespace llvm
-
-#endif // LLVM_DEBUGINFO_MSF_SEQUENCEDITEMSTREAM_H
diff --git a/include/llvm/DebugInfo/MSF/StreamArray.h b/include/llvm/DebugInfo/MSF/StreamArray.h
deleted file mode 100644
index 5dfeb8c524af..000000000000
--- a/include/llvm/DebugInfo/MSF/StreamArray.h
+++ /dev/null
@@ -1,304 +0,0 @@
-//===- StreamArray.h - Array backed by an arbitrary stream ------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_DEBUGINFO_MSF_STREAMARRAY_H
-#define LLVM_DEBUGINFO_MSF_STREAMARRAY_H
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/iterator.h"
-#include "llvm/DebugInfo/MSF/StreamRef.h"
-#include "llvm/Support/Error.h"
-#include <cassert>
-#include <cstdint>
-
-namespace llvm {
-namespace msf {
-
-/// VarStreamArrayExtractor is intended to be specialized to provide customized
-/// extraction logic. On input it receives a StreamRef pointing to the
-/// beginning of the next record, but where the length of the record is not yet
-/// known. Upon completion, it should return an appropriate Error instance if
-/// a record could not be extracted, or if one could be extracted it should
-/// return success and set Len to the number of bytes this record occupied in
-/// the underlying stream, and it should fill out the fields of the value type
-/// Item appropriately to represent the current record.
-///
-/// You can specialize this template for your own custom value types to avoid
-/// having to specify a second template argument to VarStreamArray (documented
-/// below).
-template <typename T> struct VarStreamArrayExtractor {
- // Method intentionally deleted. You must provide an explicit specialization
- // with the following method implemented.
- Error operator()(ReadableStreamRef Stream, uint32_t &Len,
- T &Item) const = delete;
-};
-
-/// VarStreamArray represents an array of variable length records backed by a
-/// stream. This could be a contiguous sequence of bytes in memory, it could
-/// be a file on disk, or it could be a PDB stream where bytes are stored as
-/// discontiguous blocks in a file. Usually it is desirable to treat arrays
-/// as contiguous blocks of memory, but doing so with large PDB files, for
-/// example, could mean allocating huge amounts of memory just to allow
-/// re-ordering of stream data to be contiguous before iterating over it. By
-/// abstracting this out, we need not duplicate this memory, and we can
-/// iterate over arrays in arbitrarily formatted streams. Elements are parsed
-/// lazily on iteration, so there is no upfront cost associated with building
-/// a VarStreamArray, no matter how large it may be.
-///
-/// You create a VarStreamArray by specifying a ValueType and an Extractor type.
-/// If you do not specify an Extractor type, it expects you to specialize
-/// VarStreamArrayExtractor<T> for your ValueType.
-///
-/// By default an Extractor is default constructed in the class, but in some
-/// cases you might find it useful for an Extractor to maintain state across
-/// extractions. In this case you can provide your own Extractor through a
-/// secondary constructor. The following examples show various ways of
-/// creating a VarStreamArray.
-///
-/// // Will use VarStreamArrayExtractor<MyType> as the extractor.
-/// VarStreamArray<MyType> MyTypeArray;
-///
-/// // Will use a default-constructed MyExtractor as the extractor.
-/// VarStreamArray<MyType, MyExtractor> MyTypeArray2;
-///
-/// // Will use the specific instance of MyExtractor provided.
-/// // MyExtractor need not be default-constructible in this case.
-/// MyExtractor E(SomeContext);
-/// VarStreamArray<MyType, MyExtractor> MyTypeArray3(E);
-///
-template <typename ValueType, typename Extractor> class VarStreamArrayIterator;
-
-template <typename ValueType,
- typename Extractor = VarStreamArrayExtractor<ValueType>>
-
-class VarStreamArray {
- friend class VarStreamArrayIterator<ValueType, Extractor>;
-
-public:
- typedef VarStreamArrayIterator<ValueType, Extractor> Iterator;
-
- VarStreamArray() = default;
- explicit VarStreamArray(const Extractor &E) : E(E) {}
-
- explicit VarStreamArray(ReadableStreamRef Stream) : Stream(Stream) {}
- VarStreamArray(ReadableStreamRef Stream, const Extractor &E)
- : Stream(Stream), E(E) {}
-
- VarStreamArray(const VarStreamArray<ValueType, Extractor> &Other)
- : Stream(Other.Stream), E(Other.E) {}
-
- Iterator begin(bool *HadError = nullptr) const {
- return Iterator(*this, E, HadError);
- }
-
- Iterator end() const { return Iterator(E); }
-
- const Extractor &getExtractor() const { return E; }
-
- ReadableStreamRef getUnderlyingStream() const { return Stream; }
-
-private:
- ReadableStreamRef Stream;
- Extractor E;
-};
-
-template <typename ValueType, typename Extractor>
-class VarStreamArrayIterator
- : public iterator_facade_base<VarStreamArrayIterator<ValueType, Extractor>,
- std::forward_iterator_tag, ValueType> {
- typedef VarStreamArrayIterator<ValueType, Extractor> IterType;
- typedef VarStreamArray<ValueType, Extractor> ArrayType;
-
-public:
- VarStreamArrayIterator(const ArrayType &Array, const Extractor &E,
- bool *HadError = nullptr)
- : IterRef(Array.Stream), Array(&Array), HadError(HadError), Extract(E) {
- if (IterRef.getLength() == 0)
- moveToEnd();
- else {
- auto EC = Extract(IterRef, ThisLen, ThisValue);
- if (EC) {
- consumeError(std::move(EC));
- markError();
- }
- }
- }
- VarStreamArrayIterator() = default;
- explicit VarStreamArrayIterator(const Extractor &E) : Extract(E) {}
- ~VarStreamArrayIterator() = default;
-
- bool operator==(const IterType &R) const {
- if (Array && R.Array) {
- // Both have a valid array, make sure they're same.
- assert(Array == R.Array);
- return IterRef == R.IterRef;
- }
-
- // Both iterators are at the end.
- if (!Array && !R.Array)
- return true;
-
- // One is not at the end and one is.
- return false;
- }
-
- const ValueType &operator*() const {
- assert(Array && !HasError);
- return ThisValue;
- }
-
- IterType &operator++() {
- // We are done with the current record, discard it so that we are
- // positioned at the next record.
- IterRef = IterRef.drop_front(ThisLen);
- if (IterRef.getLength() == 0) {
- // There is nothing after the current record, we must make this an end
- // iterator.
- moveToEnd();
- } else {
- // There is some data after the current record.
- auto EC = Extract(IterRef, ThisLen, ThisValue);
- if (EC) {
- consumeError(std::move(EC));
- markError();
- } else if (ThisLen == 0) {
- // An empty record? Make this an end iterator.
- moveToEnd();
- }
- }
- return *this;
- }
-
-private:
- void moveToEnd() {
- Array = nullptr;
- ThisLen = 0;
- }
- void markError() {
- moveToEnd();
- HasError = true;
- if (HadError != nullptr)
- *HadError = true;
- }
-
- ValueType ThisValue;
- ReadableStreamRef IterRef;
- const ArrayType *Array{nullptr};
- uint32_t ThisLen{0};
- bool HasError{false};
- bool *HadError{nullptr};
- Extractor Extract;
-};
-
-template <typename T> class FixedStreamArrayIterator;
-
-template <typename T> class FixedStreamArray {
- friend class FixedStreamArrayIterator<T>;
-
-public:
- FixedStreamArray() = default;
- FixedStreamArray(ReadableStreamRef Stream) : Stream(Stream) {
- assert(Stream.getLength() % sizeof(T) == 0);
- }
-
- bool operator==(const FixedStreamArray<T> &Other) const {
- return Stream == Other.Stream;
- }
-
- bool operator!=(const FixedStreamArray<T> &Other) const {
- return !(*this == Other);
- }
-
- FixedStreamArray &operator=(const FixedStreamArray &) = default;
-
- const T &operator[](uint32_t Index) const {
- assert(Index < size());
- uint32_t Off = Index * sizeof(T);
- ArrayRef<uint8_t> Data;
- if (auto EC = Stream.readBytes(Off, sizeof(T), Data)) {
- assert(false && "Unexpected failure reading from stream");
- // This should never happen since we asserted that the stream length was
- // an exact multiple of the element size.
- consumeError(std::move(EC));
- }
- return *reinterpret_cast<const T *>(Data.data());
- }
-
- uint32_t size() const { return Stream.getLength() / sizeof(T); }
-
- bool empty() const { return size() == 0; }
-
- FixedStreamArrayIterator<T> begin() const {
- return FixedStreamArrayIterator<T>(*this, 0);
- }
-
- FixedStreamArrayIterator<T> end() const {
- return FixedStreamArrayIterator<T>(*this, size());
- }
-
- ReadableStreamRef getUnderlyingStream() const { return Stream; }
-
-private:
- ReadableStreamRef Stream;
-};
-
-template <typename T>
-class FixedStreamArrayIterator
- : public iterator_facade_base<FixedStreamArrayIterator<T>,
- std::random_access_iterator_tag, T> {
-
-public:
- FixedStreamArrayIterator(const FixedStreamArray<T> &Array, uint32_t Index)
- : Array(Array), Index(Index) {}
-
- FixedStreamArrayIterator<T> &
- operator=(const FixedStreamArrayIterator<T> &Other) {
- Array = Other.Array;
- Index = Other.Index;
- return *this;
- }
-
- const T &operator*() const { return Array[Index]; }
-
- bool operator==(const FixedStreamArrayIterator<T> &R) const {
- assert(Array == R.Array);
- return (Index == R.Index) && (Array == R.Array);
- }
-
- FixedStreamArrayIterator<T> &operator+=(std::ptrdiff_t N) {
- Index += N;
- return *this;
- }
-
- FixedStreamArrayIterator<T> &operator-=(std::ptrdiff_t N) {
- assert(Index >= N);
- Index -= N;
- return *this;
- }
-
- std::ptrdiff_t operator-(const FixedStreamArrayIterator<T> &R) const {
- assert(Array == R.Array);
- assert(Index >= R.Index);
- return Index - R.Index;
- }
-
- bool operator<(const FixedStreamArrayIterator<T> &RHS) const {
- assert(Array == RHS.Array);
- return Index < RHS.Index;
- }
-
-private:
- FixedStreamArray<T> Array;
- uint32_t Index;
-};
-
-} // namespace msf
-} // namespace llvm
-
-#endif // LLVM_DEBUGINFO_MSF_STREAMARRAY_H
diff --git a/include/llvm/DebugInfo/MSF/StreamInterface.h b/include/llvm/DebugInfo/MSF/StreamInterface.h
deleted file mode 100644
index 09782d8e3b30..000000000000
--- a/include/llvm/DebugInfo/MSF/StreamInterface.h
+++ /dev/null
@@ -1,53 +0,0 @@
-//===- StreamInterface.h - Base interface for a stream of data --*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_DEBUGINFO_MSF_STREAMINTERFACE_H
-#define LLVM_DEBUGINFO_MSF_STREAMINTERFACE_H
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/Support/Error.h"
-#include <cstdint>
-
-namespace llvm {
-namespace msf {
-
-class ReadableStream {
-public:
- virtual ~ReadableStream() = default;
-
- // Given an offset into the stream and a number of bytes, attempt to read
- // the bytes and set the output ArrayRef to point to a reference into the
- // stream, without copying any data.
- virtual Error readBytes(uint32_t Offset, uint32_t Size,
- ArrayRef<uint8_t> &Buffer) const = 0;
-
- // Given an offset into the stream, read as much as possible without copying
- // any data.
- virtual Error readLongestContiguousChunk(uint32_t Offset,
- ArrayRef<uint8_t> &Buffer) const = 0;
-
- virtual uint32_t getLength() const = 0;
-};
-
-class WritableStream : public ReadableStream {
-public:
- ~WritableStream() override = default;
-
- // Attempt to write the given bytes into the stream at the desired offset.
- // This will always necessitate a copy. Cannot shrink or grow the stream,
- // only writes into existing allocated space.
- virtual Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Data) const = 0;
-
- virtual Error commit() const = 0;
-};
-
-} // end namespace msf
-} // end namespace llvm
-
-#endif // LLVM_DEBUGINFO_MSF_STREAMINTERFACE_H
diff --git a/include/llvm/DebugInfo/MSF/StreamReader.h b/include/llvm/DebugInfo/MSF/StreamReader.h
deleted file mode 100644
index fc2ca78dc18f..000000000000
--- a/include/llvm/DebugInfo/MSF/StreamReader.h
+++ /dev/null
@@ -1,121 +0,0 @@
-//===- StreamReader.h - Reads bytes and objects from a stream ---*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_DEBUGINFO_MSF_STREAMREADER_H
-#define LLVM_DEBUGINFO_MSF_STREAMREADER_H
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/DebugInfo/MSF/MSFError.h"
-#include "llvm/DebugInfo/MSF/StreamArray.h"
-#include "llvm/DebugInfo/MSF/StreamInterface.h"
-#include "llvm/DebugInfo/MSF/StreamRef.h"
-#include "llvm/Support/Endian.h"
-#include "llvm/Support/Error.h"
-
-#include <string>
-
-namespace llvm {
-namespace msf {
-
-class StreamReader {
-public:
- StreamReader(ReadableStreamRef Stream);
-
- Error readLongestContiguousChunk(ArrayRef<uint8_t> &Buffer);
- Error readBytes(ArrayRef<uint8_t> &Buffer, uint32_t Size);
- Error readInteger(uint8_t &Dest);
- Error readInteger(uint16_t &Dest);
- Error readInteger(uint32_t &Dest);
- Error readInteger(uint64_t &Dest);
- Error readInteger(int8_t &Dest);
- Error readInteger(int16_t &Dest);
- Error readInteger(int32_t &Dest);
- Error readInteger(int64_t &Dest);
- Error readZeroString(StringRef &Dest);
- Error readFixedString(StringRef &Dest, uint32_t Length);
- Error readStreamRef(ReadableStreamRef &Ref);
- Error readStreamRef(ReadableStreamRef &Ref, uint32_t Length);
-
- template <typename T> Error readEnum(T &Dest) {
- typename std::underlying_type<T>::type N;
- if (auto EC = readInteger(N))
- return EC;
- Dest = static_cast<T>(N);
- return Error::success();
- }
-
- template <typename T> Error readObject(const T *&Dest) {
- ArrayRef<uint8_t> Buffer;
- if (auto EC = readBytes(Buffer, sizeof(T)))
- return EC;
- Dest = reinterpret_cast<const T *>(Buffer.data());
- return Error::success();
- }
-
- template <typename T>
- Error readArray(ArrayRef<T> &Array, uint32_t NumElements) {
- ArrayRef<uint8_t> Bytes;
- if (NumElements == 0) {
- Array = ArrayRef<T>();
- return Error::success();
- }
-
- if (NumElements > UINT32_MAX / sizeof(T))
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
-
- if (auto EC = readBytes(Bytes, NumElements * sizeof(T)))
- return EC;
- Array = ArrayRef<T>(reinterpret_cast<const T *>(Bytes.data()), NumElements);
- return Error::success();
- }
-
- template <typename T, typename U>
- Error readArray(VarStreamArray<T, U> &Array, uint32_t Size) {
- ReadableStreamRef S;
- if (auto EC = readStreamRef(S, Size))
- return EC;
- Array = VarStreamArray<T, U>(S, Array.getExtractor());
- return Error::success();
- }
-
- template <typename T>
- Error readArray(FixedStreamArray<T> &Array, uint32_t NumItems) {
- if (NumItems == 0) {
- Array = FixedStreamArray<T>();
- return Error::success();
- }
- uint32_t Length = NumItems * sizeof(T);
- if (Length / sizeof(T) != NumItems)
- return make_error<MSFError>(msf_error_code::invalid_format);
- if (Offset + Length > Stream.getLength())
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
- ReadableStreamRef View = Stream.slice(Offset, Length);
- Array = FixedStreamArray<T>(View);
- Offset += Length;
- return Error::success();
- }
-
- bool empty() const { return bytesRemaining() == 0; }
- void setOffset(uint32_t Off) { Offset = Off; }
- uint32_t getOffset() const { return Offset; }
- uint32_t getLength() const { return Stream.getLength(); }
- uint32_t bytesRemaining() const { return getLength() - getOffset(); }
-
- Error skip(uint32_t Amount);
-
- uint8_t peek() const;
-
-private:
- ReadableStreamRef Stream;
- uint32_t Offset;
-};
-} // namespace msf
-} // namespace llvm
-
-#endif // LLVM_DEBUGINFO_MSF_STREAMREADER_H
diff --git a/include/llvm/DebugInfo/MSF/StreamRef.h b/include/llvm/DebugInfo/MSF/StreamRef.h
deleted file mode 100644
index eee71e53a39b..000000000000
--- a/include/llvm/DebugInfo/MSF/StreamRef.h
+++ /dev/null
@@ -1,135 +0,0 @@
-//===- StreamRef.h - A copyable reference to a stream -----------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_DEBUGINFO_MSF_STREAMREF_H
-#define LLVM_DEBUGINFO_MSF_STREAMREF_H
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/DebugInfo/MSF/MSFError.h"
-#include "llvm/DebugInfo/MSF/StreamInterface.h"
-#include "llvm/Support/Error.h"
-#include <algorithm>
-#include <cstdint>
-
-namespace llvm {
-namespace msf {
-
-template <class StreamType, class RefType> class StreamRefBase {
-public:
- StreamRefBase() : Stream(nullptr), ViewOffset(0), Length(0) {}
- StreamRefBase(const StreamType &Stream, uint32_t Offset, uint32_t Length)
- : Stream(&Stream), ViewOffset(Offset), Length(Length) {}
-
- uint32_t getLength() const { return Length; }
- const StreamType *getStream() const { return Stream; }
-
- RefType drop_front(uint32_t N) const {
- if (!Stream)
- return RefType();
-
- N = std::min(N, Length);
- return RefType(*Stream, ViewOffset + N, Length - N);
- }
-
- RefType keep_front(uint32_t N) const {
- if (!Stream)
- return RefType();
- N = std::min(N, Length);
- return RefType(*Stream, ViewOffset, N);
- }
-
- RefType slice(uint32_t Offset, uint32_t Len) const {
- return drop_front(Offset).keep_front(Len);
- }
-
- bool operator==(const RefType &Other) const {
- if (Stream != Other.Stream)
- return false;
- if (ViewOffset != Other.ViewOffset)
- return false;
- if (Length != Other.Length)
- return false;
- return true;
- }
-
-protected:
- const StreamType *Stream;
- uint32_t ViewOffset;
- uint32_t Length;
-};
-
-class ReadableStreamRef
- : public StreamRefBase<ReadableStream, ReadableStreamRef> {
-public:
- ReadableStreamRef() = default;
- ReadableStreamRef(const ReadableStream &Stream)
- : StreamRefBase(Stream, 0, Stream.getLength()) {}
- ReadableStreamRef(const ReadableStream &Stream, uint32_t Offset,
- uint32_t Length)
- : StreamRefBase(Stream, Offset, Length) {}
-
- // Use StreamRef.slice() instead.
- ReadableStreamRef(const ReadableStreamRef &S, uint32_t Offset,
- uint32_t Length) = delete;
-
- Error readBytes(uint32_t Offset, uint32_t Size,
- ArrayRef<uint8_t> &Buffer) const {
- if (ViewOffset + Offset < Offset)
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
- if (Size + Offset > Length)
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
- return Stream->readBytes(ViewOffset + Offset, Size, Buffer);
- }
-
- // Given an offset into the stream, read as much as possible without copying
- // any data.
- Error readLongestContiguousChunk(uint32_t Offset,
- ArrayRef<uint8_t> &Buffer) const {
- if (Offset >= Length)
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
-
- if (auto EC = Stream->readLongestContiguousChunk(Offset, Buffer))
- return EC;
- // This StreamRef might refer to a smaller window over a larger stream. In
- // that case we will have read out more bytes than we should return, because
- // we should not read past the end of the current view.
- uint32_t MaxLength = Length - Offset;
- if (Buffer.size() > MaxLength)
- Buffer = Buffer.slice(0, MaxLength);
- return Error::success();
- }
-};
-
-class WritableStreamRef
- : public StreamRefBase<WritableStream, WritableStreamRef> {
-public:
- WritableStreamRef() = default;
- WritableStreamRef(const WritableStream &Stream)
- : StreamRefBase(Stream, 0, Stream.getLength()) {}
- WritableStreamRef(const WritableStream &Stream, uint32_t Offset,
- uint32_t Length)
- : StreamRefBase(Stream, Offset, Length) {}
-
- // Use StreamRef.slice() instead.
- WritableStreamRef(const WritableStreamRef &S, uint32_t Offset,
- uint32_t Length) = delete;
-
- Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Data) const {
- if (Data.size() + Offset > Length)
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
- return Stream->writeBytes(ViewOffset + Offset, Data);
- }
-
- Error commit() const { return Stream->commit(); }
-};
-
-} // end namespace msf
-} // end namespace llvm
-
-#endif // LLVM_DEBUGINFO_MSF_STREAMREF_H
diff --git a/include/llvm/DebugInfo/MSF/StreamWriter.h b/include/llvm/DebugInfo/MSF/StreamWriter.h
deleted file mode 100644
index 2bb14434dd83..000000000000
--- a/include/llvm/DebugInfo/MSF/StreamWriter.h
+++ /dev/null
@@ -1,92 +0,0 @@
-//===- StreamWriter.h - Writes bytes and objects to a stream ----*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_DEBUGINFO_MSF_STREAMWRITER_H
-#define LLVM_DEBUGINFO_MSF_STREAMWRITER_H
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/DebugInfo/MSF/MSFError.h"
-#include "llvm/DebugInfo/MSF/StreamArray.h"
-#include "llvm/DebugInfo/MSF/StreamRef.h"
-#include "llvm/Support/Error.h"
-#include <cstdint>
-#include <type_traits>
-
-namespace llvm {
-namespace msf {
-
-class StreamWriter {
-public:
- StreamWriter() = default;
- explicit StreamWriter(WritableStreamRef Stream);
-
- Error writeBytes(ArrayRef<uint8_t> Buffer);
- Error writeInteger(uint8_t Int);
- Error writeInteger(uint16_t Dest);
- Error writeInteger(uint32_t Dest);
- Error writeInteger(uint64_t Dest);
- Error writeInteger(int8_t Int);
- Error writeInteger(int16_t Dest);
- Error writeInteger(int32_t Dest);
- Error writeInteger(int64_t Dest);
- Error writeZeroString(StringRef Str);
- Error writeFixedString(StringRef Str);
- Error writeStreamRef(ReadableStreamRef Ref);
- Error writeStreamRef(ReadableStreamRef Ref, uint32_t Size);
-
- template <typename T> Error writeEnum(T Num) {
- return writeInteger(
- static_cast<typename std::underlying_type<T>::type>(Num));
- }
-
- template <typename T> Error writeObject(const T &Obj) {
- static_assert(!std::is_pointer<T>::value,
- "writeObject should not be used with pointers, to write "
- "the pointed-to value dereference the pointer before calling "
- "writeObject");
- return writeBytes(
- ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(&Obj), sizeof(T)));
- }
-
- template <typename T> Error writeArray(ArrayRef<T> Array) {
- if (Array.empty())
- return Error::success();
-
- if (Array.size() > UINT32_MAX / sizeof(T))
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
-
- return writeBytes(
- ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(Array.data()),
- Array.size() * sizeof(T)));
- }
-
- template <typename T, typename U>
- Error writeArray(VarStreamArray<T, U> Array) {
- return writeStreamRef(Array.getUnderlyingStream());
- }
-
- template <typename T> Error writeArray(FixedStreamArray<T> Array) {
- return writeStreamRef(Array.getUnderlyingStream());
- }
-
- void setOffset(uint32_t Off) { Offset = Off; }
- uint32_t getOffset() const { return Offset; }
- uint32_t getLength() const { return Stream.getLength(); }
- uint32_t bytesRemaining() const { return getLength() - getOffset(); }
-
-private:
- WritableStreamRef Stream;
- uint32_t Offset = 0;
-};
-
-} // end namespace msf
-} // end namespace llvm
-
-#endif // LLVM_DEBUGINFO_MSF_STREAMWRITER_H