Skip to content

Commit e748f01

Browse files
author
Anxhelo Xhebraj
committed
Swift SIL: add constant checking for ref_element_addr field and global
1 parent 303ed78 commit e748f01

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

SwiftCompilerSources/Sources/SIL/GlobalVariable.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ final public class GlobalVariable : CustomStringConvertible, HasShortDescription
2525

2626
public var shortDescription: String { name.string }
2727

28+
public var isLet: Bool { SILGlobalVariable_isLet(bridged) != 0 }
29+
2830
// TODO: initializer instructions
2931

3032
var bridged: BridgedGlobalVar { BridgedGlobalVar(obj: SwiftObject(self)) }

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ final public class UncheckedTakeEnumDataAddrInst : SingleValueInstruction, Unary
448448

449449
final public class RefElementAddrInst : SingleValueInstruction, UnaryInstruction {
450450
public var fieldIndex: Int { RefElementAddrInst_fieldIndex(bridged) }
451+
452+
public var fieldIsLet: Bool { RefElementAddrInst_fieldIsLet(bridged) != 0 }
451453
}
452454

453455
final public class RefTailAddrInst : SingleValueInstruction, UnaryInstruction {}

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ SwiftInt SILFunction_hasSemanticsAttr(BridgedFunction function,
228228

229229
llvm::StringRef SILGlobalVariable_getName(BridgedGlobalVar global);
230230
std::string SILGlobalVariable_debugDescription(BridgedGlobalVar global);
231+
SwiftInt SILGlobalVariable_isLet(BridgedGlobalVar global);
231232

232233
OptionalBridgedBasicBlock SILBasicBlock_next(BridgedBasicBlock block);
233234
OptionalBridgedBasicBlock SILBasicBlock_previous(BridgedBasicBlock block);
@@ -316,6 +317,7 @@ SwiftInt InitEnumDataAddrInst_caseIndex(BridgedInstruction idea);
316317
SwiftInt UncheckedTakeEnumDataAddrInst_caseIndex(BridgedInstruction utedi);
317318
SwiftInt InjectEnumAddrInst_caseIndex(BridgedInstruction ieai);
318319
SwiftInt RefElementAddrInst_fieldIndex(BridgedInstruction reai);
320+
SwiftInt RefElementAddrInst_fieldIsLet(BridgedInstruction reai);
319321
SwiftInt PartialApplyInst_numArguments(BridgedInstruction ai);
320322
SwiftInt ApplyInst_numArguments(BridgedInstruction ai);
321323
SwiftInt PartialApply_getCalleeArgIndexOfFirstAppliedArg(BridgedInstruction pai);

lib/SIL/Utils/SILBridging.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,10 @@ std::string SILGlobalVariable_debugDescription(BridgedGlobalVar global) {
529529
return str;
530530
}
531531

532+
SwiftInt SILGlobalVariable_isLet(BridgedGlobalVar global) {
533+
return castToGlobal(global)->isLet();
534+
}
535+
532536
//===----------------------------------------------------------------------===//
533537
// SILInstruction
534538
//===----------------------------------------------------------------------===//
@@ -673,6 +677,10 @@ SwiftInt RefElementAddrInst_fieldIndex(BridgedInstruction reai) {
673677
return castToInst<RefElementAddrInst>(reai)->getFieldIndex();
674678
}
675679

680+
SwiftInt RefElementAddrInst_fieldIsLet(BridgedInstruction reai) {
681+
return castToInst<RefElementAddrInst>(reai)->getField()->isLet();
682+
}
683+
676684
SwiftInt PartialApplyInst_numArguments(BridgedInstruction pai) {
677685
return castToInst<PartialApplyInst>(pai)->getNumArguments();
678686
}

0 commit comments

Comments
 (0)