forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerializedSILLoader.cpp
149 lines (132 loc) · 4.69 KB
/
SerializedSILLoader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//===--- 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
//
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "serialized-sil-loader"
#include "swift/Serialization/SerializedSILLoader.h"
#include "DeserializeSIL.h"
#include "swift/Serialization/ModuleFile.h"
#include "swift/Serialization/SerializedModuleLoader.h"
#include "swift/SIL/SILModule.h"
#include "llvm/Support/Debug.h"
using namespace swift;
SerializedSILLoader::SerializedSILLoader(ASTContext &Ctx,
SILModule *SILMod,
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)) {
auto Des = new SILDeserializer(&LoadedAST->File, *SILMod, callback);
#ifndef NDEBUG
SILMod->verify();
#endif
LoadedSILSections.emplace_back(Des);
}
}
}
}
SerializedSILLoader::~SerializedSILLoader() {}
SILFunction *SerializedSILLoader::lookupSILFunction(SILFunction *Callee) {
// It is possible that one module has a declaration of a SILFunction, while
// another has the full definition.
SILFunction *retVal = nullptr;
for (auto &Des : LoadedSILSections) {
if (auto Func = Des->lookupSILFunction(Callee)) {
DEBUG(llvm::dbgs() << "Deserialized " << Func->getName() << " from "
<< Des->getModuleIdentifier().str() << "\n");
if (!Func->empty())
return Func;
retVal = Func;
}
}
return retVal;
}
SILFunction *SerializedSILLoader::lookupSILFunction(SILDeclRef Decl) {
llvm::SmallString<32> Name;
Decl.mangle(Name);
// It is possible that one module has a declaration of a SILFunction, while
// another has the full definition.
SILFunction *retVal = nullptr;
for (auto &Des : LoadedSILSections) {
if (auto Func = Des->lookupSILFunction(Name)) {
DEBUG(llvm::dbgs() << "Deserialized " << Func->getName() << " from "
<< Des->getModuleIdentifier().str() << "\n");
if (!Func->empty())
return Func;
retVal = Func;
}
}
return retVal;
}
SILFunction *SerializedSILLoader::lookupSILFunction(StringRef Name) {
// It is possible that one module has a declaration of a SILFunction, while
// another has the full definition.
SILFunction *retVal = nullptr;
for (auto &Des : LoadedSILSections) {
if (auto Func = Des->lookupSILFunction(Name)) {
DEBUG(llvm::dbgs() << "Deserialized " << Func->getName() << " from "
<< Des->getModuleIdentifier().str() << "\n");
if (!Func->empty())
return Func;
retVal = Func;
}
}
return retVal;
}
SILVTable *SerializedSILLoader::lookupVTable(Identifier Name) {
for (auto &Des : LoadedSILSections) {
if (auto VT = Des->lookupVTable(Name))
return VT;
}
return nullptr;
}
SILWitnessTable *SerializedSILLoader::lookupWitnessTable(SILWitnessTable *WT) {
for (auto &Des : LoadedSILSections)
if (auto wT = Des->lookupWitnessTable(WT))
return wT;
return nullptr;
}
void SerializedSILLoader::invalidateCaches() {
for (auto &Des : LoadedSILSections)
Des->invalidateFunctionCache();
}
void SerializedSILLoader::getAll() {
for (auto &Des : LoadedSILSections)
Des->getAll();
}
// FIXME: Not the best interface. We know exactly which FileUnits may have SIL
// those in the main module.
void SerializedSILLoader::getAllForModule(Identifier Mod,
FileUnit *PrimaryFile) {
for (auto &Des : LoadedSILSections) {
if (Des->getModuleIdentifier() == Mod) {
Des->getAll(PrimaryFile ?
Des->getFile() != PrimaryFile : false);
}
}
}
void SerializedSILLoader::getAllSILFunctions() {
for (auto &Des : LoadedSILSections)
Des->getAllSILFunctions();
}
/// Deserialize all VTables in all SILModules.
void SerializedSILLoader::getAllVTables() {
for (auto &Des : LoadedSILSections)
Des->getAllVTables();
}
/// Deserialize all WitnessTables in all SILModules.
void SerializedSILLoader::getAllWitnessTables() {
for (auto &Des : LoadedSILSections)
Des->getAllWitnessTables();
}
// Anchor the SerializedSILLoader v-table.
void SerializedSILLoader::Callback::_anchor() {}