• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- ByteStream.h - Reads stream data from a byte sequence ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_DEBUGINFO_CODEVIEW_BYTESTREAM_H
11 #define LLVM_DEBUGINFO_CODEVIEW_BYTESTREAM_H
12 
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/DebugInfo/CodeView/StreamInterface.h"
16 #include "llvm/Support/Error.h"
17 #include <cstdint>
18 #include <memory>
19 #include <type_traits>
20 
21 namespace llvm {
22 namespace codeview {
23 class StreamReader;
24 
25 template <bool Writable = false> class ByteStream : public StreamInterface {
26   typedef typename std::conditional<Writable, MutableArrayRef<uint8_t>,
27                                     ArrayRef<uint8_t>>::type ArrayType;
28 
29 public:
ByteStream()30   ByteStream() {}
ByteStream(ArrayType Data)31   explicit ByteStream(ArrayType Data) : Data(Data) {}
~ByteStream()32   ~ByteStream() override {}
33 
34   Error readBytes(uint32_t Offset, uint32_t Size,
35                   ArrayRef<uint8_t> &Buffer) const override;
36   Error readLongestContiguousChunk(uint32_t Offset,
37                                    ArrayRef<uint8_t> &Buffer) const override;
38 
39   Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Buffer) const override;
40 
41   uint32_t getLength() const override;
42 
43   Error commit() const override;
44 
data()45   ArrayRef<uint8_t> data() const { return Data; }
46   StringRef str() const;
47 
48 private:
49   ArrayType Data;
50 };
51 
52 extern template class ByteStream<true>;
53 extern template class ByteStream<false>;
54 
55 } // end namespace pdb
56 } // end namespace llvm
57 
58 #endif // LLVM_DEBUGINFO_CODEVIEW_BYTESTREAM_H
59