Skip to content

Commit 46c3a17

Browse files
committed
libswift: add Type.isAddress and Type.isObject
1 parent 891f53d commit 46c3a17

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ BridgedStringRef SILNode_debugDescription(BridgedNode node);
169169
OptionalBridgedOperand SILValue_firstUse(BridgedValue value);
170170
BridgedType SILValue_getType(BridgedValue value);
171171

172+
SwiftInt SILType_isAddress(BridgedType);
173+
172174
BridgedBasicBlock SILArgument_getParent(BridgedArgument argument);
173175

174176
OptionalBridgedInstruction SILInstruction_next(BridgedInstruction inst);

include/swift/SIL/SILBridgingUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ inline SILValue castToSILValue(BridgedValue value) {
7070
return static_cast<ValueBase *>(value.obj);
7171
}
7272

73+
inline SILType castToSILType(BridgedType type) {
74+
return SILType::getFromOpaqueValue(type.typePtr);
75+
}
76+
7377
template <class I = SILInstruction> I *castToInst(BridgedInstruction inst) {
7478
return cast<I>(static_cast<SILNode *>(inst.obj)->castToInstruction());
7579
}

lib/SIL/Utils/SILBridging.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@ BridgedType SILValue_getType(BridgedValue value) {
274274
return { castToSILValue(value)->getType().getOpaqueValue() };
275275
}
276276

277+
//===----------------------------------------------------------------------===//
278+
// SILType
279+
//===----------------------------------------------------------------------===//
280+
281+
SwiftInt SILType_isAddress(BridgedType type) {
282+
return castToSILType(type).isAddress();
283+
}
284+
277285
//===----------------------------------------------------------------------===//
278286
// SILGlobalVariable
279287
//===----------------------------------------------------------------------===//

libswift/Sources/SIL/Type.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
import SILBridging
1414

1515
public struct Type {
16-
var silType: BridgedType
16+
var bridged: BridgedType
17+
18+
public var isAddress: Bool { SILType_isAddress(bridged) != 0 }
19+
public var isObject: Bool { !isAddress }
1720
}

0 commit comments

Comments
 (0)