mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Serialization] Move (Module)Status and validateSerializedAST into a namespace.
Also into a separate file. Before (swift/Serialization/SerializedModuleLoader.h): ModuleStatus SerializedModuleLoader::ValidationInfo SerializedModuleLoader::ExtendedValidationInfo SerializedModuleLoader::isSerializedAST SerializedModuleLoader::validateSerializedAST After (swift/Serialization/Validation.h): serialization::Status serialization::ValidationInfo serialization::ExtendedValidationInfo serialization::isSerializedAST serialization::validateSerializedAST No functionality change, just a lot of renaming and a bit of reorganizing. Swift SVN r25226
This commit is contained in:
@@ -20,8 +20,8 @@
|
||||
#include "swift/AST/Module.h"
|
||||
#include "swift/AST/RawComment.h"
|
||||
#include "swift/AST/TypeLoc.h"
|
||||
#include "swift/Serialization/SerializedModuleLoader.h"
|
||||
#include "swift/Serialization/ModuleFormat.h"
|
||||
#include "swift/Serialization/Validation.h"
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
@@ -43,6 +43,7 @@ class ProtocolConformance;
|
||||
/// A serialized module, along with the tools to access it.
|
||||
class ModuleFile : public LazyMemberLoader {
|
||||
friend class SerializedASTFile;
|
||||
using Status = serialization::Status;
|
||||
|
||||
/// A reference back to the AST representation of the file.
|
||||
FileUnit *FileContext = nullptr;
|
||||
@@ -317,7 +318,7 @@ private:
|
||||
} Bits = {};
|
||||
static_assert(sizeof(Bits) <= 8, "The bit set should be small");
|
||||
|
||||
void setStatus(ModuleStatus status) {
|
||||
void setStatus(Status status) {
|
||||
Bits.Status = static_cast<unsigned>(status);
|
||||
assert(status == getStatus() && "not enough bits for status");
|
||||
}
|
||||
@@ -340,9 +341,9 @@ private:
|
||||
public:
|
||||
/// Change the status of the current module. Default argument marks the module
|
||||
/// as being malformed.
|
||||
ModuleStatus error(ModuleStatus issue = ModuleStatus::Malformed) {
|
||||
assert(issue != ModuleStatus::Valid);
|
||||
assert((!FileContext || issue != ModuleStatus::Malformed) &&
|
||||
Status error(Status issue = Status::Malformed) {
|
||||
assert(issue != Status::Valid);
|
||||
assert((!FileContext || issue != Status::Malformed) &&
|
||||
"error deserializing an individual record");
|
||||
setStatus(issue);
|
||||
return getStatus();
|
||||
@@ -444,7 +445,7 @@ public:
|
||||
/// \param[out] theModule The loaded module.
|
||||
/// \returns Whether the module was successfully loaded, or what went wrong
|
||||
/// if it was not.
|
||||
static ModuleStatus
|
||||
static Status
|
||||
load(std::unique_ptr<llvm::MemoryBuffer> moduleInputBuffer,
|
||||
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
|
||||
bool isFramework, std::unique_ptr<ModuleFile> &theModule) {
|
||||
@@ -461,11 +462,11 @@ public:
|
||||
///
|
||||
/// Returns any error that occurred during association, including validation
|
||||
/// that the module file is compatible with the module it's being loaded as.
|
||||
ModuleStatus associateWithFileContext(FileUnit *file, SourceLoc diagLoc);
|
||||
Status associateWithFileContext(FileUnit *file, SourceLoc diagLoc);
|
||||
|
||||
/// Checks whether this module can be used.
|
||||
ModuleStatus getStatus() const {
|
||||
return static_cast<ModuleStatus>(Bits.Status);
|
||||
Status getStatus() const {
|
||||
return static_cast<Status>(Bits.Status);
|
||||
}
|
||||
|
||||
/// Returns the list of modules this module depends on.
|
||||
|
||||
@@ -16,46 +16,10 @@
|
||||
#include "swift/AST/Module.h"
|
||||
#include "swift/AST/ModuleLoader.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include <map>
|
||||
|
||||
namespace swift {
|
||||
class ModuleFile;
|
||||
|
||||
/// Describes whether a loaded module can be used.
|
||||
enum class ModuleStatus {
|
||||
/// The module is valid.
|
||||
Valid,
|
||||
|
||||
/// The module file format is too old to be used by this version of the
|
||||
/// compiler.
|
||||
FormatTooOld,
|
||||
|
||||
/// The module file format is too new to be used by this version of the
|
||||
/// compiler.
|
||||
FormatTooNew,
|
||||
|
||||
/// The module file depends on another module that can't be loaded.
|
||||
MissingDependency,
|
||||
|
||||
/// The module file is an overlay for a Clang module, which can't be found.
|
||||
MissingShadowedModule,
|
||||
|
||||
/// The module file is malformed in some way.
|
||||
Malformed,
|
||||
|
||||
/// The module documentation file is malformed in some way.
|
||||
MalformedDocumentation,
|
||||
|
||||
/// The module file's name does not match the module it is being loaded into.
|
||||
NameMismatch,
|
||||
|
||||
/// The module file was built for a different target platform.
|
||||
TargetIncompatible,
|
||||
|
||||
/// The module file was built for a target newer than the current target.
|
||||
TargetTooNew
|
||||
};
|
||||
|
||||
/// \brief Imports serialized Swift modules into an ASTContext.
|
||||
class SerializedModuleLoader : public ModuleLoader {
|
||||
private:
|
||||
@@ -126,64 +90,6 @@ public:
|
||||
unsigned previousGeneration,
|
||||
llvm::TinyPtrVector<AbstractFunctionDecl *> &methods);
|
||||
|
||||
/// Returns true if the data looks like it contains a serialized AST.
|
||||
static bool isSerializedAST(StringRef data);
|
||||
|
||||
/// \see validateSerializedAST()
|
||||
struct ValidationInfo {
|
||||
StringRef name = {};
|
||||
StringRef targetTriple = {};
|
||||
size_t bytes = 0;
|
||||
ModuleStatus status = ModuleStatus::Malformed;
|
||||
};
|
||||
|
||||
/// A collection of options that can be used to set up a new AST context
|
||||
/// before it has been created.
|
||||
///
|
||||
/// Note that this is intended to be a transient data structure; as such,
|
||||
/// <strong>none of the string values added to it are copied</strong>.
|
||||
///
|
||||
/// \sa validateSerializedAST()
|
||||
class ExtendedValidationInfo {
|
||||
SmallVector<StringRef, 4> ClangImporterOpts;
|
||||
StringRef SDKPath;
|
||||
public:
|
||||
ExtendedValidationInfo() = default;
|
||||
|
||||
StringRef getSDKPath() const { return SDKPath; }
|
||||
void setSDKPath(StringRef path) {
|
||||
assert(SDKPath.empty());
|
||||
SDKPath = path;
|
||||
}
|
||||
|
||||
ArrayRef<StringRef> getClangImporterOptions() const {
|
||||
return ClangImporterOpts;
|
||||
}
|
||||
void addClangImporterOption(StringRef option) {
|
||||
ClangImporterOpts.push_back(option);
|
||||
}
|
||||
};
|
||||
|
||||
/// Returns info about the serialized AST in the given data.
|
||||
///
|
||||
/// If the returned status is anything but ModuleStatus::Valid, the
|
||||
/// serialized data cannot be loaded by this version of the compiler. If the
|
||||
/// returned size is non-zero, it's possible to skip over this module's data,
|
||||
/// in case there is more data in the buffer. The returned name, which may
|
||||
/// be empty, directly points into the given data buffer.
|
||||
///
|
||||
/// Note that this does not actually try to load the module or validate any
|
||||
/// of its dependencies; it only checks that it /can/ be loaded.
|
||||
///
|
||||
/// \param data A buffer containing the serialized AST. Result information
|
||||
/// refers directly into this buffer.
|
||||
/// \param[out] extendedInfo If present, will be populated with additional
|
||||
/// compilation options serialized into the AST at build time that may be
|
||||
/// necessary to load it properly.
|
||||
static ValidationInfo
|
||||
validateSerializedAST(StringRef data,
|
||||
ExtendedValidationInfo *extendedInfo = nullptr);
|
||||
|
||||
virtual void verifyAllModules() override;
|
||||
};
|
||||
|
||||
|
||||
@@ -13,6 +13,11 @@
|
||||
#ifndef SWIFT_SERIALIZATION_SILLOADER_H
|
||||
#define SWIFT_SERIALIZATION_SILLOADER_H
|
||||
|
||||
#include "swift/AST/Decl.h"
|
||||
#include "swift/AST/Identifier.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace swift {
|
||||
class ASTContext;
|
||||
class Module;
|
||||
|
||||
121
include/swift/Serialization/Validation.h
Normal file
121
include/swift/Serialization/Validation.h
Normal file
@@ -0,0 +1,121 @@
|
||||
//===--- Validation.h - Validation / errors for serialization ---*- c++ -*-===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See http://swift.org/LICENSE.txt for license information
|
||||
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SWIFT_SERIALIZATION_VALIDATION_H
|
||||
#define SWIFT_SERIALIZATION_VALIDATION_H
|
||||
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
namespace swift {
|
||||
namespace serialization {
|
||||
|
||||
/// Describes whether a serialized module can be used by this compiler.
|
||||
enum class Status {
|
||||
/// The module is valid.
|
||||
Valid,
|
||||
|
||||
/// The module file format is too old to be used by this version of the
|
||||
/// compiler.
|
||||
FormatTooOld,
|
||||
|
||||
/// The module file format is too new to be used by this version of the
|
||||
/// compiler.
|
||||
FormatTooNew,
|
||||
|
||||
/// The module file depends on another module that can't be loaded.
|
||||
MissingDependency,
|
||||
|
||||
/// The module file is an overlay for a Clang module, which can't be found.
|
||||
MissingShadowedModule,
|
||||
|
||||
/// The module file is malformed in some way.
|
||||
Malformed,
|
||||
|
||||
/// The module documentation file is malformed in some way.
|
||||
MalformedDocumentation,
|
||||
|
||||
/// The module file's name does not match the module it is being loaded
|
||||
/// into.
|
||||
NameMismatch,
|
||||
|
||||
/// The module file was built for a different target platform.
|
||||
TargetIncompatible,
|
||||
|
||||
/// The module file was built for a target newer than the current target.
|
||||
TargetTooNew
|
||||
};
|
||||
|
||||
/// Returns true if the data looks like it contains a serialized AST.
|
||||
bool isSerializedAST(StringRef data);
|
||||
|
||||
/// \see validateSerializedAST()
|
||||
struct ValidationInfo {
|
||||
StringRef name = {};
|
||||
StringRef targetTriple = {};
|
||||
size_t bytes = 0;
|
||||
Status status = Status::Malformed;
|
||||
};
|
||||
|
||||
/// A collection of options that can be used to set up a new AST context
|
||||
/// before it has been created.
|
||||
///
|
||||
/// Note that this is intended to be a transient data structure; as such,
|
||||
/// <strong>none of the string values added to it are copied</strong>.
|
||||
///
|
||||
/// \sa validateSerializedAST()
|
||||
class ExtendedValidationInfo {
|
||||
SmallVector<StringRef, 4> ExtraClangImporterOpts;
|
||||
StringRef SDKPath;
|
||||
public:
|
||||
ExtendedValidationInfo() = default;
|
||||
|
||||
StringRef getSDKPath() const { return SDKPath; }
|
||||
void setSDKPath(StringRef path) {
|
||||
assert(SDKPath.empty());
|
||||
SDKPath = path;
|
||||
}
|
||||
|
||||
ArrayRef<StringRef> getExtraClangImporterOptions() const {
|
||||
return ExtraClangImporterOpts;
|
||||
}
|
||||
void addExtraClangImporterOption(StringRef option) {
|
||||
ExtraClangImporterOpts.push_back(option);
|
||||
}
|
||||
};
|
||||
|
||||
/// Returns info about the serialized AST in the given data.
|
||||
///
|
||||
/// If the returned status is anything but Status::Valid, the serialized data
|
||||
/// cannot be loaded by this version of the compiler. If the returned size is
|
||||
/// non-zero, it's possible to skip over this module's data, in case there is
|
||||
/// more data in the buffer. The returned name, which may be empty, directly
|
||||
/// points into the given data buffer.
|
||||
///
|
||||
/// Note that this does not actually try to load the module or validate any
|
||||
/// of its dependencies; it only checks that it /can/ be loaded.
|
||||
///
|
||||
/// \param data A buffer containing the serialized AST. Result information
|
||||
/// refers directly into this buffer.
|
||||
/// \param[out] extendedInfo If present, will be populated with additional
|
||||
/// compilation options serialized into the AST at build time that may be
|
||||
/// necessary to load it properly.
|
||||
ValidationInfo
|
||||
validateSerializedAST(StringRef data,
|
||||
ExtendedValidationInfo *extendedInfo = nullptr);
|
||||
|
||||
} // end namespace serialization
|
||||
} // end namespace swift
|
||||
|
||||
#endif
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "swift/ASTSectionImporter/ASTSectionImporter.h"
|
||||
#include "swift/Basic/Dwarf.h"
|
||||
#include "swift/Serialization/SerializedModuleLoader.h"
|
||||
#include "swift/Serialization/Validation.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
@@ -25,17 +26,17 @@ using namespace swift;
|
||||
|
||||
bool swift::parseASTSection(SerializedModuleLoader *SML, StringRef buf,
|
||||
SmallVectorImpl<std::string> &foundModules) {
|
||||
if (!SerializedModuleLoader::isSerializedAST(buf))
|
||||
if (!serialization::isSerializedAST(buf))
|
||||
return false;
|
||||
|
||||
// An AST section consists of one or more AST modules, optionally with
|
||||
// headers. Iterate over all AST modules.
|
||||
while (!buf.empty()) {
|
||||
auto info = SerializedModuleLoader::validateSerializedAST(buf);
|
||||
auto info = serialization::validateSerializedAST(buf);
|
||||
|
||||
assert(info.name.size() < (2 << 10) && "name failed sanity check");
|
||||
|
||||
if (info.status == ModuleStatus::Valid) {
|
||||
if (info.status == serialization::Status::Valid) {
|
||||
assert(info.bytes != 0);
|
||||
if (!info.name.empty()) {
|
||||
StringRef moduleData = buf.substr(0, info.bytes);
|
||||
|
||||
@@ -130,7 +130,7 @@ bool CompilerInstance::setup(const CompilerInvocation &Invok) {
|
||||
auto Copy = std::unique_ptr<llvm::MemoryBuffer>(
|
||||
llvm::MemoryBuffer::getMemBufferCopy(
|
||||
InputBuffer->getBuffer(), InputBuffer->getBufferIdentifier()));
|
||||
if (SerializedModuleLoader::isSerializedAST(Copy->getBuffer())) {
|
||||
if (serialization::isSerializedAST(Copy->getBuffer())) {
|
||||
PartialModules.push_back({ std::move(Copy), nullptr });
|
||||
} else {
|
||||
unsigned BufferID = SourceMgr.addNewSourceBuffer(std::move(Copy));
|
||||
@@ -171,8 +171,7 @@ bool CompilerInstance::setup(const CompilerInvocation &Invok) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (SerializedModuleLoader::isSerializedAST(
|
||||
InputFileOrErr.get()->getBuffer())) {
|
||||
if (serialization::isSerializedAST(InputFileOrErr.get()->getBuffer())) {
|
||||
llvm::SmallString<128> ModuleDocFilePath(File);
|
||||
llvm::sys::path::replace_extension(ModuleDocFilePath,
|
||||
SERIALIZED_MODULE_DOC_EXTENSION);
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
#include "swift/Basic/SourceManager.h"
|
||||
#include "swift/ClangImporter/ClangModule.h"
|
||||
#include "swift/Parse/Parser.h"
|
||||
#include "swift/Serialization/SerializedModuleLoader.h"
|
||||
#include "swift/Serialization/ModuleFile.h"
|
||||
#include "swift/Subsystems.h"
|
||||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/AST/DeclObjC.h"
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "swift/Basic/Range.h"
|
||||
#include "swift/ClangImporter/ClangImporter.h"
|
||||
#include "swift/Serialization/BCReadingExtras.h"
|
||||
#include "swift/Serialization/SerializedModuleLoader.h"
|
||||
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
@@ -30,9 +31,6 @@ using namespace swift;
|
||||
using namespace swift::serialization;
|
||||
using namespace llvm::support;
|
||||
|
||||
using ValidationInfo = SerializedModuleLoader::ValidationInfo;
|
||||
using ExtendedValidationInfo = SerializedModuleLoader::ExtendedValidationInfo;
|
||||
|
||||
static bool checkModuleSignature(llvm::BitstreamCursor &cursor) {
|
||||
for (unsigned char byte : MODULE_SIGNATURE)
|
||||
if (cursor.AtEndOfStream() || cursor.Read(8) != byte)
|
||||
@@ -101,7 +99,7 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
|
||||
extendedInfo.setSDKPath(blobData);
|
||||
break;
|
||||
case options_block::XCC:
|
||||
extendedInfo.addClangImporterOption(blobData);
|
||||
extendedInfo.addExtraClangImporterOption(blobData);
|
||||
break;
|
||||
default:
|
||||
// Unknown options record, possibly for use by a future version of the
|
||||
@@ -127,7 +125,7 @@ validateControlBlock(llvm::BitstreamCursor &cursor,
|
||||
auto next = cursor.advance();
|
||||
while (next.Kind != llvm::BitstreamEntry::EndBlock) {
|
||||
if (next.Kind == llvm::BitstreamEntry::Error) {
|
||||
result.status = ModuleStatus::Malformed;
|
||||
result.status = Status::Malformed;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -135,14 +133,14 @@ validateControlBlock(llvm::BitstreamCursor &cursor,
|
||||
if (next.ID == OPTIONS_BLOCK_ID && extendedInfo) {
|
||||
cursor.EnterSubBlock(OPTIONS_BLOCK_ID);
|
||||
if (!readOptionsBlock(cursor, scratch, *extendedInfo)) {
|
||||
result.status = ModuleStatus::Malformed;
|
||||
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 = ModuleStatus::Malformed;
|
||||
result.status = Status::Malformed;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -156,26 +154,26 @@ validateControlBlock(llvm::BitstreamCursor &cursor,
|
||||
switch (kind) {
|
||||
case control_block::METADATA: {
|
||||
if (versionSeen) {
|
||||
result.status = ModuleStatus::Malformed;
|
||||
result.status = Status::Malformed;
|
||||
break;
|
||||
}
|
||||
|
||||
uint16_t versionMajor = scratch[0];
|
||||
if (versionMajor > VERSION_MAJOR)
|
||||
result.status = ModuleStatus::FormatTooNew;
|
||||
result.status = Status::FormatTooNew;
|
||||
else if (versionMajor < VERSION_MAJOR)
|
||||
result.status = ModuleStatus::FormatTooOld;
|
||||
result.status = Status::FormatTooOld;
|
||||
else
|
||||
result.status = ModuleStatus::Valid;
|
||||
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 = ModuleStatus::FormatTooOld;
|
||||
result.status = Status::FormatTooOld;
|
||||
else
|
||||
result.status = ModuleStatus::FormatTooNew;
|
||||
result.status = Status::FormatTooNew;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +198,13 @@ validateControlBlock(llvm::BitstreamCursor &cursor,
|
||||
return result;
|
||||
}
|
||||
|
||||
ValidationInfo SerializedModuleLoader::validateSerializedAST(
|
||||
bool serialization::isSerializedAST(StringRef data) {
|
||||
StringRef signatureStr(reinterpret_cast<const char *>(MODULE_SIGNATURE),
|
||||
llvm::array_lengthof(MODULE_SIGNATURE));
|
||||
return data.startswith(signatureStr);
|
||||
}
|
||||
|
||||
ValidationInfo serialization::validateSerializedAST(
|
||||
StringRef data,
|
||||
ExtendedValidationInfo *extendedInfo) {
|
||||
ValidationInfo result;
|
||||
@@ -224,12 +228,12 @@ ValidationInfo SerializedModuleLoader::validateSerializedAST(
|
||||
if (topLevelEntry.ID == CONTROL_BLOCK_ID) {
|
||||
cursor.EnterSubBlock(CONTROL_BLOCK_ID);
|
||||
result = validateControlBlock(cursor, scratch, extendedInfo);
|
||||
if (result.status == ModuleStatus::Malformed)
|
||||
if (result.status == Status::Malformed)
|
||||
return result;
|
||||
|
||||
} else {
|
||||
if (cursor.SkipBlock()) {
|
||||
result.status = ModuleStatus::Malformed;
|
||||
result.status = Status::Malformed;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -242,7 +246,7 @@ ValidationInfo SerializedModuleLoader::validateSerializedAST(
|
||||
assert(cursor.GetCurrentBitNo() % CHAR_BIT == 0);
|
||||
result.bytes = cursor.GetCurrentBitNo() / CHAR_BIT;
|
||||
} else {
|
||||
result.status = ModuleStatus::Malformed;
|
||||
result.status = Status::Malformed;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -708,7 +712,7 @@ ModuleFile::ModuleFile(
|
||||
getEndBytePtr(this->ModuleInputBuffer.get())),
|
||||
ModuleDocInputReader(getStartBytePtr(this->ModuleDocInputBuffer.get()),
|
||||
getEndBytePtr(this->ModuleDocInputBuffer.get())) {
|
||||
assert(getStatus() == ModuleStatus::Valid);
|
||||
assert(getStatus() == Status::Valid);
|
||||
Bits.IsFramework = isFramework;
|
||||
|
||||
PrettyModuleFileDeserialization stackEntry(*this);
|
||||
@@ -733,7 +737,7 @@ ModuleFile::ModuleFile(
|
||||
cursor.EnterSubBlock(CONTROL_BLOCK_ID);
|
||||
|
||||
auto info = validateControlBlock(cursor, scratch, nullptr);
|
||||
if (info.status != ModuleStatus::Valid) {
|
||||
if (info.status != Status::Valid) {
|
||||
error(info.status);
|
||||
return;
|
||||
}
|
||||
@@ -938,7 +942,7 @@ ModuleFile::ModuleFile(
|
||||
llvm::BitstreamCursor docCursor{ModuleDocInputReader};
|
||||
if (!checkModuleDocSignature(docCursor) ||
|
||||
!enterTopLevelModuleBlock(docCursor, MODULE_DOC_BLOCK_ID)) {
|
||||
error(ModuleStatus::MalformedDocumentation);
|
||||
error(Status::MalformedDocumentation);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -947,7 +951,7 @@ ModuleFile::ModuleFile(
|
||||
switch (topLevelEntry.ID) {
|
||||
case COMMENT_BLOCK_ID: {
|
||||
if (!hasValidControlBlock || !readCommentBlock(docCursor)) {
|
||||
error(ModuleStatus::MalformedDocumentation);
|
||||
error(Status::MalformedDocumentation);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -957,7 +961,7 @@ ModuleFile::ModuleFile(
|
||||
// Unknown top-level block, possibly for use by a future version of the
|
||||
// module format.
|
||||
if (docCursor.SkipBlock()) {
|
||||
error(ModuleStatus::MalformedDocumentation);
|
||||
error(Status::MalformedDocumentation);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -967,30 +971,30 @@ ModuleFile::ModuleFile(
|
||||
}
|
||||
|
||||
if (topLevelEntry.Kind != llvm::BitstreamEntry::EndBlock) {
|
||||
error(ModuleStatus::MalformedDocumentation);
|
||||
error(Status::MalformedDocumentation);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ModuleStatus ModuleFile::associateWithFileContext(FileUnit *file,
|
||||
Status ModuleFile::associateWithFileContext(FileUnit *file,
|
||||
SourceLoc diagLoc) {
|
||||
PrettyModuleFileDeserialization stackEntry(*this);
|
||||
|
||||
assert(getStatus() == ModuleStatus::Valid && "invalid module file");
|
||||
assert(getStatus() == Status::Valid && "invalid module file");
|
||||
assert(!FileContext && "already associated with an AST module");
|
||||
FileContext = file;
|
||||
|
||||
if (file->getParentModule()->Name.str() != Name)
|
||||
return error(ModuleStatus::NameMismatch);
|
||||
return error(Status::NameMismatch);
|
||||
|
||||
ASTContext &ctx = getContext();
|
||||
|
||||
llvm::Triple moduleTarget(llvm::Triple::normalize(TargetTriple));
|
||||
if (!areCompatibleArchitectures(moduleTarget, ctx.LangOpts.Target) ||
|
||||
!areCompatibleOSs(moduleTarget, ctx.LangOpts.Target)) {
|
||||
return error(ModuleStatus::TargetIncompatible);
|
||||
return error(Status::TargetIncompatible);
|
||||
} else if (isTargetTooNew(moduleTarget, ctx.LangOpts.Target)) {
|
||||
return error(ModuleStatus::TargetTooNew);
|
||||
return error(Status::TargetTooNew);
|
||||
}
|
||||
|
||||
auto clangImporter = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
|
||||
@@ -1044,7 +1048,7 @@ ModuleStatus ModuleFile::associateWithFileContext(FileUnit *file,
|
||||
// If we're missing the module we're shadowing, treat that specially.
|
||||
if (modulePath.size() == 1 &&
|
||||
modulePath.front() == file->getParentModule()->Name) {
|
||||
return error(ModuleStatus::MissingShadowedModule);
|
||||
return error(Status::MissingShadowedModule);
|
||||
}
|
||||
|
||||
// Otherwise, continue trying to load dependencies, so that we can list
|
||||
@@ -1065,7 +1069,7 @@ ModuleStatus ModuleFile::associateWithFileContext(FileUnit *file,
|
||||
}
|
||||
|
||||
if (missingDependency) {
|
||||
return error(ModuleStatus::MissingDependency);
|
||||
return error(Status::MissingDependency);
|
||||
}
|
||||
|
||||
if (Bits.HasUnderlyingModule)
|
||||
|
||||
@@ -161,10 +161,10 @@ FileUnit *SerializedModuleLoader::loadAST(
|
||||
}
|
||||
|
||||
std::unique_ptr<ModuleFile> loadedModuleFile;
|
||||
ModuleStatus err = ModuleFile::load(std::move(moduleInputBuffer),
|
||||
serialization::Status err = ModuleFile::load(std::move(moduleInputBuffer),
|
||||
std::move(moduleDocInputBuffer),
|
||||
isFramework, loadedModuleFile);
|
||||
if (err == ModuleStatus::Valid) {
|
||||
if (err == serialization::Status::Valid) {
|
||||
Ctx.bumpGeneration();
|
||||
|
||||
// We've loaded the file. Now try to bring it into the AST.
|
||||
@@ -174,7 +174,7 @@ FileUnit *SerializedModuleLoader::loadAST(
|
||||
auto diagLocOrInvalid = diagLoc.getValueOr(SourceLoc());
|
||||
err = loadedModuleFile->associateWithFileContext(fileUnit,
|
||||
diagLocOrInvalid);
|
||||
if (err == ModuleStatus::Valid) {
|
||||
if (err == serialization::Status::Valid) {
|
||||
LoadedModuleFiles.emplace_back(std::move(loadedModuleFile),
|
||||
Ctx.getCurrentGeneration());
|
||||
return fileUnit;
|
||||
@@ -188,29 +188,29 @@ FileUnit *SerializedModuleLoader::loadAST(
|
||||
return nullptr;
|
||||
|
||||
switch (loadedModuleFile->getStatus()) {
|
||||
case ModuleStatus::Valid:
|
||||
case serialization::Status::Valid:
|
||||
llvm_unreachable("At this point we know loading has failed");
|
||||
|
||||
case ModuleStatus::FormatTooNew:
|
||||
case serialization::Status::FormatTooNew:
|
||||
Ctx.Diags.diagnose(*diagLoc, diag::serialization_module_too_new,
|
||||
moduleBufferID);
|
||||
break;
|
||||
case ModuleStatus::FormatTooOld:
|
||||
case serialization::Status::FormatTooOld:
|
||||
Ctx.Diags.diagnose(*diagLoc, diag::serialization_module_too_old,
|
||||
moduleBufferID);
|
||||
break;
|
||||
case ModuleStatus::Malformed:
|
||||
case serialization::Status::Malformed:
|
||||
Ctx.Diags.diagnose(*diagLoc, diag::serialization_malformed_module,
|
||||
moduleBufferID);
|
||||
break;
|
||||
|
||||
case ModuleStatus::MalformedDocumentation:
|
||||
case serialization::Status::MalformedDocumentation:
|
||||
assert(moduleDocBufferID);
|
||||
Ctx.Diags.diagnose(*diagLoc, diag::serialization_malformed_module,
|
||||
moduleDocBufferID ? moduleDocBufferID : "");
|
||||
break;
|
||||
|
||||
case ModuleStatus::MissingDependency: {
|
||||
case serialization::Status::MissingDependency: {
|
||||
// Figure out /which/ dependencies are missing.
|
||||
// FIXME: Dependencies should be de-duplicated at serialization time,
|
||||
// not now.
|
||||
@@ -255,7 +255,7 @@ FileUnit *SerializedModuleLoader::loadAST(
|
||||
break;
|
||||
}
|
||||
|
||||
case ModuleStatus::MissingShadowedModule: {
|
||||
case serialization::Status::MissingShadowedModule: {
|
||||
Ctx.Diags.diagnose(*diagLoc, diag::serialization_missing_shadowed_module,
|
||||
M.Name);
|
||||
if (Ctx.SearchPathOpts.SDKPath.empty()) {
|
||||
@@ -265,7 +265,7 @@ FileUnit *SerializedModuleLoader::loadAST(
|
||||
break;
|
||||
}
|
||||
|
||||
case ModuleStatus::NameMismatch: {
|
||||
case serialization::Status::NameMismatch: {
|
||||
// FIXME: This doesn't handle a non-debugger REPL, which should also treat
|
||||
// this as a non-fatal error.
|
||||
auto diagKind = diag::serialization_name_mismatch;
|
||||
@@ -276,7 +276,7 @@ FileUnit *SerializedModuleLoader::loadAST(
|
||||
break;
|
||||
}
|
||||
|
||||
case ModuleStatus::TargetIncompatible: {
|
||||
case serialization::Status::TargetIncompatible: {
|
||||
// FIXME: This doesn't handle a non-debugger REPL, which should also treat
|
||||
// this as a non-fatal error.
|
||||
auto diagKind = diag::serialization_target_incompatible;
|
||||
@@ -287,7 +287,7 @@ FileUnit *SerializedModuleLoader::loadAST(
|
||||
break;
|
||||
}
|
||||
|
||||
case ModuleStatus::TargetTooNew: {
|
||||
case serialization::Status::TargetTooNew: {
|
||||
StringRef moduleTargetTriple = loadedModuleFile->getTargetTriple();
|
||||
llvm::Triple moduleTarget(llvm::Triple::normalize(moduleTargetTriple));
|
||||
|
||||
@@ -387,13 +387,6 @@ void SerializedModuleLoader::loadObjCMethods(
|
||||
}
|
||||
}
|
||||
|
||||
bool SerializedModuleLoader::isSerializedAST(StringRef data) {
|
||||
using serialization::MODULE_SIGNATURE;
|
||||
StringRef signatureStr(reinterpret_cast<const char *>(MODULE_SIGNATURE),
|
||||
llvm::array_lengthof(MODULE_SIGNATURE));
|
||||
return data.startswith(signatureStr);
|
||||
}
|
||||
|
||||
void SerializedModuleLoader::verifyAllModules() {
|
||||
#ifndef NDEBUG
|
||||
for (const LoadedModulePair &loaded : LoadedModuleFiles)
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#define DEBUG_TYPE "serialized-sil-loader"
|
||||
#include "swift/Serialization/SerializedSILLoader.h"
|
||||
#include "DeserializeSIL.h"
|
||||
#include "swift/Serialization/ModuleFile.h"
|
||||
#include "swift/Serialization/SerializedSILLoader.h"
|
||||
#include "swift/Serialization/SerializedModuleLoader.h"
|
||||
#include "swift/SIL/SILModule.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
|
||||
@@ -24,6 +25,7 @@ SerializedSILLoader::SerializedSILLoader(ASTContext &Ctx,
|
||||
Callback *callback) {
|
||||
|
||||
// Get a list of SerializedModules from ASTContext.
|
||||
// FIXME: Iterating over LoadedModules is not a good way to do this.
|
||||
for (auto &Entry : Ctx.LoadedModules) {
|
||||
for (auto File : Entry.second->getFiles()) {
|
||||
if (auto LoadedAST = dyn_cast<SerializedASTFile>(File)) {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "swift/ASTSectionImporter/ASTSectionImporter.h"
|
||||
#include "swift/Frontend/Frontend.h"
|
||||
#include "swift/Serialization/SerializedModuleLoader.h"
|
||||
#include "swift/Serialization/Validation.h"
|
||||
#include "swift/Basic/Dwarf.h"
|
||||
#include "llvm/Object/MachO.h"
|
||||
#include "llvm/Object/ObjectFile.h"
|
||||
@@ -59,19 +60,18 @@ void anchorForGetMainExecutable() {}
|
||||
using namespace llvm::MachO;
|
||||
|
||||
static void printValidationInfo(llvm::StringRef data) {
|
||||
swift::SerializedModuleLoader::ExtendedValidationInfo extendedInfo;
|
||||
swift::SerializedModuleLoader::ValidationInfo info =
|
||||
swift::SerializedModuleLoader::validateSerializedAST(data,
|
||||
&extendedInfo);
|
||||
if (info.status != swift::ModuleStatus::Valid)
|
||||
swift::serialization::ExtendedValidationInfo extendedInfo;
|
||||
swift::serialization::ValidationInfo info =
|
||||
swift::serialization::validateSerializedAST(data, &extendedInfo);
|
||||
if (info.status != swift::serialization::Status::Valid)
|
||||
return;
|
||||
|
||||
llvm::outs() << "- Target: " << info.targetTriple << "\n";
|
||||
if (!extendedInfo.getSDKPath().empty())
|
||||
llvm::outs() << "- SDK path: " << extendedInfo.getSDKPath() << "\n";
|
||||
if (!extendedInfo.getClangImporterOptions().empty()) {
|
||||
if (!extendedInfo.getExtraClangImporterOptions().empty()) {
|
||||
llvm::outs() << "- -Xcc options:";
|
||||
for (llvm::StringRef option : extendedInfo.getClangImporterOptions())
|
||||
for (llvm::StringRef option : extendedInfo.getExtraClangImporterOptions())
|
||||
llvm::outs() << " " << option;
|
||||
llvm::outs() << "\n";
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ int main(int argc, char **argv) {
|
||||
// name of the module to the file's name.
|
||||
Invocation.addInputBuffer(FileBufOrErr.get().get());
|
||||
bool IsModule = false;
|
||||
if (SerializedModuleLoader::isSerializedAST(FileBufOrErr.get()->getBuffer())){
|
||||
if (serialization::isSerializedAST(FileBufOrErr.get()->getBuffer())) {
|
||||
IsModule = true;
|
||||
const StringRef Stem = ModuleName.size() ?
|
||||
StringRef(ModuleName) :
|
||||
|
||||
@@ -372,7 +372,7 @@ int main(int argc, char **argv) {
|
||||
// name of the module to the file's name.
|
||||
Invocation.addInputBuffer(FileBufOrErr.get().get());
|
||||
bool IsModule = false;
|
||||
if (SerializedModuleLoader::isSerializedAST(FileBufOrErr.get()->getBuffer())){
|
||||
if (serialization::isSerializedAST(FileBufOrErr.get()->getBuffer())) {
|
||||
IsModule = true;
|
||||
const StringRef Stem = ModuleName.size() ?
|
||||
StringRef(ModuleName) :
|
||||
|
||||
Reference in New Issue
Block a user