xref: /freebsd/contrib/llvm-project/lldb/include/lldb/Utility/DataBufferLLVM.h (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
1 //===--- DataBufferLLVM.h ---------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_UTILITY_DATABUFFERLLVM_H
10 #define LLDB_UTILITY_DATABUFFERLLVM_H
11 
12 #include "lldb/Utility/DataBuffer.h"
13 #include "lldb/lldb-types.h"
14 
15 #include <cstdint>
16 #include <memory>
17 
18 namespace llvm {
19 class WritableMemoryBuffer;
20 class MemoryBuffer;
21 class Twine;
22 } // namespace llvm
23 
24 namespace lldb_private {
25 class FileSystem;
26 
27 class DataBufferLLVM : public DataBuffer {
28 public:
29   ~DataBufferLLVM() override;
30 
31   const uint8_t *GetBytesImpl() const override;
32   lldb::offset_t GetByteSize() const override;
33 
34   /// LLVM RTTI support.
35   /// {
36   static char ID;
isA(const void * ClassID)37   bool isA(const void *ClassID) const override {
38     return ClassID == &ID || DataBuffer::isA(ClassID);
39   }
classof(const DataBuffer * data_buffer)40   static bool classof(const DataBuffer *data_buffer) {
41     return data_buffer->isA(&ID);
42   }
43   /// }
44 
45   /// Construct a DataBufferLLVM from \p Buffer.  \p Buffer must be a valid
46   /// pointer.
47   explicit DataBufferLLVM(std::unique_ptr<llvm::MemoryBuffer> Buffer);
48 
49 protected:
50   std::unique_ptr<llvm::MemoryBuffer> Buffer;
51 };
52 
53 class WritableDataBufferLLVM : public WritableDataBuffer {
54 public:
55   ~WritableDataBufferLLVM() override;
56 
57   const uint8_t *GetBytesImpl() const override;
58   lldb::offset_t GetByteSize() const override;
59 
60   /// LLVM RTTI support.
61   /// {
62   static char ID;
isA(const void * ClassID)63   bool isA(const void *ClassID) const override {
64     return ClassID == &ID || WritableDataBuffer::isA(ClassID);
65   }
classof(const DataBuffer * data_buffer)66   static bool classof(const DataBuffer *data_buffer) {
67     return data_buffer->isA(&ID);
68   }
69   /// }
70 
71   /// Construct a DataBufferLLVM from \p Buffer.  \p Buffer must be a valid
72   /// pointer.
73   explicit WritableDataBufferLLVM(
74       std::unique_ptr<llvm::WritableMemoryBuffer> Buffer);
75 
76 protected:
77   std::unique_ptr<llvm::WritableMemoryBuffer> Buffer;
78 };
79 } // namespace lldb_private
80 
81 #endif
82