mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
remove usage of BitstreamReader
LLVM SVN r286207 removed the BitstreamReader interface. Remove the usage of the type, updating the cursor constructor accordingly.
This commit is contained in:
committed by
Bob Wilson
parent
4cced9b75a
commit
46d684f35f
@@ -56,12 +56,6 @@ class ModuleFile : public LazyMemberLoader {
|
||||
std::unique_ptr<llvm::MemoryBuffer> ModuleInputBuffer;
|
||||
std::unique_ptr<llvm::MemoryBuffer> ModuleDocInputBuffer;
|
||||
|
||||
/// The reader attached to \c ModuleInputBuffer.
|
||||
llvm::BitstreamReader ModuleInputReader;
|
||||
|
||||
/// The reader attached to \c ModuleDocInputBuffer.
|
||||
llvm::BitstreamReader ModuleDocInputReader;
|
||||
|
||||
/// The cursor used to lazily load things from the file.
|
||||
llvm::BitstreamCursor DeclTypeCursor;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "swift/LLVMPasses/Passes.h"
|
||||
#include "clang/Basic/TargetInfo.h"
|
||||
#include "llvm/Bitcode/BitcodeWriterPass.h"
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
#include "llvm/Bitcode/BitcodeWriter.h"
|
||||
#include "llvm/CodeGen/BasicTTIImpl.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/DataLayout.h"
|
||||
|
||||
@@ -105,7 +105,7 @@ SILDeserializer::SILDeserializer(ModuleFile *MF, SILModule &M,
|
||||
SILCursor = MF->getSILCursor();
|
||||
SILIndexCursor = MF->getSILIndexCursor();
|
||||
// Early return if either sil block or sil index block does not exist.
|
||||
if (!SILCursor.getBitStreamReader() || !SILIndexCursor.getBitStreamReader())
|
||||
if (SILCursor.AtEndOfStream() || SILIndexCursor.AtEndOfStream())
|
||||
return;
|
||||
|
||||
// Load any abbrev records at the start of the block.
|
||||
|
||||
@@ -55,7 +55,7 @@ static bool enterTopLevelModuleBlock(llvm::BitstreamCursor &cursor,
|
||||
|
||||
if (next.ID == llvm::bitc::BLOCKINFO_BLOCK_ID) {
|
||||
if (shouldReadBlockInfo) {
|
||||
if (cursor.ReadBlockInfoBlock())
|
||||
if (!cursor.ReadBlockInfoBlock())
|
||||
return false;
|
||||
} else {
|
||||
if (cursor.SkipBlock())
|
||||
@@ -77,23 +77,25 @@ static bool enterTopLevelModuleBlock(llvm::BitstreamCursor &cursor,
|
||||
static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
|
||||
SmallVectorImpl<uint64_t> &scratch,
|
||||
ExtendedValidationInfo &extendedInfo) {
|
||||
auto next = cursor.advance();
|
||||
while (next.Kind != llvm::BitstreamEntry::EndBlock) {
|
||||
if (next.Kind == llvm::BitstreamEntry::Error)
|
||||
while (!cursor.AtEndOfStream()) {
|
||||
auto entry = cursor.advance();
|
||||
if (entry.Kind == llvm::BitstreamEntry::EndBlock)
|
||||
break;
|
||||
|
||||
if (entry.Kind == llvm::BitstreamEntry::Error)
|
||||
return false;
|
||||
|
||||
if (next.Kind == llvm::BitstreamEntry::SubBlock) {
|
||||
if (entry.Kind == llvm::BitstreamEntry::SubBlock) {
|
||||
// Unknown metadata sub-block, possibly for use by a future version of
|
||||
// the module format.
|
||||
if (cursor.SkipBlock())
|
||||
return false;
|
||||
next = cursor.advance();
|
||||
continue;
|
||||
}
|
||||
|
||||
scratch.clear();
|
||||
StringRef blobData;
|
||||
unsigned kind = cursor.readRecord(next.ID, scratch, &blobData);
|
||||
unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
switch (kind) {
|
||||
case options_block::SDK_PATH:
|
||||
extendedInfo.setSDKPath(blobData);
|
||||
@@ -119,8 +121,6 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
|
||||
// module format.
|
||||
break;
|
||||
}
|
||||
|
||||
next = cursor.advance();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -135,15 +135,18 @@ validateControlBlock(llvm::BitstreamCursor &cursor,
|
||||
ValidationInfo result;
|
||||
bool versionSeen = false;
|
||||
|
||||
auto next = cursor.advance();
|
||||
while (next.Kind != llvm::BitstreamEntry::EndBlock) {
|
||||
if (next.Kind == llvm::BitstreamEntry::Error) {
|
||||
while (!cursor.AtEndOfStream()) {
|
||||
auto entry = cursor.advance();
|
||||
if (entry.Kind == llvm::BitstreamEntry::EndBlock)
|
||||
break;
|
||||
|
||||
if (entry.Kind == llvm::BitstreamEntry::Error) {
|
||||
result.status = Status::Malformed;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (next.Kind == llvm::BitstreamEntry::SubBlock) {
|
||||
if (next.ID == OPTIONS_BLOCK_ID && extendedInfo) {
|
||||
if (entry.Kind == llvm::BitstreamEntry::SubBlock) {
|
||||
if (entry.ID == OPTIONS_BLOCK_ID && extendedInfo) {
|
||||
cursor.EnterSubBlock(OPTIONS_BLOCK_ID);
|
||||
if (!readOptionsBlock(cursor, scratch, *extendedInfo)) {
|
||||
result.status = Status::Malformed;
|
||||
@@ -157,13 +160,12 @@ validateControlBlock(llvm::BitstreamCursor &cursor,
|
||||
return result;
|
||||
}
|
||||
}
|
||||
next = cursor.advance();
|
||||
continue;
|
||||
}
|
||||
|
||||
scratch.clear();
|
||||
StringRef blobData;
|
||||
unsigned kind = cursor.readRecord(next.ID, scratch, &blobData);
|
||||
unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
switch (kind) {
|
||||
case control_block::METADATA: {
|
||||
if (versionSeen) {
|
||||
@@ -209,8 +211,6 @@ validateControlBlock(llvm::BitstreamCursor &cursor,
|
||||
// module format.
|
||||
break;
|
||||
}
|
||||
|
||||
next = cursor.advance();
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -232,31 +232,31 @@ ValidationInfo serialization::validateSerializedAST(
|
||||
reinterpret_cast<uintptr_t>(data.data()) % 4 != 0)
|
||||
return result;
|
||||
|
||||
llvm::BitstreamReader reader(reinterpret_cast<const uint8_t *>(data.begin()),
|
||||
reinterpret_cast<const uint8_t *>(data.end()));
|
||||
llvm::BitstreamCursor cursor(reader);
|
||||
llvm::BitstreamCursor cursor(data);
|
||||
SmallVector<uint64_t, 32> scratch;
|
||||
|
||||
if (!checkModuleSignature(cursor) ||
|
||||
!enterTopLevelModuleBlock(cursor, MODULE_BLOCK_ID, false))
|
||||
return result;
|
||||
|
||||
auto topLevelEntry = cursor.advance();
|
||||
while (topLevelEntry.Kind == llvm::BitstreamEntry::SubBlock) {
|
||||
llvm::BitstreamEntry topLevelEntry;
|
||||
|
||||
while (!cursor.AtEndOfStream()) {
|
||||
topLevelEntry = cursor.advance();
|
||||
if (topLevelEntry.Kind != llvm::BitstreamEntry::SubBlock)
|
||||
break;
|
||||
|
||||
if (topLevelEntry.ID == CONTROL_BLOCK_ID) {
|
||||
cursor.EnterSubBlock(CONTROL_BLOCK_ID);
|
||||
result = validateControlBlock(cursor, scratch, extendedInfo);
|
||||
if (result.status == Status::Malformed)
|
||||
return result;
|
||||
|
||||
} else {
|
||||
if (cursor.SkipBlock()) {
|
||||
result.status = Status::Malformed;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
topLevelEntry = cursor.advance(AF_DontPopBlockAtEnd);
|
||||
}
|
||||
|
||||
if (topLevelEntry.Kind == llvm::BitstreamEntry::EndBlock) {
|
||||
@@ -466,9 +466,9 @@ bool ModuleFile::readIndexBlock(llvm::BitstreamCursor &cursor) {
|
||||
SmallVector<uint64_t, 4> scratch;
|
||||
StringRef blobData;
|
||||
|
||||
while (true) {
|
||||
auto next = cursor.advance();
|
||||
switch (next.Kind) {
|
||||
while (!cursor.AtEndOfStream()) {
|
||||
auto entry = cursor.advance();
|
||||
switch (entry.Kind) {
|
||||
case llvm::BitstreamEntry::EndBlock:
|
||||
return true;
|
||||
|
||||
@@ -484,7 +484,7 @@ bool ModuleFile::readIndexBlock(llvm::BitstreamCursor &cursor) {
|
||||
case llvm::BitstreamEntry::Record:
|
||||
scratch.clear();
|
||||
blobData = {};
|
||||
unsigned kind = cursor.readRecord(next.ID, scratch, &blobData);
|
||||
unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
|
||||
switch (kind) {
|
||||
case index_block::DECL_OFFSETS:
|
||||
@@ -648,9 +648,9 @@ bool ModuleFile::readCommentBlock(llvm::BitstreamCursor &cursor) {
|
||||
SmallVector<uint64_t, 4> scratch;
|
||||
StringRef blobData;
|
||||
|
||||
while (true) {
|
||||
auto next = cursor.advance();
|
||||
switch (next.Kind) {
|
||||
while (!cursor.AtEndOfStream()) {
|
||||
auto entry = cursor.advance();
|
||||
switch (entry.Kind) {
|
||||
case llvm::BitstreamEntry::EndBlock:
|
||||
return true;
|
||||
|
||||
@@ -665,7 +665,7 @@ bool ModuleFile::readCommentBlock(llvm::BitstreamCursor &cursor) {
|
||||
|
||||
case llvm::BitstreamEntry::Record:
|
||||
scratch.clear();
|
||||
unsigned kind = cursor.readRecord(next.ID, scratch, &blobData);
|
||||
unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData);
|
||||
|
||||
switch (kind) {
|
||||
case comment_block::DECL_COMMENTS:
|
||||
@@ -699,18 +699,6 @@ static Optional<swift::LibraryKind> getActualLibraryKind(unsigned rawKind) {
|
||||
return None;
|
||||
}
|
||||
|
||||
static const uint8_t *getStartBytePtr(llvm::MemoryBuffer *buffer) {
|
||||
if (!buffer)
|
||||
return nullptr;
|
||||
return reinterpret_cast<const uint8_t *>(buffer->getBufferStart());
|
||||
}
|
||||
|
||||
static const uint8_t *getEndBytePtr(llvm::MemoryBuffer *buffer) {
|
||||
if (!buffer)
|
||||
return nullptr;
|
||||
return reinterpret_cast<const uint8_t *>(buffer->getBufferEnd());
|
||||
}
|
||||
|
||||
static bool areCompatibleArchitectures(const llvm::Triple &moduleTarget,
|
||||
const llvm::Triple &ctxTarget) {
|
||||
if (moduleTarget.getArch() == ctxTarget.getArch())
|
||||
@@ -764,17 +752,13 @@ ModuleFile::ModuleFile(
|
||||
serialization::ExtendedValidationInfo *extInfo)
|
||||
: ModuleInputBuffer(std::move(moduleInputBuffer)),
|
||||
ModuleDocInputBuffer(std::move(moduleDocInputBuffer)),
|
||||
ModuleInputReader(getStartBytePtr(this->ModuleInputBuffer.get()),
|
||||
getEndBytePtr(this->ModuleInputBuffer.get())),
|
||||
ModuleDocInputReader(getStartBytePtr(this->ModuleDocInputBuffer.get()),
|
||||
getEndBytePtr(this->ModuleDocInputBuffer.get())),
|
||||
DeserializedTypeCallback([](Type ty) {}) {
|
||||
assert(getStatus() == Status::Valid);
|
||||
Bits.IsFramework = isFramework;
|
||||
|
||||
PrettyModuleFileDeserialization stackEntry(*this);
|
||||
|
||||
llvm::BitstreamCursor cursor{ModuleInputReader};
|
||||
llvm::BitstreamCursor cursor{ModuleInputBuffer->getMemBufferRef()};
|
||||
|
||||
if (!checkModuleSignature(cursor) ||
|
||||
!enterTopLevelModuleBlock(cursor, MODULE_BLOCK_ID)) {
|
||||
@@ -787,8 +771,13 @@ ModuleFile::ModuleFile(
|
||||
bool hasValidControlBlock = false;
|
||||
SmallVector<uint64_t, 64> scratch;
|
||||
|
||||
auto topLevelEntry = cursor.advance();
|
||||
while (topLevelEntry.Kind == llvm::BitstreamEntry::SubBlock) {
|
||||
llvm::BitstreamEntry topLevelEntry;
|
||||
|
||||
while (!cursor.AtEndOfStream()) {
|
||||
topLevelEntry = cursor.advance();
|
||||
if (topLevelEntry.Kind != llvm::BitstreamEntry::SubBlock)
|
||||
break;
|
||||
|
||||
switch (topLevelEntry.ID) {
|
||||
case CONTROL_BLOCK_ID: {
|
||||
cursor.EnterSubBlock(CONTROL_BLOCK_ID);
|
||||
@@ -996,15 +985,18 @@ ModuleFile::ModuleFile(
|
||||
if (!this->ModuleDocInputBuffer)
|
||||
return;
|
||||
|
||||
llvm::BitstreamCursor docCursor{ModuleDocInputReader};
|
||||
llvm::BitstreamCursor docCursor{ModuleDocInputBuffer->getMemBufferRef()};
|
||||
if (!checkModuleDocSignature(docCursor) ||
|
||||
!enterTopLevelModuleBlock(docCursor, MODULE_DOC_BLOCK_ID)) {
|
||||
error(Status::MalformedDocumentation);
|
||||
return;
|
||||
}
|
||||
|
||||
topLevelEntry = docCursor.advance();
|
||||
while (topLevelEntry.Kind == llvm::BitstreamEntry::SubBlock) {
|
||||
while (!docCursor.AtEndOfStream()) {
|
||||
topLevelEntry = docCursor.advance();
|
||||
if (topLevelEntry.Kind != llvm::BitstreamEntry::SubBlock)
|
||||
break;
|
||||
|
||||
switch (topLevelEntry.ID) {
|
||||
case COMMENT_BLOCK_ID: {
|
||||
if (!hasValidControlBlock || !readCommentBlock(docCursor)) {
|
||||
@@ -1023,8 +1015,6 @@ ModuleFile::ModuleFile(
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
topLevelEntry = docCursor.advance(AF_DontPopBlockAtEnd);
|
||||
}
|
||||
|
||||
if (topLevelEntry.Kind != llvm::BitstreamEntry::EndBlock) {
|
||||
|
||||
@@ -143,9 +143,7 @@ int modulewrap_main(ArrayRef<const char *> Args, const char *Argv0,
|
||||
}
|
||||
|
||||
// Superficially verify that the input is a swift module file.
|
||||
llvm::BitstreamReader Reader((unsigned char *)(*ErrOrBuf)->getBufferStart(),
|
||||
(unsigned char *)(*ErrOrBuf)->getBufferEnd());
|
||||
llvm::BitstreamCursor Cursor(Reader);
|
||||
llvm::BitstreamCursor Cursor(ErrOrBuf.get()->getMemBufferRef());
|
||||
for (unsigned char Byte : serialization::MODULE_SIGNATURE)
|
||||
if (Cursor.AtEndOfStream() || Cursor.Read(8) != Byte) {
|
||||
Instance.getDiags().diagnose(SourceLoc(), diag::error_parse_input_file,
|
||||
|
||||
Reference in New Issue
Block a user