[llvm] r296215 - [PDB] General improvements to Stream library.

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 26 12:02:51 PST 2017


I think it was reverted in r296258.

vedant

> On Feb 26, 2017, at 8:10 AM, Zachary Turner <zturner at google.com> wrote:
> 
> Can you disable this test for now? I can take a look on Monday 
> On Sat, Feb 25, 2017 at 11:29 PM Vedant Kumar <vsk at apple.com> wrote:
> Also, I'd appreciate it if you could separate the NFC renaming/doc update changes, test additions, and bug fixes into separate commits to make them easier to follow.
> 
> thanks,
> vedant
> 
> > On Feb 24, 2017, at 4:44 PM, Zachary Turner via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> >
> > Author: zturner
> > Date: Fri Feb 24 18:44:30 2017
> > New Revision: 296215
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=296215&view=rev
> > Log:
> > [PDB] General improvements to Stream library.
> >
> > This adds various new functionality and cleanup surrounding the
> > use of the Stream library.  Major changes include:
> >
> > * Renaming of all classes for more consistency / meaningfulness
> > * Addition of some new methods for reading multiple values at once.
> > * Full suite of unit tests for reader / writer functionality.
> > * Full set of doxygen comments for all classes.
> > * Streams now store their own endianness.
> > * Fixed some bugs in a few of the classes that were discovered
> >  by the unit tests.
> >
> > Added:
> >    llvm/trunk/unittests/DebugInfo/PDB/BinaryStreamTest.cpp
> > Modified:
> >    llvm/trunk/include/llvm/ADT/STLExtras.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/CVRecord.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/CVTypeVisitor.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstream.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/RecordSerialization.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecordMapping.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolSerializer.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolVisitorDelegate.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDeserializer.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecord.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecordMapping.h
> >    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeSerializer.h
> >    llvm/trunk/include/llvm/DebugInfo/MSF/BinaryByteStream.h
> >    llvm/trunk/include/llvm/DebugInfo/MSF/BinaryItemStream.h
> >    llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStream.h
> >    llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStreamArray.h
> >    llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStreamReader.h
> >    llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStreamRef.h
> >    llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStreamWriter.h
> >    llvm/trunk/include/llvm/DebugInfo/MSF/MappedBlockStream.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiStream.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/GlobalsStream.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/HashTable.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/ModInfo.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/ModStream.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/NamedStreamMap.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/PDBFile.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/PublicsStream.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/StringTable.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/StringTableBuilder.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/TpiHashing.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/TpiStream.h
> >    llvm/trunk/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h
> >    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
> >    llvm/trunk/lib/DebugInfo/CodeView/CVTypeDumper.cpp
> >    llvm/trunk/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
> >    llvm/trunk/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
> >    llvm/trunk/lib/DebugInfo/CodeView/ModuleSubstream.cpp
> >    llvm/trunk/lib/DebugInfo/CodeView/ModuleSubstreamVisitor.cpp
> >    llvm/trunk/lib/DebugInfo/CodeView/RecordSerialization.cpp
> >    llvm/trunk/lib/DebugInfo/CodeView/TypeSerializer.cpp
> >    llvm/trunk/lib/DebugInfo/MSF/BinaryStreamReader.cpp
> >    llvm/trunk/lib/DebugInfo/MSF/BinaryStreamWriter.cpp
> >    llvm/trunk/lib/DebugInfo/MSF/MappedBlockStream.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/DbiStream.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/GSI.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/GSI.h
> >    llvm/trunk/lib/DebugInfo/PDB/Native/GlobalsStream.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/HashTable.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/InfoStream.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/ModInfo.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/ModStream.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/NativeSession.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/PublicsStream.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/StringTable.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/SymbolStream.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/TpiStream.cpp
> >    llvm/trunk/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp
> >    llvm/trunk/tools/llvm-pdbdump/LLVMOutputStyle.cpp
> >    llvm/trunk/tools/llvm-pdbdump/YamlTypeDumper.cpp
> >    llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
> >    llvm/trunk/unittests/DebugInfo/PDB/CMakeLists.txt
> >    llvm/trunk/unittests/DebugInfo/PDB/HashTableTest.cpp
> >    llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp
> >    llvm/trunk/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp
> >
> > Modified: llvm/trunk/include/llvm/ADT/STLExtras.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/STLExtras.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/ADT/STLExtras.h (original)
> > +++ llvm/trunk/include/llvm/ADT/STLExtras.h Fri Feb 24 18:44:30 2017
> > @@ -640,6 +640,16 @@ detail::concat_range<ValueT, RangeTs...>
> > //     Extra additions to <utility>
> > //===----------------------------------------------------------------------===//
> >
> > +/// \brief Template class to compute the sum of sizes of all items in a
> > +/// parameter pack.
> > +template <typename T, typename... Ts> struct sizeof_sum {
> > +  static const size_t value = sizeof(T) + sizeof_sum<Ts...>::value;
> > +};
> > +
> > +template <typename T> struct sizeof_sum<T> {
> > +  static const size_t value = sizeof(T);
> > +};
> > +
> > /// \brief Function object to check whether the first component of a std::pair
> > /// compares less than the first component of another std::pair.
> > struct less_first {
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/CVRecord.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/CVRecord.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/CVRecord.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/CVRecord.h Fri Feb 24 18:44:30 2017
> > @@ -48,15 +48,13 @@ public:
> >
> > } // end namespace codeview
> >
> > -namespace msf {
> > -
> > template <typename Kind>
> > struct VarStreamArrayExtractor<codeview::CVRecord<Kind>> {
> > -  Error operator()(ReadableStreamRef Stream, uint32_t &Len,
> > +  Error operator()(BinaryStreamRef Stream, uint32_t &Len,
> >                    codeview::CVRecord<Kind> &Item) const {
> >     using namespace codeview;
> >     const RecordPrefix *Prefix = nullptr;
> > -    StreamReader Reader(Stream);
> > +    BinaryStreamReader Reader(Stream);
> >     uint32_t Offset = Reader.getOffset();
> >
> >     if (auto EC = Reader.readObject(Prefix))
> > @@ -76,8 +74,6 @@ struct VarStreamArrayExtractor<codeview:
> >   }
> > };
> >
> > -} // end namespace msf
> > -
> > } // end namespace llvm
> >
> > #endif // LLVM_DEBUGINFO_CODEVIEW_RECORDITERATOR_H
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/CVTypeVisitor.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/CVTypeVisitor.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/CVTypeVisitor.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/CVTypeVisitor.h Fri Feb 24 18:44:30 2017
> > @@ -34,7 +34,7 @@ public:
> >   Error visitTypeStream(CVTypeRange Types);
> >
> >   Error visitFieldListMemberStream(ArrayRef<uint8_t> FieldList);
> > -  Error visitFieldListMemberStream(msf::StreamReader Reader);
> > +  Error visitFieldListMemberStream(BinaryStreamReader Reader);
> >
> > private:
> >   /// The interface to the class that gets notified of each visitation.
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h Fri Feb 24 18:44:30 2017
> > @@ -33,8 +33,8 @@ class CodeViewRecordIO {
> >   }
> >
> > public:
> > -  explicit CodeViewRecordIO(msf::StreamReader &Reader) : Reader(&Reader) {}
> > -  explicit CodeViewRecordIO(msf::StreamWriter &Writer) : Writer(&Writer) {}
> > +  explicit CodeViewRecordIO(BinaryStreamReader &Reader) : Reader(&Reader) {}
> > +  explicit CodeViewRecordIO(BinaryStreamWriter &Writer) : Writer(&Writer) {}
> >
> >   Error beginRecord(Optional<uint32_t> MaxLength);
> >   Error endRecord();
> > @@ -59,9 +59,9 @@ public:
> >
> >   template <typename T> Error mapInteger(T &Value) {
> >     if (isWriting())
> > -      return Writer->writeInteger(Value, llvm::support::little);
> > +      return Writer->writeInteger(Value);
> >
> > -    return Reader->readInteger(Value, llvm::support::little);
> > +    return Reader->readInteger(Value);
> >   }
> >
> >   template <typename T> Error mapEnum(T &Value) {
> > @@ -93,7 +93,7 @@ public:
> >     SizeType Size;
> >     if (isWriting()) {
> >       Size = static_cast<SizeType>(Items.size());
> > -      if (auto EC = Writer->writeInteger(Size, llvm::support::little))
> > +      if (auto EC = Writer->writeInteger(Size))
> >         return EC;
> >
> >       for (auto &X : Items) {
> > @@ -101,7 +101,7 @@ public:
> >           return EC;
> >       }
> >     } else {
> > -      if (auto EC = Reader->readInteger(Size, llvm::support::little))
> > +      if (auto EC = Reader->readInteger(Size))
> >         return EC;
> >       for (SizeType I = 0; I < Size; ++I) {
> >         typename T::value_type Item;
> > @@ -160,8 +160,8 @@ private:
> >
> >   SmallVector<RecordLimit, 2> Limits;
> >
> > -  msf::StreamReader *Reader = nullptr;
> > -  msf::StreamWriter *Writer = nullptr;
> > +  BinaryStreamReader *Reader = nullptr;
> > +  BinaryStreamWriter *Writer = nullptr;
> > };
> >
> > } // end namespace codeview
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstream.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstream.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstream.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstream.h Fri Feb 24 18:44:30 2017
> > @@ -59,23 +59,22 @@ struct ColumnNumberEntry {
> > class ModuleSubstream {
> > public:
> >   ModuleSubstream();
> > -  ModuleSubstream(ModuleSubstreamKind Kind, msf::ReadableStreamRef Data);
> > -  static Error initialize(msf::ReadableStreamRef Stream, ModuleSubstream &Info);
> > +  ModuleSubstream(ModuleSubstreamKind Kind, BinaryStreamRef Data);
> > +  static Error initialize(BinaryStreamRef Stream, ModuleSubstream &Info);
> >   uint32_t getRecordLength() const;
> >   ModuleSubstreamKind getSubstreamKind() const;
> > -  msf::ReadableStreamRef getRecordData() const;
> > +  BinaryStreamRef getRecordData() const;
> >
> > private:
> >   ModuleSubstreamKind Kind;
> > -  msf::ReadableStreamRef Data;
> > +  BinaryStreamRef Data;
> > };
> >
> > -typedef msf::VarStreamArray<ModuleSubstream> ModuleSubstreamArray;
> > +typedef VarStreamArray<ModuleSubstream> ModuleSubstreamArray;
> > } // namespace codeview
> >
> > -namespace msf {
> > template <> struct VarStreamArrayExtractor<codeview::ModuleSubstream> {
> > -  Error operator()(ReadableStreamRef Stream, uint32_t &Length,
> > +  Error operator()(BinaryStreamRef Stream, uint32_t &Length,
> >                    codeview::ModuleSubstream &Info) const {
> >     if (auto EC = codeview::ModuleSubstream::initialize(Stream, Info))
> >       return EC;
> > @@ -83,7 +82,6 @@ template <> struct VarStreamArrayExtract
> >     return Error::success();
> >   }
> > };
> > -} // namespace msf
> > } // namespace llvm
> >
> > #endif // LLVM_DEBUGINFO_CODEVIEW_MODULESUBSTREAM_H
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h Fri Feb 24 18:44:30 2017
> > @@ -28,8 +28,8 @@ namespace codeview {
> >
> > struct LineColumnEntry {
> >   support::ulittle32_t NameIndex;
> > -  msf::FixedStreamArray<LineNumberEntry> LineNumbers;
> > -  msf::FixedStreamArray<ColumnNumberEntry> Columns;
> > +  FixedStreamArray<LineNumberEntry> LineNumbers;
> > +  FixedStreamArray<ColumnNumberEntry> Columns;
> > };
> >
> > struct FileChecksumEntry {
> > @@ -38,49 +38,47 @@ struct FileChecksumEntry {
> >   ArrayRef<uint8_t> Checksum; // The bytes of the checksum.
> > };
> >
> > -typedef msf::VarStreamArray<LineColumnEntry> LineInfoArray;
> > -typedef msf::VarStreamArray<FileChecksumEntry> FileChecksumArray;
> > +typedef VarStreamArray<LineColumnEntry> LineInfoArray;
> > +typedef VarStreamArray<FileChecksumEntry> FileChecksumArray;
> >
> > class IModuleSubstreamVisitor {
> > public:
> >   virtual ~IModuleSubstreamVisitor() = default;
> >
> >   virtual Error visitUnknown(ModuleSubstreamKind Kind,
> > -                             msf::ReadableStreamRef Data) = 0;
> > -  virtual Error visitSymbols(msf::ReadableStreamRef Data);
> > -  virtual Error visitLines(msf::ReadableStreamRef Data,
> > +                             BinaryStreamRef Data) = 0;
> > +  virtual Error visitSymbols(BinaryStreamRef Data);
> > +  virtual Error visitLines(BinaryStreamRef Data,
> >                            const LineSubstreamHeader *Header,
> >                            const LineInfoArray &Lines);
> > -  virtual Error visitStringTable(msf::ReadableStreamRef Data);
> > -  virtual Error visitFileChecksums(msf::ReadableStreamRef Data,
> > +  virtual Error visitStringTable(BinaryStreamRef Data);
> > +  virtual Error visitFileChecksums(BinaryStreamRef Data,
> >                                    const FileChecksumArray &Checksums);
> > -  virtual Error visitFrameData(msf::ReadableStreamRef Data);
> > -  virtual Error visitInlineeLines(msf::ReadableStreamRef Data);
> > -  virtual Error visitCrossScopeImports(msf::ReadableStreamRef Data);
> > -  virtual Error visitCrossScopeExports(msf::ReadableStreamRef Data);
> > -  virtual Error visitILLines(msf::ReadableStreamRef Data);
> > -  virtual Error visitFuncMDTokenMap(msf::ReadableStreamRef Data);
> > -  virtual Error visitTypeMDTokenMap(msf::ReadableStreamRef Data);
> > -  virtual Error visitMergedAssemblyInput(msf::ReadableStreamRef Data);
> > -  virtual Error visitCoffSymbolRVA(msf::ReadableStreamRef Data);
> > +  virtual Error visitFrameData(BinaryStreamRef Data);
> > +  virtual Error visitInlineeLines(BinaryStreamRef Data);
> > +  virtual Error visitCrossScopeImports(BinaryStreamRef Data);
> > +  virtual Error visitCrossScopeExports(BinaryStreamRef Data);
> > +  virtual Error visitILLines(BinaryStreamRef Data);
> > +  virtual Error visitFuncMDTokenMap(BinaryStreamRef Data);
> > +  virtual Error visitTypeMDTokenMap(BinaryStreamRef Data);
> > +  virtual Error visitMergedAssemblyInput(BinaryStreamRef Data);
> > +  virtual Error visitCoffSymbolRVA(BinaryStreamRef Data);
> > };
> >
> > Error visitModuleSubstream(const ModuleSubstream &R,
> >                            IModuleSubstreamVisitor &V);
> > } // end namespace codeview
> >
> > -namespace msf {
> > -
> > template <> class VarStreamArrayExtractor<codeview::LineColumnEntry> {
> > public:
> >   VarStreamArrayExtractor(const codeview::LineSubstreamHeader *Header)
> >       : Header(Header) {}
> >
> > -  Error operator()(ReadableStreamRef Stream, uint32_t &Len,
> > +  Error operator()(BinaryStreamRef Stream, uint32_t &Len,
> >                    codeview::LineColumnEntry &Item) const {
> >     using namespace codeview;
> >     const LineFileBlockHeader *BlockHeader;
> > -    StreamReader Reader(Stream);
> > +    BinaryStreamReader Reader(Stream);
> >     if (auto EC = Reader.readObject(BlockHeader))
> >       return EC;
> >     bool HasColumn = Header->Flags & LineFlags::HaveColumns;
> > @@ -113,11 +111,11 @@ private:
> >
> > template <> class VarStreamArrayExtractor<codeview::FileChecksumEntry> {
> > public:
> > -  Error operator()(ReadableStreamRef Stream, uint32_t &Len,
> > +  Error operator()(BinaryStreamRef Stream, uint32_t &Len,
> >                    codeview::FileChecksumEntry &Item) const {
> >     using namespace codeview;
> >     const FileChecksum *Header;
> > -    StreamReader Reader(Stream);
> > +    BinaryStreamReader Reader(Stream);
> >     if (auto EC = Reader.readObject(Header))
> >       return EC;
> >     Item.FileNameOffset = Header->FileNameOffset;
> > @@ -129,8 +127,6 @@ public:
> >   }
> > };
> >
> > -} // end namespace msf
> > -
> > } // end namespace llvm
> >
> > #endif // LLVM_DEBUGINFO_CODEVIEW_MODULESUBSTREAMVISITOR_H
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/RecordSerialization.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/RecordSerialization.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/RecordSerialization.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/RecordSerialization.h Fri Feb 24 18:44:30 2017
> > @@ -41,37 +41,37 @@ struct RecordPrefix {
> > StringRef getBytesAsCharacters(ArrayRef<uint8_t> LeafData);
> > StringRef getBytesAsCString(ArrayRef<uint8_t> LeafData);
> >
> > -inline Error consume(msf::StreamReader &Reader) { return Error::success(); }
> > +inline Error consume(BinaryStreamReader &Reader) { return Error::success(); }
> >
> > /// Decodes a numeric "leaf" value. These are integer literals encountered in
> > /// the type stream. If the value is positive and less than LF_NUMERIC (1 <<
> > /// 15), it is emitted directly in Data. Otherwise, it has a tag like LF_CHAR
> > /// that indicates the bitwidth and sign of the numeric data.
> > -Error consume(msf::StreamReader &Reader, APSInt &Num);
> > +Error consume(BinaryStreamReader &Reader, APSInt &Num);
> >
> > /// Decodes a numeric leaf value that is known to be a particular type.
> > -Error consume_numeric(msf::StreamReader &Reader, uint64_t &Value);
> > +Error consume_numeric(BinaryStreamReader &Reader, uint64_t &Value);
> >
> > /// Decodes signed and unsigned fixed-length integers.
> > -Error consume(msf::StreamReader &Reader, uint32_t &Item);
> > -Error consume(msf::StreamReader &Reader, int32_t &Item);
> > +Error consume(BinaryStreamReader &Reader, uint32_t &Item);
> > +Error consume(BinaryStreamReader &Reader, int32_t &Item);
> >
> > /// Decodes a null terminated string.
> > -Error consume(msf::StreamReader &Reader, StringRef &Item);
> > +Error consume(BinaryStreamReader &Reader, StringRef &Item);
> >
> > Error consume(StringRef &Data, APSInt &Num);
> > Error consume(StringRef &Data, uint32_t &Item);
> >
> > /// Decodes an arbitrary object whose layout matches that of the underlying
> > /// byte sequence, and returns a pointer to the object.
> > -template <typename T> Error consume(msf::StreamReader &Reader, T *&Item) {
> > +template <typename T> Error consume(BinaryStreamReader &Reader, T *&Item) {
> >   return Reader.readObject(Item);
> > }
> >
> > template <typename T, typename U> struct serialize_conditional_impl {
> >   serialize_conditional_impl(T &Item, U Func) : Item(Item), Func(Func) {}
> >
> > -  Error deserialize(msf::StreamReader &Reader) const {
> > +  Error deserialize(BinaryStreamReader &Reader) const {
> >     if (!Func())
> >       return Error::success();
> >     return consume(Reader, Item);
> > @@ -89,7 +89,7 @@ serialize_conditional_impl<T, U> seriali
> > template <typename T, typename U> struct serialize_array_impl {
> >   serialize_array_impl(ArrayRef<T> &Item, U Func) : Item(Item), Func(Func) {}
> >
> > -  Error deserialize(msf::StreamReader &Reader) const {
> > +  Error deserialize(BinaryStreamReader &Reader) const {
> >     return Reader.readArray(Item, Func());
> >   }
> >
> > @@ -100,7 +100,7 @@ template <typename T, typename U> struct
> > template <typename T> struct serialize_vector_tail_impl {
> >   serialize_vector_tail_impl(std::vector<T> &Item) : Item(Item) {}
> >
> > -  Error deserialize(msf::StreamReader &Reader) const {
> > +  Error deserialize(BinaryStreamReader &Reader) const {
> >     T Field;
> >     // Stop when we run out of bytes or we hit record padding bytes.
> >     while (!Reader.empty() && Reader.peek() < LF_PAD0) {
> > @@ -118,14 +118,14 @@ struct serialize_null_term_string_array_
> >   serialize_null_term_string_array_impl(std::vector<StringRef> &Item)
> >       : Item(Item) {}
> >
> > -  Error deserialize(msf::StreamReader &Reader) const {
> > +  Error deserialize(BinaryStreamReader &Reader) const {
> >     if (Reader.empty())
> >       return make_error<CodeViewError>(cv_error_code::insufficient_buffer,
> >                                        "Null terminated string is empty!");
> >
> >     while (Reader.peek() != 0) {
> >       StringRef Field;
> > -      if (auto EC = Reader.readZeroString(Field))
> > +      if (auto EC = Reader.readCString(Field))
> >         return EC;
> >       Item.push_back(Field);
> >     }
> > @@ -138,7 +138,7 @@ struct serialize_null_term_string_array_
> > template <typename T> struct serialize_arrayref_tail_impl {
> >   serialize_arrayref_tail_impl(ArrayRef<T> &Item) : Item(Item) {}
> >
> > -  Error deserialize(msf::StreamReader &Reader) const {
> > +  Error deserialize(BinaryStreamReader &Reader) const {
> >     uint32_t Count = Reader.bytesRemaining() / sizeof(T);
> >     return Reader.readArray(Item, Count);
> >   }
> > @@ -149,7 +149,7 @@ template <typename T> struct serialize_a
> > template <typename T> struct serialize_numeric_impl {
> >   serialize_numeric_impl(T &Item) : Item(Item) {}
> >
> > -  Error deserialize(msf::StreamReader &Reader) const {
> > +  Error deserialize(BinaryStreamReader &Reader) const {
> >     return consume_numeric(Reader, Item);
> >   }
> >
> > @@ -201,42 +201,42 @@ template <typename T> serialize_numeric_
> > #define CV_NUMERIC_FIELD(I) serialize_numeric(I)
> >
> > template <typename T, typename U>
> > -Error consume(msf::StreamReader &Reader,
> > +Error consume(BinaryStreamReader &Reader,
> >               const serialize_conditional_impl<T, U> &Item) {
> >   return Item.deserialize(Reader);
> > }
> >
> > template <typename T, typename U>
> > -Error consume(msf::StreamReader &Reader,
> > +Error consume(BinaryStreamReader &Reader,
> >               const serialize_array_impl<T, U> &Item) {
> >   return Item.deserialize(Reader);
> > }
> >
> > -inline Error consume(msf::StreamReader &Reader,
> > +inline Error consume(BinaryStreamReader &Reader,
> >                      const serialize_null_term_string_array_impl &Item) {
> >   return Item.deserialize(Reader);
> > }
> >
> > template <typename T>
> > -Error consume(msf::StreamReader &Reader,
> > +Error consume(BinaryStreamReader &Reader,
> >               const serialize_vector_tail_impl<T> &Item) {
> >   return Item.deserialize(Reader);
> > }
> >
> > template <typename T>
> > -Error consume(msf::StreamReader &Reader,
> > +Error consume(BinaryStreamReader &Reader,
> >               const serialize_arrayref_tail_impl<T> &Item) {
> >   return Item.deserialize(Reader);
> > }
> >
> > template <typename T>
> > -Error consume(msf::StreamReader &Reader,
> > +Error consume(BinaryStreamReader &Reader,
> >               const serialize_numeric_impl<T> &Item) {
> >   return Item.deserialize(Reader);
> > }
> >
> > template <typename T, typename U, typename... Args>
> > -Error consume(msf::StreamReader &Reader, T &&X, U &&Y, Args &&... Rest) {
> > +Error consume(BinaryStreamReader &Reader, T &&X, U &&Y, Args &&... Rest) {
> >   if (auto EC = consume(Reader, X))
> >     return EC;
> >   return consume(Reader, Y, std::forward<Args>(Rest)...);
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h Fri Feb 24 18:44:30 2017
> > @@ -25,10 +25,11 @@ class SymbolVisitorDelegate;
> > class SymbolDeserializer : public SymbolVisitorCallbacks {
> >   struct MappingInfo {
> >     explicit MappingInfo(ArrayRef<uint8_t> RecordData)
> > -        : Stream(RecordData), Reader(Stream), Mapping(Reader) {}
> > +        : Stream(RecordData, llvm::support::little), Reader(Stream),
> > +          Mapping(Reader) {}
> >
> > -    msf::ByteStream Stream;
> > -    msf::StreamReader Reader;
> > +    BinaryByteStream Stream;
> > +    BinaryStreamReader Reader;
> >     SymbolRecordMapping Mapping;
> >   };
> >
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h Fri Feb 24 18:44:30 2017
> > @@ -938,7 +938,7 @@ public:
> > };
> >
> > typedef CVRecord<SymbolKind> CVSymbol;
> > -typedef msf::VarStreamArray<CVSymbol> CVSymbolArray;
> > +typedef VarStreamArray<CVSymbol> CVSymbolArray;
> >
> > } // end namespace codeview
> > } // end namespace llvm
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecordMapping.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecordMapping.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecordMapping.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecordMapping.h Fri Feb 24 18:44:30 2017
> > @@ -14,16 +14,14 @@
> > #include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h"
> >
> > namespace llvm {
> > -namespace msf {
> > -class StreamReader;
> > -class StreamWriter;
> > -}
> > +class BinaryStreamReader;
> > +class BinaryStreamWriter;
> >
> > namespace codeview {
> > class SymbolRecordMapping : public SymbolVisitorCallbacks {
> > public:
> > -  explicit SymbolRecordMapping(msf::StreamReader &Reader) : IO(Reader) {}
> > -  explicit SymbolRecordMapping(msf::StreamWriter &Writer) : IO(Writer) {}
> > +  explicit SymbolRecordMapping(BinaryStreamReader &Reader) : IO(Reader) {}
> > +  explicit SymbolRecordMapping(BinaryStreamWriter &Writer) : IO(Writer) {}
> >
> >   Error visitSymbolBegin(CVSymbol &Record) override;
> >   Error visitSymbolEnd(CVSymbol &Record) override;
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolSerializer.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolSerializer.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolSerializer.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolSerializer.h Fri Feb 24 18:44:30 2017
> > @@ -20,6 +20,8 @@
> > #include "llvm/ADT/StringMap.h"
> > #include "llvm/ADT/StringRef.h"
> > #include "llvm/ADT/iterator_range.h"
> > +#include "llvm/DebugInfo/MSF/BinaryByteStream.h"
> > +#include "llvm/DebugInfo/MSF/BinaryStreamWriter.h"
> > #include "llvm/Support/Allocator.h"
> > #include "llvm/Support/Error.h"
> >
> > @@ -28,7 +30,7 @@ namespace codeview {
> >
> > class SymbolSerializer : public SymbolVisitorCallbacks {
> >   uint32_t RecordStart = 0;
> > -  msf::StreamWriter &Writer;
> > +  BinaryStreamWriter &Writer;
> >   SymbolRecordMapping Mapping;
> >   Optional<SymbolKind> CurrentSymbol;
> >
> > @@ -42,7 +44,7 @@ class SymbolSerializer : public SymbolVi
> >   }
> >
> > public:
> > -  explicit SymbolSerializer(msf::StreamWriter &Writer)
> > +  explicit SymbolSerializer(BinaryStreamWriter &Writer)
> >       : Writer(Writer), Mapping(Writer) {}
> >
> >   virtual Error visitSymbolBegin(CVSymbol &Record) override {
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolVisitorDelegate.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolVisitorDelegate.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolVisitorDelegate.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolVisitorDelegate.h Fri Feb 24 18:44:30 2017
> > @@ -15,9 +15,7 @@
> >
> > namespace llvm {
> >
> > -namespace msf {
> > -class StreamReader;
> > -} // end namespace msf
> > +class BinaryStreamReader;
> >
> > namespace codeview {
> >
> > @@ -25,7 +23,7 @@ class SymbolVisitorDelegate {
> > public:
> >   virtual ~SymbolVisitorDelegate() = default;
> >
> > -  virtual uint32_t getRecordOffset(msf::StreamReader Reader) = 0;
> > +  virtual uint32_t getRecordOffset(BinaryStreamReader Reader) = 0;
> >   virtual StringRef getFileNameForFileOffset(uint32_t FileOffset) = 0;
> >   virtual StringRef getStringTable() = 0;
> > };
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDeserializer.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDeserializer.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDeserializer.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDeserializer.h Fri Feb 24 18:44:30 2017
> > @@ -29,10 +29,11 @@ namespace codeview {
> > class TypeDeserializer : public TypeVisitorCallbacks {
> >   struct MappingInfo {
> >     explicit MappingInfo(ArrayRef<uint8_t> RecordData)
> > -        : Stream(RecordData), Reader(Stream), Mapping(Reader) {}
> > +        : Stream(RecordData, llvm::support::little), Reader(Stream),
> > +          Mapping(Reader) {}
> >
> > -    msf::ByteStream Stream;
> > -    msf::StreamReader Reader;
> > +    BinaryByteStream Stream;
> > +    BinaryStreamReader Reader;
> >     TypeRecordMapping Mapping;
> >   };
> >
> > @@ -72,16 +73,16 @@ private:
> >
> > class FieldListDeserializer : public TypeVisitorCallbacks {
> >   struct MappingInfo {
> > -    explicit MappingInfo(msf::StreamReader &R)
> > +    explicit MappingInfo(BinaryStreamReader &R)
> >         : Reader(R), Mapping(Reader), StartOffset(0) {}
> >
> > -    msf::StreamReader &Reader;
> > +    BinaryStreamReader &Reader;
> >     TypeRecordMapping Mapping;
> >     uint32_t StartOffset;
> >   };
> >
> > public:
> > -  explicit FieldListDeserializer(msf::StreamReader &Reader) : Mapping(Reader) {
> > +  explicit FieldListDeserializer(BinaryStreamReader &Reader) : Mapping(Reader) {
> >     CVType FieldList;
> >     FieldList.Type = TypeLeafKind::LF_FIELDLIST;
> >     consumeError(Mapping.Mapping.visitTypeBegin(FieldList));
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecord.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecord.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecord.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecord.h Fri Feb 24 18:44:30 2017
> > @@ -26,9 +26,7 @@
> >
> > namespace llvm {
> >
> > -namespace msf {
> > -class StreamReader;
> > -} // end namespace msf
> > +class BinaryStreamReader;
> >
> > namespace codeview {
> >
> > @@ -42,7 +40,7 @@ struct CVMemberRecord {
> >   TypeLeafKind Kind;
> >   ArrayRef<uint8_t> Data;
> > };
> > -typedef msf::VarStreamArray<CVType> CVTypeArray;
> > +typedef VarStreamArray<CVType> CVTypeArray;
> > typedef iterator_range<CVTypeArray::Iterator> CVTypeRange;
> >
> > /// Equvalent to CV_fldattr_t in cvinfo.h.
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecordMapping.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecordMapping.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecordMapping.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecordMapping.h Fri Feb 24 18:44:30 2017
> > @@ -16,15 +16,14 @@
> > #include "llvm/Support/Error.h"
> >
> > namespace llvm {
> > -namespace msf {
> > -class StreamReader;
> > -class StreamWriter;
> > -}
> > +class BinaryStreamReader;
> > +class BinaryStreamWriter;
> > +
> > namespace codeview {
> > class TypeRecordMapping : public TypeVisitorCallbacks {
> > public:
> > -  explicit TypeRecordMapping(msf::StreamReader &Reader) : IO(Reader) {}
> > -  explicit TypeRecordMapping(msf::StreamWriter &Writer) : IO(Writer) {}
> > +  explicit TypeRecordMapping(BinaryStreamReader &Reader) : IO(Reader) {}
> > +  explicit TypeRecordMapping(BinaryStreamWriter &Writer) : IO(Writer) {}
> >
> >   Error visitTypeBegin(CVType &Record) override;
> >   Error visitTypeEnd(CVType &Record) override;
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeSerializer.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeSerializer.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeSerializer.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeSerializer.h Fri Feb 24 18:44:30 2017
> > @@ -56,8 +56,8 @@ class TypeSerializer : public TypeVisito
> >   Optional<TypeLeafKind> TypeKind;
> >   Optional<TypeLeafKind> MemberKind;
> >   std::vector<uint8_t> RecordBuffer;
> > -  msf::MutableByteStream Stream;
> > -  msf::StreamWriter Writer;
> > +  MutableBinaryByteStream Stream;
> > +  BinaryStreamWriter Writer;
> >   TypeRecordMapping Mapping;
> >
> >   RecordList SeenRecords;
> > @@ -109,7 +109,7 @@ private:
> >   Error visitKnownMemberImpl(CVMemberRecord &CVR, RecordType &Record) {
> >     assert(CVR.Kind == static_cast<TypeLeafKind>(Record.getKind()));
> >
> > -    if (auto EC = Writer.writeEnum(CVR.Kind, llvm::support::little))
> > +    if (auto EC = Writer.writeEnum(CVR.Kind))
> >       return EC;
> >
> >     if (auto EC = Mapping.visitKnownMember(CVR, Record))
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/MSF/BinaryByteStream.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/MSF/BinaryByteStream.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/MSF/BinaryByteStream.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/MSF/BinaryByteStream.h Fri Feb 24 18:44:30 2017
> > @@ -1,19 +1,19 @@
> > -//===- ByteStream.h - Reads stream data from a byte sequence ----*- C++ -*-===//
> > +//===- BinaryByteStream.h ---------------------------------------*- C++ -*-===//
> > //
> > //                     The LLVM Compiler Infrastructure
> > //
> > // This file is distributed under the University of Illinois Open Source
> > // License. See LICENSE.TXT for details.
> > -//
> > +//===----------------------------------------------------------------------===//
> > +// A BinaryStream which stores data in a single continguous memory buffer.
> > //===----------------------------------------------------------------------===//
> >
> > -#ifndef LLVM_DEBUGINFO_MSF_BYTESTREAM_H
> > -#define LLVM_DEBUGINFO_MSF_BYTESTREAM_H
> > +#ifndef LLVM_SUPPORT_BINARYBYTESTREAM_H
> > +#define LLVM_SUPPORT_BINARYBYTESTREAM_H
> >
> > #include "llvm/ADT/ArrayRef.h"
> > #include "llvm/ADT/StringRef.h"
> > #include "llvm/DebugInfo/MSF/BinaryStream.h"
> > -#include "llvm/DebugInfo/MSF/MSFError.h"
> > #include "llvm/Support/Error.h"
> > #include "llvm/Support/FileOutputBuffer.h"
> > #include "llvm/Support/MemoryBuffer.h"
> > @@ -23,34 +23,40 @@
> > #include <memory>
> >
> > namespace llvm {
> > -namespace msf {
> >
> > -class ByteStream : public ReadableStream {
> > +/// \brief An implementation of BinaryStream which holds its entire data set
> > +/// in a single contiguous buffer.  BinaryByteStream guarantees that no read
> > +/// operation will ever incur a copy.  Note that BinaryByteStream does not
> > +/// own the underlying buffer.
> > +class BinaryByteStream : public BinaryStream {
> > public:
> > -  ByteStream() = default;
> > -  explicit ByteStream(ArrayRef<uint8_t> Data) : Data(Data) {}
> > -  explicit ByteStream(StringRef Data)
> > -      : Data(Data.bytes_begin(), Data.bytes_end()) {}
> > +  BinaryByteStream() = default;
> > +  BinaryByteStream(ArrayRef<uint8_t> Data, llvm::support::endianness Endian)
> > +      : Endian(Endian), Data(Data) {}
> > +  BinaryByteStream(StringRef Data, llvm::support::endianness Endian)
> > +      : Endian(Endian), Data(Data.bytes_begin(), Data.bytes_end()) {}
> > +
> > +  llvm::support::endianness getEndian() const override { return Endian; }
> >
> >   Error readBytes(uint32_t Offset, uint32_t Size,
> > -                  ArrayRef<uint8_t> &Buffer) const override {
> > +                  ArrayRef<uint8_t> &Buffer) override {
> >     if (Offset > Data.size())
> > -      return make_error<MSFError>(msf_error_code::insufficient_buffer);
> > +      return errorCodeToError(make_error_code(std::errc::no_buffer_space));
> >     if (Data.size() < Size + Offset)
> > -      return make_error<MSFError>(msf_error_code::insufficient_buffer);
> > +      return errorCodeToError(make_error_code(std::errc::no_buffer_space));
> >     Buffer = Data.slice(Offset, Size);
> >     return Error::success();
> >   }
> >
> >   Error readLongestContiguousChunk(uint32_t Offset,
> > -                                   ArrayRef<uint8_t> &Buffer) const override {
> > +                                   ArrayRef<uint8_t> &Buffer) override {
> >     if (Offset >= Data.size())
> > -      return make_error<MSFError>(msf_error_code::insufficient_buffer);
> > +      return errorCodeToError(make_error_code(std::errc::no_buffer_space));
> >     Buffer = Data.slice(Offset);
> >     return Error::success();
> >   }
> >
> > -  uint32_t getLength() const override { return Data.size(); }
> > +  uint32_t getLength() override { return Data.size(); }
> >
> >   ArrayRef<uint8_t> data() const { return Data; }
> >
> > @@ -60,76 +66,91 @@ public:
> >   }
> >
> > protected:
> > +  llvm::support::endianness Endian;
> >   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 {
> > +/// \brief An implementation of BinaryStream whose data is backed by an llvm
> > +/// MemoryBuffer object.  MemoryBufferByteStream owns the MemoryBuffer in
> > +/// question.  As with BinaryByteStream, reading from a MemoryBufferByteStream
> > +/// will never cause a copy.
> > +class MemoryBufferByteStream : public BinaryByteStream {
> > public:
> > -  explicit MemoryBufferByteStream(std::unique_ptr<MemoryBuffer> Buffer)
> > -      : ByteStream(ArrayRef<uint8_t>(Buffer->getBuffer().bytes_begin(),
> > -                                     Buffer->getBuffer().bytes_end())),
> > +  explicit MemoryBufferByteStream(std::unique_ptr<MemoryBuffer> Buffer,
> > +                                  llvm::support::endianness Endian)
> > +      : BinaryByteStream(Buffer->getBuffer(), Endian),
> >         MemBuffer(std::move(Buffer)) {}
> >
> >   std::unique_ptr<MemoryBuffer> MemBuffer;
> > };
> >
> > -class MutableByteStream : public WritableStream {
> > +/// \brief An implementation of BinaryStream which holds its entire data set
> > +/// in a single contiguous buffer.  As with BinaryByteStream, the mutable
> > +/// version also guarantees that no read operation will ever incur a copy,
> > +/// and similarly it does not own the underlying buffer.
> > +class MutableBinaryByteStream : public WritableBinaryStream {
> > public:
> > -  MutableByteStream() = default;
> > -  explicit MutableByteStream(MutableArrayRef<uint8_t> Data)
> > -      : Data(Data), ImmutableStream(Data) {}
> > +  MutableBinaryByteStream() = default;
> > +  MutableBinaryByteStream(MutableArrayRef<uint8_t> Data,
> > +                          llvm::support::endianness Endian)
> > +      : Data(Data), ImmutableStream(Data, Endian) {}
> > +
> > +  llvm::support::endianness getEndian() const override {
> > +    return ImmutableStream.getEndian();
> > +  }
> >
> >   Error readBytes(uint32_t Offset, uint32_t Size,
> > -                  ArrayRef<uint8_t> &Buffer) const override {
> > +                  ArrayRef<uint8_t> &Buffer) override {
> >     return ImmutableStream.readBytes(Offset, Size, Buffer);
> >   }
> >
> >   Error readLongestContiguousChunk(uint32_t Offset,
> > -                                   ArrayRef<uint8_t> &Buffer) const override {
> > +                                   ArrayRef<uint8_t> &Buffer) override {
> >     return ImmutableStream.readLongestContiguousChunk(Offset, Buffer);
> >   }
> >
> > -  uint32_t getLength() const override { return ImmutableStream.getLength(); }
> > +  uint32_t getLength() override { return ImmutableStream.getLength(); }
> >
> > -  Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Buffer) const override {
> > +  Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Buffer) override {
> >     if (Buffer.empty())
> >       return Error::success();
> >
> >     if (Data.size() < Buffer.size())
> > -      return make_error<MSFError>(msf_error_code::insufficient_buffer);
> > +      return errorCodeToError(make_error_code(std::errc::no_buffer_space));
> >     if (Offset > Buffer.size() - Data.size())
> > -      return make_error<MSFError>(msf_error_code::insufficient_buffer);
> > +      return errorCodeToError(make_error_code(std::errc::no_buffer_space));
> >
> >     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(); }
> > +  Error commit() override { return Error::success(); }
> >
> >   MutableArrayRef<uint8_t> data() const { return Data; }
> >
> > private:
> >   MutableArrayRef<uint8_t> Data;
> > -  ByteStream ImmutableStream;
> > +  BinaryByteStream ImmutableStream;
> > };
> >
> > -// A simple adapter that acts like a ByteStream but holds ownership over
> > -// and underlying FileOutputBuffer.
> > -class FileBufferByteStream : public WritableStream {
> > +/// \brief An implementation of WritableBinaryStream backed by an llvm
> > +/// FileOutputBuffer.
> > +class FileBufferByteStream : public WritableBinaryStream {
> > private:
> > -  class StreamImpl : public MutableByteStream {
> > +  class StreamImpl : public MutableBinaryByteStream {
> >   public:
> > -    StreamImpl(std::unique_ptr<FileOutputBuffer> Buffer)
> > -        : MutableByteStream(MutableArrayRef<uint8_t>(Buffer->getBufferStart(),
> > -                                                     Buffer->getBufferEnd())),
> > +    StreamImpl(std::unique_ptr<FileOutputBuffer> Buffer,
> > +               llvm::support::endianness Endian)
> > +        : MutableBinaryByteStream(
> > +              MutableArrayRef<uint8_t>(Buffer->getBufferStart(),
> > +                                       Buffer->getBufferEnd()),
> > +              Endian),
> >           FileBuffer(std::move(Buffer)) {}
> >
> > -    Error commit() const override {
> > +    Error commit() override {
> >       if (FileBuffer->commit())
> > -        return llvm::make_error<MSFError>(msf_error_code::not_writable);
> > +        return errorCodeToError(make_error_code(std::errc::no_buffer_space));
> >       return Error::success();
> >     }
> >
> > @@ -138,32 +159,36 @@ private:
> >   };
> >
> > public:
> > -  explicit FileBufferByteStream(std::unique_ptr<FileOutputBuffer> Buffer)
> > -      : Impl(std::move(Buffer)) {}
> > +  explicit FileBufferByteStream(std::unique_ptr<FileOutputBuffer> Buffer,
> > +                                llvm::support::endianness Endian)
> > +      : Impl(std::move(Buffer), Endian) {}
> > +
> > +  llvm::support::endianness getEndian() const override {
> > +    return Impl.getEndian();
> > +  }
> >
> >   Error readBytes(uint32_t Offset, uint32_t Size,
> > -                  ArrayRef<uint8_t> &Buffer) const override {
> > +                  ArrayRef<uint8_t> &Buffer) override {
> >     return Impl.readBytes(Offset, Size, Buffer);
> >   }
> >
> >   Error readLongestContiguousChunk(uint32_t Offset,
> > -                                   ArrayRef<uint8_t> &Buffer) const override {
> > +                                   ArrayRef<uint8_t> &Buffer) override {
> >     return Impl.readLongestContiguousChunk(Offset, Buffer);
> >   }
> >
> > -  uint32_t getLength() const override { return Impl.getLength(); }
> > +  uint32_t getLength() override { return Impl.getLength(); }
> >
> > -  Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Data) const override {
> > +  Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Data) override {
> >     return Impl.writeBytes(Offset, Data);
> >   }
> >
> > -  Error commit() const override { return Impl.commit(); }
> > +  Error commit() override { return Impl.commit(); }
> >
> > private:
> >   StreamImpl Impl;
> > };
> >
> > -} // end namespace msf
> > } // end namespace llvm
> >
> > -#endif // LLVM_DEBUGINFO_MSF_BYTESTREAM_H
> > +#endif // LLVM_SUPPORT_BINARYBYTESTREAM_H
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/MSF/BinaryItemStream.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/MSF/BinaryItemStream.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/MSF/BinaryItemStream.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/MSF/BinaryItemStream.h Fri Feb 24 18:44:30 2017
> > @@ -1,4 +1,4 @@
> > -//===- SequencedItemStream.h ------------------------------------*- C++ -*-===//
> > +//===- BinaryItemStream.h ---------------------------------------*- C++ -*-===//
> > //
> > //                     The LLVM Compiler Infrastructure
> > //
> > @@ -7,87 +7,96 @@
> > //
> > //===----------------------------------------------------------------------===//
> >
> > -#ifndef LLVM_DEBUGINFO_MSF_SEQUENCEDITEMSTREAM_H
> > -#define LLVM_DEBUGINFO_MSF_SEQUENCEDITEMSTREAM_H
> > +#ifndef LLVM_SUPPORT_BINARYITEMSTREAM_H
> > +#define LLVM_SUPPORT_BINARYITEMSTREAM_H
> >
> > #include "llvm/ADT/ArrayRef.h"
> > #include "llvm/DebugInfo/MSF/BinaryStream.h"
> > -#include "llvm/DebugInfo/MSF/MSFError.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;
> > +template <typename T> struct BinaryItemTraits {
> > +  size_t length(const T &Item) = delete;
> > +  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 {
> > +/// BinaryItemStream represents a sequence of objects stored in some kind of
> > +/// external 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 collection of
> > +/// records and you serialize each one into a buffer, and store these serialized
> > +/// records in a container.  The pointers themselves are not laid out
> > +/// contiguously in memory, but we may wish to read from or write to these
> > +/// records as if they were.
> > +template <typename T, typename ItemTraits = BinaryItemTraits<T>>
> > +class BinaryItemStream : public BinaryStream {
> > public:
> > -  SequencedItemStream() = default;
> > +  explicit BinaryItemStream(llvm::support::endianness Endian)
> > +      : Endian(Endian) {}
> > +
> > +  llvm::support::endianness getEndian() const override { return Endian; }
> >
> >   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);
> > +                  ArrayRef<uint8_t> &Buffer) override {
> > +    if (auto EC = readLongestContiguousChunk(Offset, Buffer))
> > +      return EC;
> > +
> > +    if (Size > Buffer.size())
> > +      return errorCodeToError(make_error_code(std::errc::no_buffer_space));
> > +
> > +    Buffer = Buffer.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]);
> > +                                   ArrayRef<uint8_t> &Buffer) override {
> > +    uint32_t Index;
> > +    uint32_t ByteOffset;
> > +    if (auto EC = translateOffsetIndex(Offset, Index, ByteOffset))
> > +      return EC;
> > +    const auto &Item = Items[Index];
> > +    Buffer = Traits.bytes(Item).drop_front(ByteOffset);
> >     return Error::success();
> >   }
> >
> >   void setItems(ArrayRef<T> ItemArray) { Items = ItemArray; }
> >
> > -  uint32_t getLength() const override {
> > +  uint32_t getLength() override {
> >     uint32_t Size = 0;
> >     for (const auto &Item : Items)
> > -      Size += Traits::length(Item);
> > +      Size += Traits.length(Item);
> >     return Size;
> >   }
> >
> > private:
> > -  Expected<uint32_t> translateOffsetIndex(uint32_t Offset) const {
> > +  Error translateOffsetIndex(uint32_t Offset, uint32_t &ItemIndex,
> > +                             uint32_t &ByteOffset) {
> > +    ItemIndex = 0;
> > +    ByteOffset = 0;
> > +    uint32_t PrevOffset = 0;
> >     uint32_t CurrentOffset = 0;
> > -    uint32_t CurrentIndex = 0;
> > -    for (const auto &Item : Items) {
> > -      if (CurrentOffset >= Offset)
> > -        break;
> > -      CurrentOffset += Traits::length(Item);
> > -      ++CurrentIndex;
> > +    if (Offset > 0) {
> > +      for (const auto &Item : Items) {
> > +        PrevOffset = CurrentOffset;
> > +        CurrentOffset += Traits.length(Item);
> > +        if (CurrentOffset > Offset)
> > +          break;
> > +        ++ItemIndex;
> > +      }
> >     }
> > -    if (CurrentOffset != Offset)
> > -      return make_error<MSFError>(msf_error_code::insufficient_buffer);
> > -    return CurrentIndex;
> > +    if (CurrentOffset < Offset)
> > +      return errorCodeToError(make_error_code(std::errc::no_buffer_space));
> > +    ByteOffset = Offset - PrevOffset;
> > +    return Error::success();
> >   }
> >
> > +  llvm::support::endianness Endian;
> > +  ItemTraits Traits;
> >   ArrayRef<T> Items;
> > };
> >
> > -} // end namespace msf
> > } // end namespace llvm
> >
> > -#endif // LLVM_DEBUGINFO_MSF_SEQUENCEDITEMSTREAM_H
> > +#endif // LLVM_SUPPORT_BINARYITEMSTREAM_H
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStream.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStream.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStream.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStream.h Fri Feb 24 18:44:30 2017
> > @@ -1,4 +1,4 @@
> > -//===- StreamInterface.h - Base interface for a stream of data --*- C++ -*-===//
> > +//===- BinaryStream.h - Base interface for a stream of data -----*- C++ -*-===//
> > //
> > //                     The LLVM Compiler Infrastructure
> > //
> > @@ -7,47 +7,62 @@
> > //
> > //===----------------------------------------------------------------------===//
> >
> > -#ifndef LLVM_DEBUGINFO_MSF_STREAMINTERFACE_H
> > -#define LLVM_DEBUGINFO_MSF_STREAMINTERFACE_H
> > +#ifndef LLVM_SUPPORT_BINARYSTREAM_H
> > +#define LLVM_SUPPORT_BINARYSTREAM_H
> >
> > #include "llvm/ADT/ArrayRef.h"
> > +#include "llvm/Support/Endian.h"
> > #include "llvm/Support/Error.h"
> > #include <cstdint>
> >
> > namespace llvm {
> > -namespace msf {
> >
> > -class ReadableStream {
> > +/// \brief An interface for accessing data in a stream-like format, but which
> > +/// discourages copying.  Instead of specifying a buffer in which to copy
> > +/// data on a read, the API returns an ArrayRef to data owned by the stream's
> > +/// implementation.  Since implementations may not necessarily store data in a
> > +/// single contiguous buffer (or even in memory at all), in such cases a it may
> > +/// be necessary for an implementation to cache such a buffer so that it can
> > +/// return it.
> > +class BinaryStream {
> > public:
> > -  virtual ~ReadableStream() = default;
> > +  virtual ~BinaryStream() = 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 llvm::support::endianness getEndian() const = 0;
> > +
> > +  /// \brief Given an offset into the stream and a number of bytes, attempt to
> > +  /// read the bytes and set the output ArrayRef to point to data owned by the
> > +  /// stream.
> >   virtual Error readBytes(uint32_t Offset, uint32_t Size,
> > -                          ArrayRef<uint8_t> &Buffer) const = 0;
> > +                          ArrayRef<uint8_t> &Buffer) = 0;
> >
> > -  // Given an offset into the stream, read as much as possible without copying
> > -  // any data.
> > +  /// \brief 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;
> > +                                           ArrayRef<uint8_t> &Buffer) = 0;
> >
> > -  virtual uint32_t getLength() const = 0;
> > +  /// \brief Return the number of bytes of data in this stream.
> > +  virtual uint32_t getLength() = 0;
> > };
> >
> > -class WritableStream : public ReadableStream {
> > +/// \brief A BinaryStream which can be read from as well as written to.  Note
> > +/// that writing to a BinaryStream always necessitates copying from the input
> > +/// buffer to the stream's backing store.  Streams are assumed to be buffered
> > +/// so that to be portable it is necessary to call commit() on the stream when
> > +/// all data has been written.
> > +class WritableBinaryStream : public BinaryStream {
> > public:
> > -  ~WritableStream() override = default;
> > +  ~WritableBinaryStream() 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;
> > +  /// \brief 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) = 0;
> >
> > -  virtual Error commit() const = 0;
> > +  /// \brief For buffered streams, commits changes to the backing store.
> > +  virtual Error commit() = 0;
> > };
> >
> > -} // end namespace msf
> > } // end namespace llvm
> >
> > -#endif // LLVM_DEBUGINFO_MSF_STREAMINTERFACE_H
> > +#endif // LLVM_SUPPORT_BINARYSTREAM_H
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStreamArray.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStreamArray.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStreamArray.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStreamArray.h Fri Feb 24 18:44:30 2017
> > @@ -1,4 +1,4 @@
> > -//===- StreamArray.h - Array backed by an arbitrary stream ------*- C++ -*-===//
> > +//===- BinaryStreamArray.h - Array backed by an arbitrary stream *- C++ -*-===//
> > //
> > //                     The LLVM Compiler Infrastructure
> > //
> > @@ -7,8 +7,8 @@
> > //
> > //===----------------------------------------------------------------------===//
> >
> > -#ifndef LLVM_DEBUGINFO_MSF_STREAMARRAY_H
> > -#define LLVM_DEBUGINFO_MSF_STREAMARRAY_H
> > +#ifndef LLVM_SUPPORT_BINARYSTREAMARRAY_H
> > +#define LLVM_SUPPORT_BINARYSTREAMARRAY_H
> >
> > #include "llvm/ADT/ArrayRef.h"
> > #include "llvm/ADT/iterator.h"
> > @@ -17,11 +17,20 @@
> > #include <cassert>
> > #include <cstdint>
> >
> > +/// Lightweight arrays that are backed by an arbitrary BinaryStream.  This file
> > +/// provides two different array implementations.
> > +///
> > +///     VarStreamArray - Arrays of variable length records.  The user specifies
> > +///       an Extractor type that can extract a record from a given offset and
> > +///       return the number of bytes consumed by the record.
> > +///
> > +///     FixedStreamArray - Arrays of fixed length records.  This is similar in
> > +///       spirit to ArrayRef<T>, but since it is backed by a BinaryStream, the
> > +///       elements of the array need not be laid out in contiguous memory.
> > namespace llvm {
> > -namespace msf {
> >
> > /// VarStreamArrayExtractor is intended to be specialized to provide customized
> > -/// extraction logic.  On input it receives a StreamRef pointing to the
> > +/// extraction logic.  On input it receives a BinaryStreamRef 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
> > @@ -35,7 +44,7 @@ namespace msf {
> > 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,
> > +  Error operator()(BinaryStreamRef Stream, uint32_t &Len,
> >                    T &Item) const = delete;
> > };
> >
> > @@ -49,10 +58,10 @@ template <typename T> struct VarStreamAr
> > /// 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.
> > +/// or copying 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
> > +/// If you do not specify an Extractor type, you are expected to specialize
> > /// VarStreamArrayExtractor<T> for your ValueType.
> > ///
> > /// By default an Extractor is default constructed in the class, but in some
> > @@ -86,8 +95,8 @@ public:
> >   VarStreamArray() = default;
> >   explicit VarStreamArray(const Extractor &E) : E(E) {}
> >
> > -  explicit VarStreamArray(ReadableStreamRef Stream) : Stream(Stream) {}
> > -  VarStreamArray(ReadableStreamRef Stream, const Extractor &E)
> > +  explicit VarStreamArray(BinaryStreamRef Stream) : Stream(Stream) {}
> > +  VarStreamArray(BinaryStreamRef Stream, const Extractor &E)
> >       : Stream(Stream), E(E) {}
> >
> >   VarStreamArray(const VarStreamArray<ValueType, Extractor> &Other)
> > @@ -101,10 +110,10 @@ public:
> >
> >   const Extractor &getExtractor() const { return E; }
> >
> > -  ReadableStreamRef getUnderlyingStream() const { return Stream; }
> > +  BinaryStreamRef getUnderlyingStream() const { return Stream; }
> >
> > private:
> > -  ReadableStreamRef Stream;
> > +  BinaryStreamRef Stream;
> >   Extractor E;
> > };
> >
> > @@ -153,23 +162,25 @@ public:
> >     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.
> > +  IterType &operator+=(unsigned N) {
> > +    for (unsigned I = 0; I < N; ++I) {
> > +      // 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;
> > @@ -188,7 +199,7 @@ private:
> >   }
> >
> >   ValueType ThisValue;
> > -  ReadableStreamRef IterRef;
> > +  BinaryStreamRef IterRef;
> >   const ArrayType *Array{nullptr};
> >   uint32_t ThisLen{0};
> >   bool HasError{false};
> > @@ -198,12 +209,17 @@ private:
> >
> > template <typename T> class FixedStreamArrayIterator;
> >
> > +/// FixedStreamArray is similar to VarStreamArray, except with each record
> > +/// having a fixed-length.  As with VarStreamArray, there is no upfront
> > +/// cost associated with building or copying a FixedStreamArray, as the
> > +/// memory for each element is not read from the backing stream until that
> > +/// element is iterated.
> > template <typename T> class FixedStreamArray {
> >   friend class FixedStreamArrayIterator<T>;
> >
> > public:
> >   FixedStreamArray() = default;
> > -  FixedStreamArray(ReadableStreamRef Stream) : Stream(Stream) {
> > +  explicit FixedStreamArray(BinaryStreamRef Stream) : Stream(Stream) {
> >     assert(Stream.getLength() % sizeof(T) == 0);
> >   }
> >
> > @@ -242,10 +258,10 @@ public:
> >     return FixedStreamArrayIterator<T>(*this, size());
> >   }
> >
> > -  ReadableStreamRef getUnderlyingStream() const { return Stream; }
> > +  BinaryStreamRef getUnderlyingStream() const { return Stream; }
> >
> > private:
> > -  ReadableStreamRef Stream;
> > +  BinaryStreamRef Stream;
> > };
> >
> > template <typename T>
> > @@ -298,7 +314,6 @@ private:
> >   uint32_t Index;
> > };
> >
> > -} // namespace msf
> > } // namespace llvm
> >
> > -#endif // LLVM_DEBUGINFO_MSF_STREAMARRAY_H
> > +#endif // LLVM_SUPPORT_BINARYSTREAMARRAY_H
> >
> > Modified: llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStreamReader.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStreamReader.h?rev=296215&r1=296214&r2=296215&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStreamReader.h (original)
> > +++ llvm/trunk/include/llvm/DebugInfo/MSF/BinaryStreamReader.h Fri Feb 24 18:44:30 2017
> > @@ -1,4 +1,4 @@
> > -//===- StreamReader.h - Reads bytes and objects from a stream ---*- C++ -*-===//
> > +//===- BinaryStreamReader.h - Reads objects from a binary stream *- C++ -*-===//
> > //
> > //                     The LLVM Compiler Infrastructure
> > //
> > @@ -7,71 +7,166 @@
> > //
> > //===----------------------------------------------------------------------===//
> >
> > -#ifndef LLVM_DEBUGINFO_MSF_STREAMREADER_H
> > -#define LLVM_DEBUGINFO_MSF_STREAMREADER_H
> > +#ifndef LLVM_SUPPORT_BINARYSTREAMREADER_H
> > +#define LLVM_SUPPORT_BINARYSTREAMREADER_H
> >
> > #include "llvm/ADT/ArrayRef.h"
> > +#include "llvm/ADT/STLExtras.h"
> > #include "llvm/DebugInfo/MSF/BinaryStream.h"
> > #include "llvm/DebugInfo/MSF/BinaryStreamArray.h"
> > #include "llvm/DebugInfo/MSF/BinaryStreamRef.h"
> > -#include "llvm/DebugInfo/MSF/MSFError.h"
> > #include "llvm/Support/Endian.h"
> > #include "llvm/Support/Error.h"
> > +#include "llvm/Support/MathExtras.h"
> > #include "llvm/Support/type_traits.h"
> >
> > #include <string>
> > #include <type_traits>
> >
> > namespace llvm {
> > -namespace msf {
> >
> > -class StreamReader {
> > +/// \brief Provides read only access to a subclass of `BinaryStream`.  Provides
> > +/// bounds checking and helpers for writing certain common data types such as
> > +/// null-terminated strings, integers in various flavors of endianness, etc.
> > +/// Can be subclassed to provide reading of custom datatypes, although no
> > +/// are overridable.
> > +class BinaryStreamReader {
> > public:
> > -  StreamReader(ReadableStreamRef Stream);
> > +  explicit BinaryStreamReader(BinaryStreamRef Stream);
> > +  virtual ~BinaryStreamReader() {}
> >
> > +  /// Read as much as possible from the underlying string at the current offset
> > +  /// without invoking a copy, and set \p Buffer to the resulting data slice.
> > +  /// Updates the stream's offset to point after the newly read data.
> > +  ///
> > +  /// \returns a success error code if the data was successfully read, otherwise
> > +  /// returns an appropriate error code.
> >   Error readLongestContiguousChunk(ArrayRef<uint8_t> &Buffer);
> > +
> > +  /// Read \p Size bytes from the underlying stream at the current offset and
> > +  /// and set \p Buffer to the resulting data slice.  Whether a copy occurs
> > +  /// depends on the implementation of the underlying stream.  Updates the
> > +  /// stream's offset to point after the newly read data.
> > +  ///
> > +  /// \returns a success error code if the data was successfully read, otherwise
> > +  /// returns an appropriate error code.
> >   Error readBytes(ArrayRef<uint8_t> &Buffer, uint32_t Size);
> >
> > -  template <typename T>
> > -  Error readInteger(T &Dest,
> > -     



More information about the llvm-commits mailing list