LLVM  8.0.1
SmallVectorMemoryBuffer.h
Go to the documentation of this file.
1 //===- SmallVectorMemoryBuffer.h --------------------------------*- 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_OBJECTMEMORYBUFFER_H
16 #define LLVM_EXECUTIONENGINE_OBJECTMEMORYBUFFER_H
17 
18 #include "llvm/ADT/SmallVector.h"
21 
22 namespace llvm {
23 
24 /// SmallVector-backed MemoryBuffer instance.
25 ///
26 /// This class enables efficient construction of MemoryBuffers from SmallVector
27 /// instances. This is useful for MCJIT and Orc, where object files are streamed
28 /// into SmallVectors, then inspected using ObjectFile (which takes a
29 /// MemoryBuffer).
31 public:
32  /// Construct an SmallVectorMemoryBuffer from the given SmallVector
33  /// r-value.
34  ///
35  /// FIXME: It'd be nice for this to be a non-templated constructor taking a
36  /// SmallVectorImpl here instead of a templated one taking a SmallVector<N>,
37  /// but SmallVector's move-construction/assignment currently only take
38  /// SmallVectors. If/when that is fixed we can simplify this constructor and
39  /// the following one.
41  : SV(std::move(SV)), BufferName("<in-memory object>") {
42  init(this->SV.begin(), this->SV.end(), false);
43  }
44 
45  /// Construct a named SmallVectorMemoryBuffer from the given
46  /// SmallVector r-value and StringRef.
48  : SV(std::move(SV)), BufferName(Name) {
49  init(this->SV.begin(), this->SV.end(), false);
50  }
51 
52  // Key function.
53  ~SmallVectorMemoryBuffer() override;
54 
55  StringRef getBufferIdentifier() const override { return BufferName; }
56 
57  BufferKind getBufferKind() const override { return MemoryBuffer_Malloc; }
58 
59 private:
61  std::string BufferName;
62 };
63 
64 } // namespace llvm
65 
66 #endif
void init(const char *BufStart, const char *BufEnd, bool RequiresNullTerminator)
init - Initialize this MemoryBuffer as a reference to externally allocated memory, memory that we know is already null terminated.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
SmallVectorMemoryBuffer(SmallVectorImpl< char > &&SV, StringRef Name)
Construct a named SmallVectorMemoryBuffer from the given SmallVector r-value and StringRef.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Definition: BitVector.h:938
SmallVectorMemoryBuffer(SmallVectorImpl< char > &&SV)
Construct an SmallVectorMemoryBuffer from the given SmallVector r-value.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:129
StringRef getBufferIdentifier() const override
Return an identifier for this buffer, typically the filename it was read from.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:42
SmallVector-backed MemoryBuffer instance.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:133
BufferKind
The kind of memory backing used to support the MemoryBuffer.
Definition: MemoryBuffer.h:140
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
BufferKind getBufferKind() const override
Return information on the memory mechanism used to support the MemoryBuffer.