本文整理汇总了C++中llvm::BitstreamCursor::EnterSubBlock方法的典型用法代码示例。如果您正苦于以下问题:C++ BitstreamCursor::EnterSubBlock方法的具体用法?C++ BitstreamCursor::EnterSubBlock怎么用?C++ BitstreamCursor::EnterSubBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类llvm::BitstreamCursor
的用法示例。
在下文中一共展示了BitstreamCursor::EnterSubBlock方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: enterTopLevelModuleBlock
static bool enterTopLevelModuleBlock(llvm::BitstreamCursor &cursor,
unsigned ID,
bool shouldReadBlockInfo = true) {
auto next = cursor.advance();
if (next.Kind != llvm::BitstreamEntry::SubBlock)
return false;
if (next.ID == llvm::bitc::BLOCKINFO_BLOCK_ID) {
if (shouldReadBlockInfo) {
if (cursor.ReadBlockInfoBlock())
return false;
} else {
if (cursor.SkipBlock())
return false;
}
return enterTopLevelModuleBlock(cursor, ID, false);
}
if (next.ID != ID)
return false;
cursor.EnterSubBlock(ID);
return true;
}
示例2: readMetaBlock
LoadResult DiagLoader::readMetaBlock(llvm::BitstreamCursor &Stream) {
if (Stream.EnterSubBlock(lfort::serialized_diags::BLOCK_META)) {
reportInvalidFile("Malformed metadata block");
return Failure;
}
bool versionChecked = false;
while (true) {
unsigned blockOrCode = 0;
StreamResult Res = readToNextRecordOrBlock(Stream, "Metadata Block",
blockOrCode);
switch(Res) {
case Read_EndOfStream:
llvm_unreachable("EndOfStream handled by readToNextRecordOrBlock");
case Read_Failure:
return Failure;
case Read_Record:
break;
case Read_BlockBegin:
if (Stream.SkipBlock()) {
reportInvalidFile("Malformed metadata block");
return Failure;
}
case Read_BlockEnd:
if (!versionChecked) {
reportInvalidFile("Diagnostics file does not contain version"
" information");
return Failure;
}
return Success;
}
RecordData Record;
const char *Blob;
unsigned BlobLen;
unsigned recordID = Stream.ReadRecord(blockOrCode, Record, &Blob, &BlobLen);
if (recordID == serialized_diags::RECORD_VERSION) {
if (Record.size() < 1) {
reportInvalidFile("malformed VERSION identifier in diagnostics file");
return Failure;
}
if (Record[0] > MaxSupportedVersion) {
reportInvalidFile("diagnosics file is a newer version than the one "
"supported");
return Failure;
}
versionChecked = true;
}
}
}
示例3: readCommentBlock
bool ModuleFile::readCommentBlock(llvm::BitstreamCursor &cursor) {
cursor.EnterSubBlock(COMMENT_BLOCK_ID);
SmallVector<uint64_t, 4> scratch;
StringRef blobData;
while (true) {
auto next = cursor.advance();
switch (next.Kind) {
case llvm::BitstreamEntry::EndBlock:
return true;
case llvm::BitstreamEntry::Error:
return false;
case llvm::BitstreamEntry::SubBlock:
// Unknown sub-block, which this version of the compiler won't use.
if (cursor.SkipBlock())
return false;
break;
case llvm::BitstreamEntry::Record:
scratch.clear();
unsigned kind = cursor.readRecord(next.ID, scratch, &blobData);
switch (kind) {
case comment_block::DECL_COMMENTS:
DeclCommentTable = readDeclCommentTable(scratch, blobData);
break;
case comment_block::GROUP_NAMES:
GroupNamesMap = readGroupTable(scratch, blobData);
break;
default:
// Unknown index kind, which this version of the compiler won't use.
break;
}
break;
}
}
}
示例4: error_code
std::error_code
SerializedDiagnosticReader::readMetaBlock(llvm::BitstreamCursor &Stream) {
if (Stream.EnterSubBlock(clang::serialized_diags::BLOCK_META))
return SDError::MalformedMetadataBlock;
bool VersionChecked = false;
while (true) {
unsigned BlockOrCode = 0;
llvm::ErrorOr<Cursor> Res = skipUntilRecordOrBlock(Stream, BlockOrCode);
if (!Res)
Res.getError();
switch (Res.get()) {
case Cursor::Record:
break;
case Cursor::BlockBegin:
if (Stream.SkipBlock())
return SDError::MalformedMetadataBlock;
case Cursor::BlockEnd:
if (!VersionChecked)
return SDError::MissingVersion;
return std::error_code();
}
SmallVector<uint64_t, 1> Record;
unsigned RecordID = Stream.readRecord(BlockOrCode, Record);
if (RecordID == RECORD_VERSION) {
if (Record.size() < 1)
return SDError::MissingVersion;
if (Record[0] > VersionNumber)
return SDError::VersionMismatch;
VersionChecked = true;
}
}
}
示例5: readIndexBlock
bool ModuleFile::readIndexBlock(llvm::BitstreamCursor &cursor) {
cursor.EnterSubBlock(INDEX_BLOCK_ID);
SmallVector<uint64_t, 4> scratch;
StringRef blobData;
while (true) {
auto next = cursor.advance();
switch (next.Kind) {
case llvm::BitstreamEntry::EndBlock:
return true;
case llvm::BitstreamEntry::Error:
return false;
case llvm::BitstreamEntry::SubBlock:
// Unknown sub-block, which this version of the compiler won't use.
if (cursor.SkipBlock())
return false;
break;
case llvm::BitstreamEntry::Record:
scratch.clear();
blobData = {};
unsigned kind = cursor.readRecord(next.ID, scratch, &blobData);
switch (kind) {
case index_block::DECL_OFFSETS:
assert(blobData.empty());
Decls.assign(scratch.begin(), scratch.end());
break;
case index_block::DECL_CONTEXT_OFFSETS:
assert(blobData.empty());
DeclContexts.assign(scratch.begin(), scratch.end());
break;
case index_block::TYPE_OFFSETS:
assert(blobData.empty());
Types.assign(scratch.begin(), scratch.end());
break;
case index_block::IDENTIFIER_OFFSETS:
assert(blobData.empty());
Identifiers.assign(scratch.begin(), scratch.end());
break;
case index_block::TOP_LEVEL_DECLS:
TopLevelDecls = readDeclTable(scratch, blobData);
break;
case index_block::OPERATORS:
OperatorDecls = readDeclTable(scratch, blobData);
break;
case index_block::EXTENSIONS:
ExtensionDecls = readDeclTable(scratch, blobData);
break;
case index_block::CLASS_MEMBERS:
ClassMembersByName = readDeclTable(scratch, blobData);
break;
case index_block::OPERATOR_METHODS:
OperatorMethodDecls = readDeclTable(scratch, blobData);
break;
case index_block::OBJC_METHODS:
ObjCMethods = readObjCMethodTable(scratch, blobData);
break;
case index_block::ENTRY_POINT:
assert(blobData.empty());
setEntryPointClassID(scratch.front());
break;
case index_block::LOCAL_TYPE_DECLS:
LocalTypeDecls = readLocalDeclTable(scratch, blobData);
break;
case index_block::LOCAL_DECL_CONTEXT_OFFSETS:
assert(blobData.empty());
LocalDeclContexts.assign(scratch.begin(), scratch.end());
break;
case index_block::NORMAL_CONFORMANCE_OFFSETS:
assert(blobData.empty());
NormalConformances.assign(scratch.begin(), scratch.end());
break;
default:
// Unknown index kind, which this version of the compiler won't use.
break;
}
break;
}
}
}
示例6: if
static ValidationInfo
validateControlBlock(llvm::BitstreamCursor &cursor,
SmallVectorImpl<uint64_t> &scratch,
ExtendedValidationInfo *extendedInfo) {
// The control block is malformed until we've at least read a major version
// number.
ValidationInfo result;
bool versionSeen = false;
auto next = cursor.advance();
while (next.Kind != llvm::BitstreamEntry::EndBlock) {
if (next.Kind == llvm::BitstreamEntry::Error) {
result.status = Status::Malformed;
return result;
}
if (next.Kind == llvm::BitstreamEntry::SubBlock) {
if (next.ID == OPTIONS_BLOCK_ID && extendedInfo) {
cursor.EnterSubBlock(OPTIONS_BLOCK_ID);
if (!readOptionsBlock(cursor, scratch, *extendedInfo)) {
result.status = Status::Malformed;
return result;
}
} else {
// Unknown metadata sub-block, possibly for use by a future version of
// the module format.
if (cursor.SkipBlock()) {
result.status = Status::Malformed;
return result;
}
}
next = cursor.advance();
continue;
}
scratch.clear();
StringRef blobData;
unsigned kind = cursor.readRecord(next.ID, scratch, &blobData);
switch (kind) {
case control_block::METADATA: {
if (versionSeen) {
result.status = Status::Malformed;
break;
}
uint16_t versionMajor = scratch[0];
if (versionMajor > VERSION_MAJOR)
result.status = Status::FormatTooNew;
else if (versionMajor < VERSION_MAJOR)
result.status = Status::FormatTooOld;
else
result.status = Status::Valid;
// Major version 0 does not have stable minor versions.
if (versionMajor == 0) {
uint16_t versionMinor = scratch[1];
if (versionMinor != VERSION_MINOR) {
if (versionMinor < VERSION_MINOR)
result.status = Status::FormatTooOld;
else
result.status = Status::FormatTooNew;
}
}
versionSeen = true;
break;
}
case control_block::MODULE_NAME:
result.name = blobData;
break;
case control_block::TARGET:
result.targetTriple = blobData;
break;
default:
// Unknown metadata record, possibly for use by a future version of the
// module format.
break;
}
next = cursor.advance();
}
return result;
}
示例7: Buffer
GlobalModuleIndex::GlobalModuleIndex(std::unique_ptr<llvm::MemoryBuffer> Buffer,
llvm::BitstreamCursor Cursor)
: Buffer(std::move(Buffer)), IdentifierIndex(), NumIdentifierLookups(),
NumIdentifierLookupHits() {
// Read the global index.
bool InGlobalIndexBlock = false;
bool Done = false;
while (!Done) {
llvm::BitstreamEntry Entry = Cursor.advance();
switch (Entry.Kind) {
case llvm::BitstreamEntry::Error:
return;
case llvm::BitstreamEntry::EndBlock:
if (InGlobalIndexBlock) {
InGlobalIndexBlock = false;
Done = true;
continue;
}
return;
case llvm::BitstreamEntry::Record:
// Entries in the global index block are handled below.
if (InGlobalIndexBlock)
break;
return;
case llvm::BitstreamEntry::SubBlock:
if (!InGlobalIndexBlock && Entry.ID == GLOBAL_INDEX_BLOCK_ID) {
if (Cursor.EnterSubBlock(GLOBAL_INDEX_BLOCK_ID))
return;
InGlobalIndexBlock = true;
} else if (Cursor.SkipBlock()) {
return;
}
continue;
}
SmallVector<uint64_t, 64> Record;
StringRef Blob;
switch ((IndexRecordTypes)Cursor.readRecord(Entry.ID, Record, &Blob)) {
case INDEX_METADATA:
// Make sure that the version matches.
if (Record.size() < 1 || Record[0] != CurrentVersion)
return;
break;
case MODULE: {
unsigned Idx = 0;
unsigned ID = Record[Idx++];
// Make room for this module's information.
if (ID == Modules.size())
Modules.push_back(ModuleInfo());
else
Modules.resize(ID + 1);
// Size/modification time for this module file at the time the
// global index was built.
Modules[ID].Size = Record[Idx++];
Modules[ID].ModTime = Record[Idx++];
// File name.
unsigned NameLen = Record[Idx++];
Modules[ID].FileName.assign(Record.begin() + Idx,
Record.begin() + Idx + NameLen);
Idx += NameLen;
// Dependencies
unsigned NumDeps = Record[Idx++];
Modules[ID].Dependencies.insert(Modules[ID].Dependencies.end(),
Record.begin() + Idx,
Record.begin() + Idx + NumDeps);
Idx += NumDeps;
// Make sure we're at the end of the record.
assert(Idx == Record.size() && "More module info?");
// Record this module as an unresolved module.
// FIXME: this doesn't work correctly for module names containing path
// separators.
StringRef ModuleName = llvm::sys::path::stem(Modules[ID].FileName);
// Remove the -<hash of ModuleMapPath>
ModuleName = ModuleName.rsplit('-').first;
UnresolvedModules[ModuleName] = ID;
break;
}
case IDENTIFIER_INDEX:
// Wire up the identifier index.
if (Record[0]) {
IdentifierIndex = IdentifierIndexTable::Create(
(const unsigned char *)Blob.data() + Record[0],
(const unsigned char *)Blob.data() + sizeof(uint32_t),
(const unsigned char *)Blob.data(), IdentifierIndexReaderTrait());
}
//.........这里部分代码省略.........
示例8: Buffer
GlobalModuleIndex::GlobalModuleIndex(FileManager &FileMgr,
llvm::MemoryBuffer *Buffer,
llvm::BitstreamCursor Cursor)
: Buffer(Buffer), IdentifierIndex(),
NumIdentifierLookups(), NumIdentifierLookupHits()
{
typedef llvm::DenseMap<unsigned, LoadedModuleInfo> LoadedModulesMap;
LoadedModulesMap LoadedModules;
// Read the global index.
unsigned LargestID = 0;
bool InGlobalIndexBlock = false;
bool Done = false;
bool AnyOutOfDate = false;
while (!Done) {
llvm::BitstreamEntry Entry = Cursor.advance();
switch (Entry.Kind) {
case llvm::BitstreamEntry::Error:
return;
case llvm::BitstreamEntry::EndBlock:
if (InGlobalIndexBlock) {
InGlobalIndexBlock = false;
Done = true;
continue;
}
return;
case llvm::BitstreamEntry::Record:
// Entries in the global index block are handled below.
if (InGlobalIndexBlock)
break;
return;
case llvm::BitstreamEntry::SubBlock:
if (!InGlobalIndexBlock && Entry.ID == GLOBAL_INDEX_BLOCK_ID) {
if (Cursor.EnterSubBlock(GLOBAL_INDEX_BLOCK_ID))
return;
InGlobalIndexBlock = true;
} else if (Cursor.SkipBlock()) {
return;
}
continue;
}
SmallVector<uint64_t, 64> Record;
StringRef Blob;
switch ((IndexRecordTypes)Cursor.readRecord(Entry.ID, Record, &Blob)) {
case INDEX_METADATA:
// Make sure that the version matches.
if (Record.size() < 1 || Record[0] != CurrentVersion)
return;
break;
case MODULE: {
unsigned Idx = 0;
unsigned ID = Record[Idx++];
if (ID > LargestID)
LargestID = ID;
off_t Size = Record[Idx++];
time_t ModTime = Record[Idx++];
// File name.
unsigned NameLen = Record[Idx++];
llvm::SmallString<64> FileName(Record.begin() + Idx,
Record.begin() + Idx + NameLen);
Idx += NameLen;
// Dependencies
unsigned NumDeps = Record[Idx++];
llvm::SmallVector<unsigned, 2>
Dependencies(Record.begin() + Idx, Record.begin() + Idx + NumDeps);
// Find the file. If we can't find it, ignore it.
const FileEntry *File = FileMgr.getFile(FileName);
if (!File) {
AnyOutOfDate = true;
break;
}
// If the module file is newer than the index, ignore it.
if (File->getSize() != Size || File->getModificationTime() != ModTime) {
AnyOutOfDate = true;
break;
}
// Record this module. The dependencies will be resolved later.
LoadedModuleInfo &Info = LoadedModules[ID];
Info.File = File;
Info.Dependencies.swap(Dependencies);
break;
}
case IDENTIFIER_INDEX:
// Wire up the identifier index.
//.........这里部分代码省略.........