|
22 | 22 | #include "llvm/ExecutionEngine/JITSymbol.h"
|
23 | 23 | #include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h"
|
24 | 24 | #include "llvm/Support/Allocator.h"
|
| 25 | +#include "llvm/Support/BinaryStreamReader.h" |
| 26 | +#include "llvm/Support/BinaryStreamWriter.h" |
25 | 27 | #include "llvm/Support/Endian.h"
|
26 | 28 | #include "llvm/Support/Error.h"
|
27 | 29 | #include "llvm/Support/FormatVariadic.h"
|
@@ -1031,13 +1033,43 @@ class LinkGraph {
|
1031 | 1033 | AlignmentOffset);
|
1032 | 1034 | }
|
1033 | 1035 |
|
| 1036 | + /// Create a content block with initially mutable data of the given size. |
| 1037 | + /// Content will be allocated via the LinkGraph's allocateBuffer method. |
| 1038 | + /// By default the memory will be zero-initialized. Passing false for |
| 1039 | + /// ZeroInitialize will prevent this. |
| 1040 | + Block &createMutableContentBlock(Section &Parent, size_t ContentSize, |
| 1041 | + orc::ExecutorAddr Address, |
| 1042 | + uint64_t Alignment, uint64_t AlignmentOffset, |
| 1043 | + bool ZeroInitialize = true) { |
| 1044 | + auto Content = allocateContent(ContentSize); |
| 1045 | + if (ZeroInitialize) |
| 1046 | + memset(Content.data(), 0, Content.size()); |
| 1047 | + return createBlock(Parent, Content, Address, Alignment, AlignmentOffset); |
| 1048 | + } |
| 1049 | + |
1034 | 1050 | /// Create a zero-fill block.
|
1035 | 1051 | Block &createZeroFillBlock(Section &Parent, orc::ExecutorAddrDiff Size,
|
1036 | 1052 | orc::ExecutorAddr Address, uint64_t Alignment,
|
1037 | 1053 | uint64_t AlignmentOffset) {
|
1038 | 1054 | return createBlock(Parent, Size, Address, Alignment, AlignmentOffset);
|
1039 | 1055 | }
|
1040 | 1056 |
|
| 1057 | + /// Returns a BinaryStreamReader for the given block. |
| 1058 | + BinaryStreamReader getBlockContentReader(Block &B) { |
| 1059 | + ArrayRef<uint8_t> C( |
| 1060 | + reinterpret_cast<const uint8_t *>(B.getContent().data()), B.getSize()); |
| 1061 | + return BinaryStreamReader(C, getEndianness()); |
| 1062 | + } |
| 1063 | + |
| 1064 | + /// Returns a BinaryStreamWriter for the given block. |
| 1065 | + /// This will call getMutableContent to obtain mutable content for the block. |
| 1066 | + BinaryStreamWriter getBlockContentWriter(Block &B) { |
| 1067 | + MutableArrayRef<uint8_t> C( |
| 1068 | + reinterpret_cast<uint8_t *>(B.getMutableContent(*this).data()), |
| 1069 | + B.getSize()); |
| 1070 | + return BinaryStreamWriter(C, getEndianness()); |
| 1071 | + } |
| 1072 | + |
1041 | 1073 | /// Cache type for the splitBlock function.
|
1042 | 1074 | using SplitBlockCache = Optional<SmallVector<Symbol *, 8>>;
|
1043 | 1075 |
|
|
0 commit comments