本文整理汇总了C++中SILGenFunction::collectThunkParams方法的典型用法代码示例。如果您正苦于以下问题:C++ SILGenFunction::collectThunkParams方法的具体用法?C++ SILGenFunction::collectThunkParams怎么用?C++ SILGenFunction::collectThunkParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SILGenFunction
的用法示例。
在下文中一共展示了SILGenFunction::collectThunkParams方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emit
void MaterializeForSetEmitter::emit(SILGenFunction &gen) {
SILLocation loc = Witness;
loc.markAutoGenerated();
gen.F.setBare(IsBare);
SmallVector<ManagedValue, 4> params;
gen.collectThunkParams(loc, params, /*allowPlusZero*/ true);
ManagedValue self = params.back();
SILValue resultBuffer = params[0].getUnmanagedValue();
SILValue callbackBuffer = params[1].getUnmanagedValue();
auto indices = ArrayRef<ManagedValue>(params).slice(2).drop_back();
// If there's an abstraction difference, we always need to use the
// get/set pattern.
AccessStrategy strategy;
if (WitnessStorage->getType()->is<ReferenceStorageType>() ||
(RequirementStorageType != WitnessStorageType)) {
strategy = AccessStrategy::DispatchToAccessor;
} else {
strategy = WitnessStorage->getAccessStrategy(TheAccessSemantics,
AccessKind::ReadWrite);
}
// Handle the indices.
RValue indicesRV;
if (isa<SubscriptDecl>(WitnessStorage)) {
indicesRV = collectIndicesFromParameters(gen, loc, indices);
} else {
assert(indices.empty() && "indices for a non-subscript?");
}
// As above, assume that we don't need to reabstract 'self'.
// Choose the right implementation.
SILValue address;
SILFunction *callbackFn = nullptr;
switch (strategy) {
case AccessStrategy::BehaviorStorage:
llvm_unreachable("materializeForSet should never engage in behavior init");
case AccessStrategy::Storage:
address = emitUsingStorage(gen, loc, self, std::move(indicesRV));
break;
case AccessStrategy::Addressor:
address = emitUsingAddressor(gen, loc, self, std::move(indicesRV),
callbackBuffer, callbackFn);
break;
case AccessStrategy::DirectToAccessor:
case AccessStrategy::DispatchToAccessor:
address = emitUsingGetterSetter(gen, loc, self, std::move(indicesRV),
resultBuffer, callbackBuffer, callbackFn);
break;
}
// Return the address as a Builtin.RawPointer.
SILType rawPointerTy = SILType::getRawPointerType(gen.getASTContext());
address = gen.B.createAddressToPointer(loc, address, rawPointerTy);
SILType resultTupleTy = gen.F.mapTypeIntoContext(
gen.F.getLoweredFunctionType()->getSILResult());
SILType optCallbackTy = resultTupleTy.getTupleElementType(1);
// Form the callback.
SILValue callback;
if (callbackFn) {
// Make a reference to the callback.
callback = gen.B.createFunctionRef(loc, callbackFn);
callback = gen.B.createThinFunctionToPointer(loc, callback, rawPointerTy);
callback = gen.B.createOptionalSome(loc, callback, optCallbackTy);
} else {
// There is no callback.
callback = gen.B.createOptionalNone(loc, optCallbackTy);
}
// Form the result and return.
auto result = gen.B.createTuple(loc, resultTupleTy, { address, callback });
gen.Cleanups.emitCleanupsForReturn(CleanupLocation::get(loc));
gen.B.createReturn(loc, result);
}