|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 | 13 | #include "swift/Basic/BridgingUtils.h"
|
| 14 | +#include "swift/AST/Attr.h" |
| 15 | +#include "swift/AST/SemanticAttrs.h" |
14 | 16 | #include "swift/SIL/SILNode.h"
|
15 | 17 | #include "swift/SIL/ApplySite.h"
|
16 | 18 | #include "swift/SIL/SILBridgingUtils.h"
|
@@ -447,8 +449,21 @@ static Operand *castToOperand(BridgedOperand operand) {
|
447 | 449 | return const_cast<Operand *>(static_cast<const Operand *>(operand.op));
|
448 | 450 | }
|
449 | 451 |
|
450 |
| -BridgedValue Operand_getValue(BridgedOperand operand) { |
451 |
| - return {castToOperand(operand)->get()}; |
| 452 | +BridgedClassifiedValue Operand_getValue(BridgedOperand operand) { |
| 453 | + SILValue v = castToOperand(operand)->get(); |
| 454 | + BridgedClassifiedValue::Kind k; |
| 455 | + if (isa<SingleValueInstruction>(v)) { |
| 456 | + k = BridgedClassifiedValue::Kind::SingleValueInstruction; |
| 457 | + } else if (isa<SILArgument>(v)) { |
| 458 | + k = BridgedClassifiedValue::Kind::Argument; |
| 459 | + } else if (isa<MultipleValueInstructionResult>(v)) { |
| 460 | + k = BridgedClassifiedValue::Kind::MultipleValueInstructionResult; |
| 461 | + } else if (isa<SILUndef>(v)) { |
| 462 | + k = BridgedClassifiedValue::Kind::Undef; |
| 463 | + } else { |
| 464 | + llvm_unreachable("unknown SILValue"); |
| 465 | + } |
| 466 | + return {castToOperand(operand)->get(), k}; |
452 | 467 | }
|
453 | 468 |
|
454 | 469 | OptionalBridgedOperand Operand_nextUse(BridgedOperand operand) {
|
@@ -574,6 +589,48 @@ bool SILType_isCalleeConsumedFunction(BridgedType type) {
|
574 | 589 | return funcTy->isCalleeConsumed() && !funcTy->isNoEscape();
|
575 | 590 | }
|
576 | 591 |
|
| 592 | +static bool hasImmortalAttr(NominalTypeDecl *nominal) { |
| 593 | + if (auto *semAttr = nominal->getAttrs().getAttribute<SemanticsAttr>()) { |
| 594 | + if (semAttr->Value == semantics::ARC_IMMORTAL) { |
| 595 | + return true; |
| 596 | + } |
| 597 | + } |
| 598 | + return false; |
| 599 | +} |
| 600 | + |
| 601 | +static bool isMarkedAsImmortal(NominalTypeDecl *nominal) { |
| 602 | + if (hasImmortalAttr(nominal)) |
| 603 | + return true; |
| 604 | + |
| 605 | + if (!isa<ProtocolDecl>(nominal)) { |
| 606 | + for (ProtocolDecl *p : nominal->getAllProtocols()) { |
| 607 | + if (hasImmortalAttr(p)) |
| 608 | + return true; |
| 609 | + } |
| 610 | + } |
| 611 | + return false; |
| 612 | +} |
| 613 | + |
| 614 | +bool SILType_isMarkedAsImmortal(BridgedType type) { |
| 615 | + SILType ty = castToSILType(type); |
| 616 | + NominalTypeDecl *nominal = ty.getNominalOrBoundGenericNominal(); |
| 617 | + if (!nominal) |
| 618 | + return false; |
| 619 | + |
| 620 | + if (isMarkedAsImmortal(nominal)) |
| 621 | + return true; |
| 622 | + |
| 623 | + if (ClassDecl *cl = dyn_cast<ClassDecl>(nominal)) { |
| 624 | + cl = cl->getSuperclassDecl(); |
| 625 | + while (cl) { |
| 626 | + if (isMarkedAsImmortal(cl)) |
| 627 | + return true; |
| 628 | + cl = cl->getSuperclassDecl(); |
| 629 | + } |
| 630 | + } |
| 631 | + return false; |
| 632 | +} |
| 633 | + |
577 | 634 | SwiftInt SILType_getNumTupleElements(BridgedType type) {
|
578 | 635 | TupleType *tupleTy = castToSILType(type).castTo<TupleType>();
|
579 | 636 | return tupleTy->getNumElements();
|
|
0 commit comments