1 //===- SmallVectorMemoryBuffer.h --------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file declares a wrapper class to hold the memory into which an
10 // object will be generated.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_EXECUTIONENGINE_OBJECTMEMORYBUFFER_H
15 #define LLVM_EXECUTIONENGINE_OBJECTMEMORYBUFFER_H
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/Support/MemoryBuffer.h"
19 #include "llvm/Support/raw_ostream.h"
23 /// SmallVector-backed MemoryBuffer instance.
25 /// This class enables efficient construction of MemoryBuffers from SmallVector
26 /// instances. This is useful for MCJIT and Orc, where object files are streamed
27 /// into SmallVectors, then inspected using ObjectFile (which takes a
29 class SmallVectorMemoryBuffer
: public MemoryBuffer
{
31 /// Construct an SmallVectorMemoryBuffer from the given SmallVector
34 /// FIXME: It'd be nice for this to be a non-templated constructor taking a
35 /// SmallVectorImpl here instead of a templated one taking a SmallVector<N>,
36 /// but SmallVector's move-construction/assignment currently only take
37 /// SmallVectors. If/when that is fixed we can simplify this constructor and
38 /// the following one.
39 SmallVectorMemoryBuffer(SmallVectorImpl
<char> &&SV
)
40 : SV(std::move(SV
)), BufferName("<in-memory object>") {
41 init(this->SV
.begin(), this->SV
.end(), false);
44 /// Construct a named SmallVectorMemoryBuffer from the given
45 /// SmallVector r-value and StringRef.
46 SmallVectorMemoryBuffer(SmallVectorImpl
<char> &&SV
, StringRef Name
)
47 : SV(std::move(SV
)), BufferName(Name
) {
48 init(this->SV
.begin(), this->SV
.end(), false);
52 ~SmallVectorMemoryBuffer() override
;
54 StringRef
getBufferIdentifier() const override
{ return BufferName
; }
56 BufferKind
getBufferKind() const override
{ return MemoryBuffer_Malloc
; }
59 SmallVector
<char, 0> SV
;
60 std::string BufferName
;