mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Swift SIL: add some Builder APIs
* `createCheckedCastAddrBranch` * `createUnconditionalCheckedCastAddr` * `createDebugValue` * `createWitnessMethod` * `createInitEnumDataAddr`
This commit is contained in:
@@ -175,6 +175,38 @@ public struct Builder {
|
|||||||
let cast = bridged.createUpcast(value.bridged, type.bridged)
|
let cast = bridged.createUpcast(value.bridged, type.bridged)
|
||||||
return notifyNew(cast.getAs(UpcastInst.self))
|
return notifyNew(cast.getAs(UpcastInst.self))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
public func createCheckedCastAddrBranch(
|
||||||
|
source: Value, sourceFormalType: CanonicalType,
|
||||||
|
destination: Value, targetFormalType: CanonicalType,
|
||||||
|
consumptionKind: CheckedCastAddrBranchInst.CastConsumptionKind,
|
||||||
|
successBlock: BasicBlock,
|
||||||
|
failureBlock: BasicBlock
|
||||||
|
) -> CheckedCastAddrBranchInst {
|
||||||
|
|
||||||
|
let bridgedConsumption: BridgedInstruction.CastConsumptionKind
|
||||||
|
switch consumptionKind {
|
||||||
|
case .TakeAlways: bridgedConsumption = .TakeAlways
|
||||||
|
case .TakeOnSuccess: bridgedConsumption = .TakeOnSuccess
|
||||||
|
case .CopyOnSuccess: bridgedConsumption = .CopyOnSuccess
|
||||||
|
}
|
||||||
|
let cast = bridged.createCheckedCastAddrBranch(source.bridged, sourceFormalType.bridged,
|
||||||
|
destination.bridged, targetFormalType.bridged,
|
||||||
|
bridgedConsumption,
|
||||||
|
successBlock.bridged, failureBlock.bridged)
|
||||||
|
return notifyNew(cast.getAs(CheckedCastAddrBranchInst.self))
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
public func createUnconditionalCheckedCastAddr(
|
||||||
|
source: Value, sourceFormalType: CanonicalType,
|
||||||
|
destination: Value, targetFormalType: CanonicalType
|
||||||
|
) -> UnconditionalCheckedCastAddrInst {
|
||||||
|
let cast = bridged.createUnconditionalCheckedCastAddr(source.bridged, sourceFormalType.bridged,
|
||||||
|
destination.bridged, targetFormalType.bridged)
|
||||||
|
return notifyNew(cast.getAs(UnconditionalCheckedCastAddrInst.self))
|
||||||
|
}
|
||||||
|
|
||||||
public func createLoad(fromAddress: Value, ownership: LoadInst.LoadOwnership) -> LoadInst {
|
public func createLoad(fromAddress: Value, ownership: LoadInst.LoadOwnership) -> LoadInst {
|
||||||
let load = bridged.createLoad(fromAddress.bridged, ownership.rawValue)
|
let load = bridged.createLoad(fromAddress.bridged, ownership.rawValue)
|
||||||
@@ -285,6 +317,11 @@ public struct Builder {
|
|||||||
return notifyNew(bridged.createEndLifetime(value.bridged).getAs(EndLifetimeInst.self))
|
return notifyNew(bridged.createEndLifetime(value.bridged).getAs(EndLifetimeInst.self))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
public func createDebugValue(value: Value, debugVariable: DebugVariableInstruction.DebugVariable) -> DebugValueInst {
|
||||||
|
return notifyNew(bridged.createDebugValue(value.bridged, debugVariable).getAs(DebugValueInst.self))
|
||||||
|
}
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func createDebugStep() -> DebugStepInst {
|
public func createDebugStep() -> DebugStepInst {
|
||||||
return notifyNew(bridged.createDebugStep().getAs(DebugStepInst.self))
|
return notifyNew(bridged.createDebugStep().getAs(DebugStepInst.self))
|
||||||
@@ -324,6 +361,14 @@ public struct Builder {
|
|||||||
return notifyNew(apply.getAs(TryApplyInst.self))
|
return notifyNew(apply.getAs(TryApplyInst.self))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func createWitnessMethod(lookupType: CanonicalType,
|
||||||
|
conformance: Conformance,
|
||||||
|
member: DeclRef,
|
||||||
|
methodType: Type) -> WitnessMethodInst {
|
||||||
|
return notifyNew(bridged.createWitnessMethod(lookupType.bridged, conformance.bridged,
|
||||||
|
member.bridged, methodType.bridged).getAs(WitnessMethodInst.self))
|
||||||
|
}
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func createReturn(of value: Value) -> ReturnInst {
|
public func createReturn(of value: Value) -> ReturnInst {
|
||||||
return notifyNew(bridged.createReturn(value.bridged).getAs(ReturnInst.self))
|
return notifyNew(bridged.createReturn(value.bridged).getAs(ReturnInst.self))
|
||||||
@@ -347,6 +392,11 @@ public struct Builder {
|
|||||||
return notifyNew(uteda.getAs(UncheckedTakeEnumDataAddrInst.self))
|
return notifyNew(uteda.getAs(UncheckedTakeEnumDataAddrInst.self))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func createInitEnumDataAddr(enumAddress: Value, caseIndex: Int, type: Type) -> InitEnumDataAddrInst {
|
||||||
|
let uteda = bridged.createInitEnumDataAddr(enumAddress.bridged, caseIndex, type.bridged)
|
||||||
|
return notifyNew(uteda.getAs(InitEnumDataAddrInst.self))
|
||||||
|
}
|
||||||
|
|
||||||
public func createEnum(caseIndex: Int, payload: Value?, enumType: Type) -> EnumInst {
|
public func createEnum(caseIndex: Int, payload: Value?, enumType: Type) -> EnumInst {
|
||||||
let enumInst = bridged.createEnum(caseIndex, payload.bridged, enumType.bridged)
|
let enumInst = bridged.createEnum(caseIndex, payload.bridged, enumType.bridged)
|
||||||
return notifyNew(enumInst.getAs(EnumInst.self))
|
return notifyNew(enumInst.getAs(EnumInst.self))
|
||||||
|
|||||||
@@ -1135,6 +1135,14 @@ struct BridgedBuilder{
|
|||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createUncheckedAddrCast(BridgedValue op,
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createUncheckedAddrCast(BridgedValue op,
|
||||||
BridgedType type) const;
|
BridgedType type) const;
|
||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createUpcast(BridgedValue op, BridgedType type) const;
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createUpcast(BridgedValue op, BridgedType type) const;
|
||||||
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createCheckedCastAddrBranch(
|
||||||
|
BridgedValue source, BridgedCanType sourceFormalType,
|
||||||
|
BridgedValue destination, BridgedCanType targetFormalType,
|
||||||
|
BridgedInstruction::CastConsumptionKind consumptionKind,
|
||||||
|
BridgedBasicBlock successBlock, BridgedBasicBlock failureBlock) const;
|
||||||
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createUnconditionalCheckedCastAddr(
|
||||||
|
BridgedValue source, BridgedCanType sourceFormalType,
|
||||||
|
BridgedValue destination, BridgedCanType targetFormalType) const;
|
||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createLoad(BridgedValue op, SwiftInt ownership) const;
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createLoad(BridgedValue op, SwiftInt ownership) const;
|
||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createLoadBorrow(BridgedValue op) const;
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createLoadBorrow(BridgedValue op) const;
|
||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createBeginDeallocRef(BridgedValue reference,
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createBeginDeallocRef(BridgedValue reference,
|
||||||
@@ -1162,6 +1170,8 @@ struct BridgedBuilder{
|
|||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createDestroyValue(BridgedValue op) const;
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createDestroyValue(BridgedValue op) const;
|
||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createDestroyAddr(BridgedValue op) const;
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createDestroyAddr(BridgedValue op) const;
|
||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createEndLifetime(BridgedValue op) const;
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createEndLifetime(BridgedValue op) const;
|
||||||
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createDebugValue(BridgedValue src,
|
||||||
|
BridgedSILDebugVariable var) const;
|
||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createDebugStep() const;
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createDebugStep() const;
|
||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createApply(BridgedValue function,
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createApply(BridgedValue function,
|
||||||
BridgedSubstitutionMap subMap,
|
BridgedSubstitutionMap subMap,
|
||||||
@@ -1173,6 +1183,9 @@ struct BridgedBuilder{
|
|||||||
BridgedBasicBlock normalBB, BridgedBasicBlock errorBB,
|
BridgedBasicBlock normalBB, BridgedBasicBlock errorBB,
|
||||||
bool isNonAsync,
|
bool isNonAsync,
|
||||||
BridgedGenericSpecializationInformation specInfo) const;
|
BridgedGenericSpecializationInformation specInfo) const;
|
||||||
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createWitnessMethod(BridgedCanType lookupType,
|
||||||
|
BridgedConformance conformance,
|
||||||
|
BridgedDeclRef member, BridgedType methodType) const;
|
||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createReturn(BridgedValue op) const;
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createReturn(BridgedValue op) const;
|
||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createThrow(BridgedValue op) const;
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createThrow(BridgedValue op) const;
|
||||||
SWIFT_IMPORT_UNSAFE BridgedInstruction createSwitchEnumInst(BridgedValue enumVal,
|
SWIFT_IMPORT_UNSAFE BridgedInstruction createSwitchEnumInst(BridgedValue enumVal,
|
||||||
@@ -1185,6 +1198,9 @@ struct BridgedBuilder{
|
|||||||
SwiftInt caseIdx, BridgedType resultType) const;
|
SwiftInt caseIdx, BridgedType resultType) const;
|
||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createUncheckedTakeEnumDataAddr(BridgedValue enumAddr,
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createUncheckedTakeEnumDataAddr(BridgedValue enumAddr,
|
||||||
SwiftInt caseIdx) const;
|
SwiftInt caseIdx) const;
|
||||||
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createInitEnumDataAddr(BridgedValue enumAddr,
|
||||||
|
SwiftInt caseIdx,
|
||||||
|
BridgedType type) const;
|
||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createEnum(SwiftInt caseIdx, OptionalBridgedValue payload,
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createEnum(SwiftInt caseIdx, OptionalBridgedValue payload,
|
||||||
BridgedType resultType) const;
|
BridgedType resultType) const;
|
||||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createThinToThickFunction(BridgedValue fn,
|
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createThinToThickFunction(BridgedValue fn,
|
||||||
|
|||||||
@@ -2128,6 +2128,28 @@ BridgedInstruction BridgedBuilder::createUpcast(BridgedValue op, BridgedType typ
|
|||||||
type.unbridged())};
|
type.unbridged())};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BridgedInstruction BridgedBuilder::createCheckedCastAddrBranch(
|
||||||
|
BridgedValue source, BridgedCanType sourceFormalType,
|
||||||
|
BridgedValue destination, BridgedCanType targetFormalType,
|
||||||
|
BridgedInstruction::CastConsumptionKind consumptionKind,
|
||||||
|
BridgedBasicBlock successBlock, BridgedBasicBlock failureBlock) const
|
||||||
|
{
|
||||||
|
return {unbridged().createCheckedCastAddrBranch(
|
||||||
|
regularLoc(), (swift::CastConsumptionKind)consumptionKind,
|
||||||
|
source.getSILValue(), sourceFormalType.unbridged(),
|
||||||
|
destination.getSILValue(), targetFormalType.unbridged(),
|
||||||
|
successBlock.unbridged(), failureBlock.unbridged())};
|
||||||
|
}
|
||||||
|
|
||||||
|
BridgedInstruction BridgedBuilder::createUnconditionalCheckedCastAddr(
|
||||||
|
BridgedValue source, BridgedCanType sourceFormalType,
|
||||||
|
BridgedValue destination, BridgedCanType targetFormalType) const
|
||||||
|
{
|
||||||
|
return {unbridged().createUnconditionalCheckedCastAddr(
|
||||||
|
regularLoc(), source.getSILValue(), sourceFormalType.unbridged(),
|
||||||
|
destination.getSILValue(), targetFormalType.unbridged())};
|
||||||
|
}
|
||||||
|
|
||||||
BridgedInstruction BridgedBuilder::createLoad(BridgedValue op, SwiftInt ownership) const {
|
BridgedInstruction BridgedBuilder::createLoad(BridgedValue op, SwiftInt ownership) const {
|
||||||
return {unbridged().createLoad(regularLoc(), op.getSILValue(),
|
return {unbridged().createLoad(regularLoc(), op.getSILValue(),
|
||||||
(swift::LoadOwnershipQualifier)ownership)};
|
(swift::LoadOwnershipQualifier)ownership)};
|
||||||
@@ -2226,6 +2248,11 @@ BridgedInstruction BridgedBuilder::createEndLifetime(BridgedValue op) const {
|
|||||||
return {unbridged().createEndLifetime(regularLoc(), op.getSILValue())};
|
return {unbridged().createEndLifetime(regularLoc(), op.getSILValue())};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BridgedInstruction BridgedBuilder::createDebugValue(BridgedValue op,
|
||||||
|
BridgedSILDebugVariable var) const {
|
||||||
|
return {unbridged().createDebugValue(regularLoc(), op.getSILValue(), var.unbridge())};
|
||||||
|
}
|
||||||
|
|
||||||
BridgedInstruction BridgedBuilder::createDebugStep() const {
|
BridgedInstruction BridgedBuilder::createDebugStep() const {
|
||||||
return {unbridged().createDebugStep(regularLoc())};
|
return {unbridged().createDebugStep(regularLoc())};
|
||||||
}
|
}
|
||||||
@@ -2257,6 +2284,14 @@ BridgedInstruction BridgedBuilder::createTryApply(BridgedValue function, Bridged
|
|||||||
arguments.getValues(argValues), normalBB.unbridged(), errorBB.unbridged(), applyOpts, specInfo.data)};
|
arguments.getValues(argValues), normalBB.unbridged(), errorBB.unbridged(), applyOpts, specInfo.data)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BridgedInstruction BridgedBuilder::createWitnessMethod(BridgedCanType lookupType,
|
||||||
|
BridgedConformance conformance,
|
||||||
|
BridgedDeclRef member, BridgedType methodType) const {
|
||||||
|
return {unbridged().createWitnessMethod(regularLoc(), lookupType.unbridged(), conformance.unbridged(),
|
||||||
|
member.unbridged(), methodType.unbridged())};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BridgedInstruction BridgedBuilder::createReturn(BridgedValue op) const {
|
BridgedInstruction BridgedBuilder::createReturn(BridgedValue op) const {
|
||||||
return {unbridged().createReturn(regularLoc(), op.getSILValue())};
|
return {unbridged().createReturn(regularLoc(), op.getSILValue())};
|
||||||
}
|
}
|
||||||
@@ -2278,6 +2313,14 @@ BridgedInstruction BridgedBuilder::createUncheckedTakeEnumDataAddr(BridgedValue
|
|||||||
return {unbridged().createUncheckedTakeEnumDataAddr(regularLoc(), en, en->getType().getEnumElement(caseIdx))};
|
return {unbridged().createUncheckedTakeEnumDataAddr(regularLoc(), en, en->getType().getEnumElement(caseIdx))};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BridgedInstruction BridgedBuilder::createInitEnumDataAddr(BridgedValue enumAddr,
|
||||||
|
SwiftInt caseIdx,
|
||||||
|
BridgedType type) const {
|
||||||
|
swift::SILValue en = enumAddr.getSILValue();
|
||||||
|
return {unbridged().createInitEnumDataAddr(regularLoc(), en, en->getType().getEnumElement(caseIdx),
|
||||||
|
type.unbridged())};
|
||||||
|
}
|
||||||
|
|
||||||
BridgedInstruction BridgedBuilder::createEnum(SwiftInt caseIdx, OptionalBridgedValue payload,
|
BridgedInstruction BridgedBuilder::createEnum(SwiftInt caseIdx, OptionalBridgedValue payload,
|
||||||
BridgedType resultType) const {
|
BridgedType resultType) const {
|
||||||
swift::EnumElementDecl *caseDecl =
|
swift::EnumElementDecl *caseDecl =
|
||||||
|
|||||||
Reference in New Issue
Block a user