1 //===--- ObjectBuffer.h - Utility class to wrap object memory ---*- 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 // This file declares a wrapper class to hold the memory into which an
11 // object will be generated.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_EXECUTIONENGINE_OBJECTBUFFER_H
16 #define LLVM_EXECUTIONENGINE_OBJECTBUFFER_H
17 
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/Support/MemoryBuffer.h"
20 #include "llvm/Support/raw_ostream.h"
21 
22 namespace llvm {
23 
24 class ObjectMemoryBuffer : public MemoryBuffer {
25 public:
26   template <unsigned N>
ObjectMemoryBuffer(SmallVector<char,N> SV)27   ObjectMemoryBuffer(SmallVector<char, N> SV)
28     : SV(SV), BufferName("<in-memory object>") {
29     init(this->SV.begin(), this->SV.end(), false);
30   }
31 
32   template <unsigned N>
ObjectMemoryBuffer(SmallVector<char,N> SV,StringRef Name)33   ObjectMemoryBuffer(SmallVector<char, N> SV, StringRef Name)
34     : SV(SV), BufferName(Name) {
35     init(this->SV.begin(), this->SV.end(), false);
36   }
getBufferIdentifier()37   const char* getBufferIdentifier() const override { return BufferName.c_str(); }
38 
getBufferKind()39   BufferKind getBufferKind() const override { return MemoryBuffer_Malloc; }
40 
41 private:
42   SmallVector<char, 4096> SV;
43   std::string BufferName;
44 };
45 
46 } // namespace llvm
47 
48 #endif
49