本文整理汇总了C++中SILDeclRef::getAsRegularLocation方法的典型用法代码示例。如果您正苦于以下问题:C++ SILDeclRef::getAsRegularLocation方法的具体用法?C++ SILDeclRef::getAsRegularLocation怎么用?C++ SILDeclRef::getAsRegularLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SILDeclRef
的用法示例。
在下文中一共展示了SILDeclRef::getAsRegularLocation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emitNativeToForeignThunk
void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) {
assert(thunk.isForeign);
SILDeclRef native = thunk.asForeign(false);
auto loc = thunk.getAsRegularLocation();
loc.markAutoGenerated();
Scope scope(Cleanups, CleanupLocation::get(loc));
// Bridge the arguments.
SmallVector<SILValue, 4> args;
Optional<ForeignErrorConvention> foreignError;
SILValue foreignErrorSlot;
auto objcFnTy = emitObjCThunkArguments(*this, loc, thunk, args,
foreignErrorSlot, foreignError);
auto nativeInfo = getConstantInfo(native);
auto swiftResultTy =
F.mapTypeIntoContext(nativeInfo.SILFnType->getSILResult());
auto objcResultTy =
F.mapTypeIntoContext(objcFnTy->getSILResult());
// Call the native entry point.
SILValue nativeFn = emitGlobalFunctionRef(loc, native, nativeInfo);
auto subs = F.getForwardingSubstitutions();
auto substTy = nativeInfo.SILFnType->substGenericArgs(
SGM.M, SGM.M.getSwiftModule(), subs);
SILType substSILTy = SILType::getPrimitiveObjectType(substTy);
CanType bridgedResultType = objcResultTy.getSwiftRValueType();
SILValue result;
assert(foreignError.hasValue() == substTy->hasErrorResult());
if (!substTy->hasErrorResult()) {
// Create the apply.
result = B.createApply(loc, nativeFn, substSILTy,
swiftResultTy, subs, args);
// Leave the scope immediately. This isn't really necessary; it
// just limits lifetimes a little bit more.
scope.pop();
// Now bridge the return value.
result = emitBridgeReturnValue(*this, loc, result,
objcFnTy->getRepresentation(),
bridgedResultType);
} else {
SILBasicBlock *contBB = createBasicBlock();
SILBasicBlock *errorBB = createBasicBlock();
SILBasicBlock *normalBB = createBasicBlock();
B.createTryApply(loc, nativeFn, substSILTy, subs, args,
normalBB, errorBB);
// Emit the non-error destination.
{
B.emitBlock(normalBB);
SILValue nativeResult = normalBB->createBBArg(swiftResultTy);
// In this branch, the eventual return value is mostly created
// by bridging the native return value, but we may need to
// adjust it slightly.
SILValue bridgedResult =
emitBridgeReturnValueForForeignError(loc, nativeResult,
objcFnTy->getRepresentation(),
objcResultTy,
foreignErrorSlot, *foreignError);
B.createBranch(loc, contBB, bridgedResult);
}
// Emit the error destination.
{
B.emitBlock(errorBB);
SILValue nativeError =
errorBB->createBBArg(substTy->getErrorResult().getSILType());
// In this branch, the eventual return value is mostly invented.
// Store the native error in the appropriate location and return.
SILValue bridgedResult =
emitBridgeErrorForForeignError(loc, nativeError, objcResultTy,
foreignErrorSlot, *foreignError);
B.createBranch(loc, contBB, bridgedResult);
}
// Emit the join block.
B.emitBlock(contBB);
result = contBB->createBBArg(objcResultTy);
// Leave the scope now.
scope.pop();
}
B.createReturn(loc, result);
}