本文整理汇总了C++中MemoryBuffer::getBufferEnd方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryBuffer::getBufferEnd方法的具体用法?C++ MemoryBuffer::getBufferEnd怎么用?C++ MemoryBuffer::getBufferEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryBuffer
的用法示例。
在下文中一共展示了MemoryBuffer::getBufferEnd方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例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
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";
}
示例3: 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();
}
}
示例4: 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";
}
示例5: 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);
}
示例6: 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();
}
}
示例7: 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, const Twine &Msg,
const char *Type, bool ShowLine) 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;
std::string LineStr;
if (ShowLine) {
// Get the end of the line.
const char *LineEnd = Loc.getPointer();
while (LineEnd != CurMB->getBufferEnd() &&
LineEnd[0] != '\n' && LineEnd[0] != '\r')
++LineEnd;
LineStr = std::string(LineStart, LineEnd);
}
std::string PrintedMsg;
raw_string_ostream OS(PrintedMsg);
if (Type)
OS << Type << ": ";
OS << Msg;
return SMDiagnostic(*this, Loc,
CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
Loc.getPointer()-LineStart, OS.str(),
LineStr, ShowLine);
}
示例8: parse
ErrorOr<unique_ptr<Executable>> parseExecutable(MemoryBuffer& executableCode)
{
auto start = reinterpret_cast<const uint8_t*>(executableCode.getBufferStart());
auto end = reinterpret_cast<const uint8_t*>(executableCode.getBufferEnd());
return Executable::parse(start, end);
}