1 //===- ObjectMemoryBuffer.h - SmallVector-backed MemoryBuffrer -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares a wrapper class to hold the memory into which an
11 // object will be generated.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_EXECUTIONENGINE_OBJECTMEMORYBUFFER_H
16 #define LLVM_EXECUTIONENGINE_OBJECTMEMORYBUFFER_H
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/Support/MemoryBuffer.h"
20 #include "llvm/Support/raw_ostream.h"
24 /// \brief SmallVector-backed MemoryBuffer instance.
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
30 class ObjectMemoryBuffer : public MemoryBuffer {
33 /// \brief Construct an ObjectMemoryBuffer from the given SmallVector r-value.
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.
40 ObjectMemoryBuffer(SmallVectorImpl<char> &&SV)
41 : SV(std::move(SV)), BufferName("<in-memory object>") {
42 init(this->SV.begin(), this->SV.end(), false);
45 /// \brief Construct a named ObjectMemoryBuffer from the given SmallVector
46 /// r-value and StringRef.
47 ObjectMemoryBuffer(SmallVectorImpl<char> &&SV, StringRef Name)
48 : SV(std::move(SV)), BufferName(Name) {
49 init(this->SV.begin(), this->SV.end(), false);
52 const char* getBufferIdentifier() const override { return BufferName.c_str(); }
54 BufferKind getBufferKind() const override { return MemoryBuffer_Malloc; }
57 SmallVector<char, 0> SV;
58 std::string BufferName;