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