[SILGen] Make it possible to emit generator function given its body and result type

This would be used for runtime attribute generators that have to
emit `if #available(...)` block in the body which is much easier
to do during Sema.
This commit is contained in:
Pavel Yaskevich
2022-12-02 17:44:28 -08:00
parent bcaaa91a53
commit 91042d77aa
2 changed files with 27 additions and 0 deletions

View File

@@ -1153,6 +1153,28 @@ void SILGenFunction::emitGeneratorFunction(SILDeclRef function, VarDecl *var) {
emitEpilog(loc);
}
void SILGenFunction::emitGeneratorFunction(SILDeclRef function,
Type resultInterfaceType,
BraceStmt *body) {
MagicFunctionName = SILGenModule::getMagicFunctionName(function);
RegularLocation loc(body);
loc.markAutoGenerated();
auto *dc = function.getDecl()->getInnermostDeclContext();
auto captureInfo = SGM.M.Types.getLoweredLocalCaptures(function);
emitProlog(captureInfo, ParameterList::createEmpty(getASTContext()),
/*selfParam=*/nullptr, dc, resultInterfaceType, /*throws=*/false,
SourceLoc());
prepareEpilog(resultInterfaceType, /*hasThrows=*/false, CleanupLocation(loc));
emitStmt(body);
emitEpilog(loc);
mergeCleanupBlocks();
}
void SILGenFunction::emitProfilerIncrement(ASTNode Node) {
emitProfilerIncrement(ProfileCounterRef::node(Node));
}