LLVM 20.0.0git
SmallVectorMemoryBuffer.h
Go to the documentation of this file.
1//===- SmallVectorMemoryBuffer.h --------------------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares a wrapper class to hold the memory into which an
10// object will be generated.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_SUPPORT_SMALLVECTORMEMORYBUFFER_H
15#define LLVM_SUPPORT_SMALLVECTORMEMORYBUFFER_H
16
20
21namespace llvm {
22
23/// SmallVector-backed MemoryBuffer instance.
24///
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
28/// MemoryBuffer).
30public:
31 /// Construct a SmallVectorMemoryBuffer from the given SmallVector r-value.
33 bool RequiresNullTerminator = true)
34 : SmallVectorMemoryBuffer(std::move(SV), "<in-memory object>",
35 RequiresNullTerminator) {}
36
37 /// Construct a named SmallVectorMemoryBuffer from the given SmallVector
38 /// r-value and StringRef.
40 bool RequiresNullTerminator = true)
41 : SV(std::move(SV)), BufferName(std::string(Name)) {
42 if (RequiresNullTerminator) {
43 this->SV.push_back('\0');
44 this->SV.pop_back();
45 }
46 init(this->SV.begin(), this->SV.end(), false);
47 }
48
49 // Key function.
51
52 StringRef getBufferIdentifier() const override { return BufferName; }
53
54 BufferKind getBufferKind() const override { return MemoryBuffer_Malloc; }
55
56private:
58 std::string BufferName;
59};
60
61} // namespace llvm
62
63#endif
std::string Name
This file defines the SmallVector class.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:51
BufferKind
The kind of memory backing used to support the MemoryBuffer.
Definition: MemoryBuffer.h:165
void init(const char *BufStart, const char *BufEnd, bool RequiresNullTerminator)
init - Initialize this MemoryBuffer as a reference to externally allocated memory,...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
SmallVector-backed MemoryBuffer instance.
SmallVectorMemoryBuffer(SmallVectorImpl< char > &&SV, bool RequiresNullTerminator=true)
Construct a SmallVectorMemoryBuffer from the given SmallVector r-value.
StringRef getBufferIdentifier() const override
Return an identifier for this buffer, typically the filename it was read from.
SmallVectorMemoryBuffer(SmallVectorImpl< char > &&SV, StringRef Name, bool RequiresNullTerminator=true)
Construct a named SmallVectorMemoryBuffer from the given SmallVector r-value and StringRef.
BufferKind getBufferKind() const override
Return information on the memory mechanism used to support the MemoryBuffer.
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1873
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858