LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjectBuffer.h
Go to the documentation of this file.
1 //===---- ObjectBuffer.h - Utility class to wrap object image memory -----===//
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/OwningPtr.h"
19 #include "llvm/ADT/SmallVector.h"
22 
23 namespace llvm {
24 
25 /// ObjectBuffer - This class acts as a container for the memory buffer used during
26 /// generation and loading of executable objects using MCJIT and RuntimeDyld. The
27 /// underlying memory for the object will be owned by the ObjectBuffer instance
28 /// throughout its lifetime. The getMemBuffer() method provides a way to create a
29 /// MemoryBuffer wrapper object instance to be owned by other classes (such as
30 /// ObjectFile) as needed, but the MemoryBuffer instance returned does not own the
31 /// actual memory it points to.
32 class ObjectBuffer {
33  virtual void anchor();
34 public:
37  virtual ~ObjectBuffer() {}
38 
39  /// getMemBuffer - Like MemoryBuffer::getMemBuffer() this function
40  /// returns a pointer to an object that is owned by the caller. However,
41  /// the caller does not take ownership of the underlying memory.
43  return MemoryBuffer::getMemBuffer(Buffer->getBuffer(), "", false);
44  }
45 
46  const char *getBufferStart() const { return Buffer->getBufferStart(); }
47  size_t getBufferSize() const { return Buffer->getBufferSize(); }
48  StringRef getBuffer() const { return Buffer->getBuffer(); }
49 
50 protected:
51  // The memory contained in an ObjectBuffer
53 };
54 
55 /// ObjectBufferStream - This class encapsulates the SmallVector and
56 /// raw_svector_ostream needed to generate an object using MC code emission
57 /// while providing a common ObjectBuffer interface for access to the
58 /// memory once the object has been generated.
60  virtual void anchor();
61 public:
63  virtual ~ObjectBufferStream() {}
64 
65  raw_ostream &getOStream() { return OS; }
66  void flush()
67  {
68  OS.flush();
69 
70  // Make the data accessible via the ObjectBuffer::Buffer
72  "",
73  false));
74  }
75 
76 protected:
77  SmallVector<char, 4096> SV; // Working buffer into which we JIT.
78  raw_svector_ostream OS; // streaming wrapper
79 };
80 
81 } // namespace llvm
82 
83 #endif
static MemoryBuffer * getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
size_t getBufferSize() const
Definition: ObjectBuffer.h:47
virtual ~ObjectBuffer()
Definition: ObjectBuffer.h:37
raw_svector_ostream OS
Definition: ObjectBuffer.h:78
const char * getBufferStart() const
Definition: ObjectBuffer.h:46
MemoryBuffer * getMemBuffer() const
Definition: ObjectBuffer.h:42
SmallVector< char, 4096 > SV
Definition: ObjectBuffer.h:77
raw_ostream & getOStream()
Definition: ObjectBuffer.h:65
OwningPtr< MemoryBuffer > Buffer
Definition: ObjectBuffer.h:52
pointer data()
data - Return a pointer to the vector's buffer, even if empty().
Definition: SmallVector.h:135
StringRef getBuffer() const
Definition: ObjectBuffer.h:48
ObjectBuffer(MemoryBuffer *Buf)
Definition: ObjectBuffer.h:36