15 #include "llvm/Support/SourceMgr.h"
16 #include "llvm/Support/raw_ostream.h"
23 raw_ostream &os, llvm::StringRef inputSplitMarker,
24 llvm::StringRef outputSplitMarker) {
26 if (inputSplitMarker.empty())
27 return processChunkBuffer(std::move(originalBuffer), os);
29 const int inputSplitMarkerLen = inputSplitMarker.size();
31 auto *origMemBuffer = originalBuffer.get();
33 const int checkLen = 2;
35 origMemBuffer->getBuffer().split(rawSourceBuffers,
36 inputSplitMarker.drop_back(checkLen));
37 if (rawSourceBuffers.empty())
41 llvm::SourceMgr fileSourceMgr;
42 fileSourceMgr.AddNewSourceBuffer(std::move(originalBuffer), SMLoc());
51 for (
auto buffer : rawSourceBuffers) {
59 buffer.starts_with(inputSplitMarker.take_back(checkLen)) &&
60 buffer.size() > checkLen && buffer[checkLen] !=
'0';
62 sourceBuffers.push_back(prev);
63 prev = buffer.drop_front(checkLen);
66 auto splitLoc = SMLoc::getFromPointer(buffer.data());
67 fileSourceMgr.PrintMessage(llvm::errs(), splitLoc,
68 llvm::SourceMgr::DK_Warning,
69 "near miss with file split marker");
70 prev = StringRef(prev.data(), prev.size() + inputSplitMarkerLen -
71 checkLen + buffer.size());
75 sourceBuffers.push_back(prev);
78 bool hadFailure =
false;
79 auto interleaveFn = [&](StringRef subBuffer) {
80 auto splitLoc = SMLoc::getFromPointer(subBuffer.data());
81 unsigned splitLine = fileSourceMgr.getLineAndColumn(splitLoc).first;
82 auto subMemBuffer = llvm::MemoryBuffer::getMemBufferCopy(
83 subBuffer, Twine(
"within split at ") +
84 origMemBuffer->getBufferIdentifier() +
":" +
85 Twine(splitLine) +
" offset ");
86 if (failed(processChunkBuffer(std::move(subMemBuffer), os)))
89 llvm::interleave(sourceBuffers, os, interleaveFn,
90 (llvm::Twine(outputSplitMarker) +
"\n").str());
93 return failure(hadFailure);
Include the generated interface declarations.
LogicalResult splitAndProcessBuffer(std::unique_ptr< llvm::MemoryBuffer > originalBuffer, ChunkBufferHandler processChunkBuffer, raw_ostream &os, llvm::StringRef inputSplitMarker=kDefaultSplitMarker, llvm::StringRef outputSplitMarker="")
Splits the specified buffer on a marker (// ----- by default), processes each chunk independently acc...