Extend SILModule with an API for linking of SILFunctions by their SILDeclRef.

Before, providing a full SILFunction declaration object with a proper SILType was the only way to link a function. And constructing such a SILFunction declaration by hand using low-level SIL APIs is very annoying and requires a lot of code to be written. This new linkFunction API allows for a lookup using SILDeclRef and essentially performs linking of a SILFunction by its mangled name (assuming this name is unique), which is much easier to invoke. The new API is useful, e.g. when you need to link a well-known function from a standard library.

Swift SVN r26252
This commit is contained in:
Roman Levenstein
2015-03-18 06:11:22 +00:00
parent 02f542c2d0
commit 1f875b9bcb
7 changed files with 62 additions and 1 deletions

View File

@@ -57,6 +57,22 @@ SILFunction *SerializedSILLoader::lookupSILFunction(SILFunction *Callee) {
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))