本文整理汇总了C++中MemoryBuffer::getBufferStart方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryBuffer::getBufferStart方法的具体用法?C++ MemoryBuffer::getBufferStart怎么用?C++ MemoryBuffer::getBufferStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryBuffer
的用法示例。
在下文中一共展示了MemoryBuffer::getBufferStart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DetectEOL
/// Detect the likely line ending style of \p FromFile by examining the first
/// newline found within it.
static StringRef DetectEOL(const MemoryBuffer &FromFile) {
// detect what line endings the file uses, so that added content does not mix
// the style
const char *Pos = strchr(FromFile.getBufferStart(), '\n');
if (Pos == NULL)
return "\n";
if (Pos + 1 < FromFile.getBufferEnd() && Pos[1] == '\r')
return "\n\r";
if (Pos - 1 >= FromFile.getBufferStart() && Pos[-1] == '\r')
return "\r\n";
return "\n";
}
示例2: DetectEOL
/// Detect the likely line ending style of \p FromFile by examining the first
/// newline found within it.
static StringRef DetectEOL(const MemoryBuffer &FromFile) {
// Detect what line endings the file uses, so that added content does not mix
// the style. We need to check for "\r\n" first because "\n\r" will match
// "\r\n\r\n".
const char *Pos = strchr(FromFile.getBufferStart(), '\n');
if (!Pos)
return "\n";
if (Pos - 1 >= FromFile.getBufferStart() && Pos[-1] == '\r')
return "\r\n";
if (Pos + 1 < FromFile.getBufferEnd() && Pos[1] == '\r')
return "\n\r";
return "\n";
}
示例3: Buffer
line_iterator::line_iterator(const MemoryBuffer &Buffer, bool SkipBlanks,
char CommentMarker)
: Buffer(Buffer.getBufferSize() ? &Buffer : nullptr),
CommentMarker(CommentMarker), SkipBlanks(SkipBlanks), LineNumber(1),
CurrentLine(Buffer.getBufferSize() ? Buffer.getBufferStart() : nullptr,
0) {
// Ensure that if we are constructed on a non-empty memory buffer that it is
// a null terminated buffer.
if (Buffer.getBufferSize()) {
assert(Buffer.getBufferEnd()[0] == '\0');
// Make sure we don't skip a leading newline if we're keeping blanks
if (SkipBlanks || !isAtLineEnd(Buffer.getBufferStart()))
advance();
}
}
示例4: WriteBundle
void WriteBundle(raw_fd_ostream &OS, MemoryBuffer &Input) final {
Module *M = AuxModule.get();
// Create the new section name, it will consist of the reserved prefix
// concatenated with the triple.
std::string SectionName = OFFLOAD_BUNDLER_MAGIC_STR;
SectionName += CurrentTriple;
// Create the constant with the content of the section. For the input we are
// bundling into (the host input), this is just a place-holder, so a single
// byte is sufficient.
assert(HostInputIndex != ~0u && "Host input index undefined??");
Constant *Content;
if (NumberOfProcessedInputs == HostInputIndex + 1) {
uint8_t Byte[] = {0};
Content = ConstantDataArray::get(VMContext, Byte);
} else
Content = ConstantDataArray::get(
VMContext, ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(
Input.getBufferStart()),
Input.getBufferSize()));
// Create the global in the desired section. We don't want these globals in
// the symbol table, so we mark them private.
auto *GV = new GlobalVariable(*M, Content->getType(), /*IsConstant=*/true,
GlobalVariable::PrivateLinkage, Content);
GV->setSection(SectionName);
}
示例5: parse
bool CodeGenCoverage::parse(MemoryBuffer &Buffer, StringRef BackendName) {
const char *CurPtr = Buffer.getBufferStart();
while (CurPtr != Buffer.getBufferEnd()) {
// Read the backend name from the input.
const char *LexedBackendName = CurPtr;
while (*CurPtr++ != 0)
;
if (CurPtr == Buffer.getBufferEnd())
return false; // Data is invalid, expected rule id's to follow.
bool IsForThisBackend = BackendName.equals(LexedBackendName);
while (CurPtr != Buffer.getBufferEnd()) {
if (std::distance(CurPtr, Buffer.getBufferEnd()) < 8)
return false; // Data is invalid. Not enough bytes for another rule id.
uint64_t RuleID = support::endian::read64(CurPtr, support::native);
CurPtr += 8;
// ~0ull terminates the rule id list.
if (RuleID == ~0ull)
break;
// Anything else, is recorded or ignored depending on whether it's
// intended for the backend we're interested in.
if (IsForThisBackend)
setCovered(RuleID);
}
}
return true;
}
示例6: printFile
static void printFile(const sys::Path *err)
{
std::string ErrMsg;
ErrMsg.clear();
MemoryBuffer *buf = MemoryBuffer::getFile(err->c_str(), &ErrMsg);
errs().write(buf->getBufferStart(), buf->getBufferSize());
delete buf;
}
示例7: hasFormat
bool TextInstrProfReader::hasFormat(const MemoryBuffer &Buffer) {
// Verify that this really looks like plain ASCII text by checking a
// 'reasonable' number of characters (up to profile magic size).
size_t count = std::min(Buffer.getBufferSize(), sizeof(uint64_t));
StringRef buffer = Buffer.getBufferStart();
return count == 0 || std::all_of(buffer.begin(), buffer.begin() + count,
[](char c) { return ::isprint(c) || ::isspace(c); });
}
示例8:
bool RawInstrProfReader<IntPtrT>::hasFormat(const MemoryBuffer &DataBuffer) {
if (DataBuffer.getBufferSize() < sizeof(uint64_t))
return false;
uint64_t Magic =
*reinterpret_cast<const uint64_t *>(DataBuffer.getBufferStart());
return RawInstrProf::getMagic<IntPtrT>() == Magic ||
sys::getSwappedBytes(RawInstrProf::getMagic<IntPtrT>()) == Magic;
}
示例9: getNewUninitMemBuffer
/// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
/// copying the contents and taking ownership of it. This has no requirements
/// on EndPtr[0].
MemoryBuffer *MemoryBuffer::getMemBufferCopy(StringRef InputData,
StringRef BufferName) {
MemoryBuffer *Buf = getNewUninitMemBuffer(InputData.size(), BufferName);
if (!Buf) return 0;
memcpy(const_cast<char*>(Buf->getBufferStart()), InputData.data(),
InputData.size());
return Buf;
}
示例10: OutputContentUpTo
/// Writes out bytes from \p FromFile, starting at \p NextToWrite and ending at
/// \p WriteTo - 1.
void InclusionRewriter::OutputContentUpTo(const MemoryBuffer &FromFile,
unsigned &WriteFrom, unsigned WriteTo,
StringRef EOL, int &Line,
bool EnsureNewline) {
if (WriteTo <= WriteFrom)
return;
OS.write(FromFile.getBufferStart() + WriteFrom, WriteTo - WriteFrom);
// count lines manually, it's faster than getPresumedLoc()
Line += std::count(FromFile.getBufferStart() + WriteFrom,
FromFile.getBufferStart() + WriteTo, '\n');
if (EnsureNewline) {
char LastChar = FromFile.getBufferStart()[WriteTo - 1];
if (LastChar != '\n' && LastChar != '\r')
OS << EOL;
}
WriteFrom = WriteTo;
}
示例11: hasFormat
bool IndexedInstrProfReader::hasFormat(const MemoryBuffer &DataBuffer) {
if (DataBuffer.getBufferSize() < 8)
return false;
using namespace support;
uint64_t Magic =
endian::read<uint64_t, little, aligned>(DataBuffer.getBufferStart());
return Magic == IndexedInstrProf::Magic;
}
示例12: OutputContentUpTo
/// Writes out bytes from \p FromFile, starting at \p NextToWrite and ending at
/// \p WriteTo - 1.
void InclusionRewriter::OutputContentUpTo(const MemoryBuffer &FromFile,
unsigned &WriteFrom, unsigned WriteTo,
StringRef LocalEOL, int &Line,
bool EnsureNewline) {
if (WriteTo <= WriteFrom)
return;
if (&FromFile == PredefinesBuffer) {
// Ignore the #defines of the predefines buffer.
WriteFrom = WriteTo;
return;
}
// If we would output half of a line ending, advance one character to output
// the whole line ending. All buffers are null terminated, so looking ahead
// one byte is safe.
if (LocalEOL.size() == 2 &&
LocalEOL[0] == (FromFile.getBufferStart() + WriteTo)[-1] &&
LocalEOL[1] == (FromFile.getBufferStart() + WriteTo)[0])
WriteTo++;
StringRef TextToWrite(FromFile.getBufferStart() + WriteFrom,
WriteTo - WriteFrom);
if (MainEOL == LocalEOL) {
OS << TextToWrite;
// count lines manually, it's faster than getPresumedLoc()
Line += TextToWrite.count(LocalEOL);
if (EnsureNewline && !TextToWrite.endswith(LocalEOL))
OS << MainEOL;
} else {
// Output the file one line at a time, rewriting the line endings as we go.
StringRef Rest = TextToWrite;
while (!Rest.empty()) {
StringRef LineText;
std::tie(LineText, Rest) = Rest.split(LocalEOL);
OS << LineText;
Line++;
if (!Rest.empty())
OS << MainEOL;
}
if (TextToWrite.endswith(LocalEOL) || EnsureNewline)
OS << MainEOL;
}
WriteFrom = WriteTo;
}
示例13: fillHeader
// Write one member out to the file.
bool
Archive::writeMember(
const ArchiveMember& member,
raw_fd_ostream& ARFile,
std::string* ErrMsg
) {
uint64_t filepos = ARFile.tell();
filepos -= 8;
// Get the data and its size either from the
// member's in-memory data or directly from the file.
size_t fSize = member.getSize();
const char *data = (const char*)member.getData();
MemoryBuffer *mFile = 0;
if (!data) {
ErrorOr<std::unique_ptr<MemoryBuffer> > FileOrErr =
MemoryBuffer::getFile(member.getPath());
if (!FileOrErr) {
if (ErrMsg)
*ErrMsg = FileOrErr.getError().message();
return true;
}
mFile = FileOrErr.get().release();
data = mFile->getBufferStart();
fSize = mFile->getBufferSize();
}
int hdrSize = fSize;
// Compute the fields of the header
ArchiveMemberHeader Hdr;
bool writeLongName = fillHeader(member,Hdr,hdrSize);
// Write header to archive file
ARFile.write((char*)&Hdr, sizeof(Hdr));
// Write the long filename if its long
if (writeLongName) {
StringRef Name = sys::path::filename(member.getPath());
ARFile.write(Name.data(), Name.size());
}
// Write the (possibly compressed) member's content to the file.
ARFile.write(data,fSize);
// Make sure the member is an even length
if ((ARFile.tell() & 1) == 1)
ARFile << ARFILE_PAD;
// Close the mapped file if it was opened
delete mFile;
return false;
}
示例14: Buffer
line_iterator::line_iterator(const MemoryBuffer &Buffer, char CommentMarker)
: Buffer(Buffer.getBufferSize() ? &Buffer : nullptr),
CommentMarker(CommentMarker), LineNumber(1),
CurrentLine(Buffer.getBufferSize() ? Buffer.getBufferStart() : nullptr,
0) {
// Ensure that if we are constructed on a non-empty memory buffer that it is
// a null terminated buffer.
if (Buffer.getBufferSize()) {
assert(Buffer.getBufferEnd()[0] == '\0');
advance();
}
}
示例15: GetMessage
/// GetMessage - Return an SMDiagnostic at the specified location with the
/// specified string.
///
/// @param Type - If non-null, the kind of message (e.g., "error") which is
/// prefixed to the message.
SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
const Twine &Msg,
ArrayRef<SMRange> Ranges) const {
// First thing to do: find the current buffer containing the specified
// location.
int CurBuf = FindBufferContainingLoc(Loc);
assert(CurBuf != -1 && "Invalid or unspecified location!");
MemoryBuffer *CurMB = getBufferInfo(CurBuf).Buffer;
// Scan backward to find the start of the line.
const char *LineStart = Loc.getPointer();
while (LineStart != CurMB->getBufferStart() &&
LineStart[-1] != '\n' && LineStart[-1] != '\r')
--LineStart;
// Get the end of the line.
const char *LineEnd = Loc.getPointer();
while (LineEnd != CurMB->getBufferEnd() &&
LineEnd[0] != '\n' && LineEnd[0] != '\r')
++LineEnd;
std::string LineStr(LineStart, LineEnd);
// Convert any ranges to column ranges that only intersect the line of the
// location.
SmallVector<std::pair<unsigned, unsigned>, 4> ColRanges;
for (unsigned i = 0, e = Ranges.size(); i != e; ++i) {
SMRange R = Ranges[i];
if (!R.isValid()) continue;
// If the line doesn't contain any part of the range, then ignore it.
if (R.Start.getPointer() > LineEnd || R.End.getPointer() < LineStart)
continue;
// Ignore pieces of the range that go onto other lines.
if (R.Start.getPointer() < LineStart)
R.Start = SMLoc::getFromPointer(LineStart);
if (R.End.getPointer() > LineEnd)
R.End = SMLoc::getFromPointer(LineEnd);
// Translate from SMLoc ranges to column ranges.
ColRanges.push_back(std::make_pair(R.Start.getPointer()-LineStart,
R.End.getPointer()-LineStart));
}
return SMDiagnostic(*this, Loc,
CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
Loc.getPointer()-LineStart, Kind, Msg.str(),
LineStr, ColRanges);
}