Files
swift-mirror/lib/Serialization/SerializedSILLoader.cpp
Manman Ren b2bd2e9f8d SIL Serialization: handle SILVTable.
We add two records in sil_block to specify a Vtable and its entry list. Two
records are also added in sil_index_block for mapping from name to ID and
from ID to bit offset.

Two functions are added to SerializedSILLoader: to look up a specific VTable
given the class name or to deserialize all VTables in all SILModules. The latter
is mostly used for testing.

We serialize a VTable if the class is fragile and deserialize it via
SerializedSILLoader::lookupVTable.


Swift SVN r9746
2013-10-28 23:38:48 +00:00

54 lines
1.7 KiB
C++

//===--- SerializedSILLoader.cpp - A loader for SIL sections --------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "DeserializeSIL.h"
#include "ModuleFile.h"
#include "swift/Serialization/SerializedSILLoader.h"
#include "swift/SIL/SILModule.h"
using namespace swift;
SerializedSILLoader::SerializedSILLoader(ASTContext &Ctx,
SILModule *SILMod) {
// Get a list of SerializedModules from ASTContext.
for (auto &CtxM : Ctx.LoadedModules) {
if (SerializedModule *LM = dyn_cast<SerializedModule>(CtxM.getValue())) {
auto Des = new SILDeserializer(&LM->File, *SILMod, Ctx);
LoadedSILSections.emplace_back(std::unique_ptr<SILDeserializer>(Des));
}
}
}
SerializedSILLoader::~SerializedSILLoader() = default;
SILFunction *SerializedSILLoader::lookupSILFunction(SILFunction *Callee) {
for (auto &Des : LoadedSILSections) {
if (auto Func = Des->lookupSILFunction(Callee))
return Func;
}
return nullptr;
}
SILVTable *SerializedSILLoader::lookupVTable(Identifier Name) {
for (auto &Des : LoadedSILSections) {
if (auto VT = Des->lookupVTable(Name))
return VT;
}
return nullptr;
}
/// Deserialize all VTables in all SILModules.
void SerializedSILLoader::getAllVTables() {
for (auto &Des : LoadedSILSections)
Des->getAllVTables();
}