mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user