本文整理汇总了C++中SILGenFunction类的典型用法代码示例。如果您正苦于以下问题:C++ SILGenFunction类的具体用法?C++ SILGenFunction怎么用?C++ SILGenFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SILGenFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emitOnceCall
static void emitOnceCall(SILGenFunction &SGF, VarDecl *global,
SILGlobalVariable *onceToken, SILFunction *onceFunc) {
SILType rawPointerSILTy
= SGF.getLoweredLoadableType(SGF.getASTContext().TheRawPointerType);
// Emit a reference to the global token.
SILValue onceTokenAddr = SGF.B.createGlobalAddr(global, onceToken);
onceTokenAddr = SGF.B.createAddressToPointer(global, onceTokenAddr,
rawPointerSILTy);
// Emit a reference to the function to execute.
SILValue onceFuncRef = SGF.B.createFunctionRef(global, onceFunc);
// Call Builtin.once.
SILValue onceArgs[] = {onceTokenAddr, onceFuncRef};
SGF.B.createBuiltin(global, SGF.getASTContext().getIdentifier("once"),
SGF.SGM.Types.getEmptyTupleType(), {}, onceArgs);
}
示例2: emitConstructorMetatypeArg
static SILValue emitConstructorMetatypeArg(SILGenFunction &gen,
ValueDecl *ctor) {
// In addition to the declared arguments, the constructor implicitly takes
// the metatype as its first argument, like a static function.
Type metatype = ctor->getInterfaceType()->castTo<AnyFunctionType>()->getInput();
auto *DC = ctor->getInnermostDeclContext();
auto &AC = gen.getASTContext();
auto VD = new (AC) ParamDecl(/*IsLet*/ true, SourceLoc(), SourceLoc(),
AC.getIdentifier("$metatype"), SourceLoc(),
AC.getIdentifier("$metatype"), Type(),
DC);
VD->setInterfaceType(metatype);
gen.AllocatorMetatype = gen.F.begin()->createFunctionArgument(
gen.getLoweredType(DC->mapTypeIntoContext(metatype)), VD);
return gen.AllocatorMetatype;
}
示例3: emitBuiltinBindMemory
static ManagedValue emitBuiltinBindMemory(SILGenFunction &gen,
SILLocation loc,
SubstitutionList subs,
ArrayRef<ManagedValue> args,
CanFunctionType formalApplyType,
SGFContext C) {
assert(subs.size() == 1 && "bindMemory should have a single substitution");
assert(args.size() == 3 && "bindMemory should have three argument");
// The substitution determines the element type for bound memory.
CanType boundFormalType = subs[0].getReplacement()->getCanonicalType();
SILType boundType = gen.getLoweredType(boundFormalType);
gen.B.createBindMemory(loc, args[0].getValue(),
args[1].getValue(), boundType);
return ManagedValue::forUnmanaged(gen.emitEmptyTuple(loc));
}
示例4: emitLValueForMemberInit
static LValue emitLValueForMemberInit(SILGenFunction &SGF, SILLocation loc,
VarDecl *selfDecl,
VarDecl *property) {
CanType selfFormalType = selfDecl->getType()->getCanonicalType();
auto self = emitSelfForMemberInit(SGF, loc, selfDecl);
return SGF.emitPropertyLValue(loc, self, selfFormalType, property,
LValueOptions(), SGFAccessKind::Write,
AccessSemantics::DirectToStorage);
}
示例5: emitBuiltinTypeTrait
static ManagedValue emitBuiltinTypeTrait(SILGenFunction &gen,
SILLocation loc,
SubstitutionList substitutions,
ArrayRef<ManagedValue> args,
CanFunctionType formalApplyType,
SGFContext C) {
assert(substitutions.size() == 1
&& "type trait should take a single type parameter");
assert(args.size() == 1
&& "type trait should take a single argument");
unsigned result;
auto traitTy = substitutions[0].getReplacement()->getCanonicalType();
switch ((traitTy.getPointer()->*Trait)()) {
// If the type obviously has or lacks the trait, emit a constant result.
case TypeTraitResult::IsNot:
result = 0;
break;
case TypeTraitResult::Is:
result = 1;
break;
// If not, emit the builtin call normally. Specialization may be able to
// eliminate it later, or we'll lower it away at IRGen time.
case TypeTraitResult::CanBe: {
auto &C = gen.getASTContext();
auto int8Ty = BuiltinIntegerType::get(8, C)->getCanonicalType();
auto apply = gen.B.createBuiltin(loc,
C.getIdentifier(getBuiltinName(Kind)),
SILType::getPrimitiveObjectType(int8Ty),
substitutions, args[0].getValue());
return ManagedValue::forUnmanaged(apply);
}
}
// Produce the result as an integer literal constant.
auto val = gen.B.createIntegerLiteral(
loc, SILType::getBuiltinIntegerType(8, gen.getASTContext()),
(uintmax_t)result);
return ManagedValue::forUnmanaged(val);
}
示例6: adjustForConditionalCheckedCastOperand
static ManagedValue
adjustForConditionalCheckedCastOperand(SILLocation loc, ManagedValue src,
CanType sourceType, CanType targetType,
SILGenFunction &SGF) {
// Reabstract to the most general abstraction, and put it into a
// temporary if necessary.
// Figure out if we need the value to be in a temporary.
bool requiresAddress =
!canUseScalarCheckedCastInstructions(SGF.SGM.M, sourceType, targetType);
AbstractionPattern abstraction = SGF.SGM.M.Types.getMostGeneralAbstraction();
auto &srcAbstractTL = SGF.getTypeLowering(abstraction, sourceType);
bool hasAbstraction = (src.getType() != srcAbstractTL.getLoweredType());
// Fast path: no re-abstraction required.
if (!hasAbstraction && (!requiresAddress || src.getType().isAddress())) {
return src;
}
std::unique_ptr<TemporaryInitialization> init;
SGFContext ctx;
if (requiresAddress) {
init = SGF.emitTemporary(loc, srcAbstractTL);
// Okay, if all we need to do is drop the value in an address,
// this is easy.
if (!hasAbstraction) {
SGF.B.createStore(loc, src.forward(SGF), init->getAddress());
init->finishInitialization(SGF);
return init->getManagedAddress();
}
ctx = SGFContext(init.get());
}
assert(hasAbstraction);
assert(src.getType().isObject() &&
"address-only type with abstraction difference?");
// Produce the value at +1.
return SGF.emitSubstToOrigValue(loc, src, abstraction, sourceType);
}
示例7: materialize
ManagedValue ManagedValue::materialize(SILGenFunction &SGF,
SILLocation loc) const {
auto temporary = SGF.emitTemporaryAllocation(loc, getType());
bool hadCleanup = hasCleanup();
// The temporary memory is +0 if the value was.
if (hadCleanup) {
SGF.B.emitStoreValueOperation(loc, forward(SGF), temporary,
StoreOwnershipQualifier::Init);
// SEMANTIC SIL TODO: This should really be called a temporary LValue.
return ManagedValue::forOwnedAddressRValue(temporary,
SGF.enterDestroyCleanup(temporary));
} else {
auto object = SGF.emitManagedBeginBorrow(loc, getValue());
SGF.emitManagedStoreBorrow(loc, object.getValue(), temporary);
return ManagedValue::forBorrowedAddressRValue(temporary);
}
}
示例8: emitBuiltinCondFail
/// Specialized emitter for Builtin.condfail.
static ManagedValue emitBuiltinCondFail(SILGenFunction &SGF,
SILLocation loc,
SubstitutionMap substitutions,
ArrayRef<ManagedValue> args,
SGFContext C) {
assert(args.size() == 1 && "condfail should be given one argument");
SGF.B.createCondFail(loc, args[0].getUnmanagedValue());
return ManagedValue::forUnmanaged(SGF.emitEmptyTuple(loc));
}
示例9: emitBuiltinFixLifetime
/// Specialized emitter for Builtin.fixLifetime.
static ManagedValue emitBuiltinFixLifetime(SILGenFunction &SGF,
SILLocation loc,
SubstitutionMap substitutions,
ArrayRef<ManagedValue> args,
SGFContext C) {
for (auto arg : args) {
SGF.B.createFixLifetime(loc, arg.getValue());
}
return ManagedValue::forUnmanaged(SGF.emitEmptyTuple(loc));
}
示例10: emitBuiltinAutorelease
static ManagedValue emitBuiltinAutorelease(SILGenFunction &gen,
SILLocation loc,
SubstitutionList substitutions,
ArrayRef<ManagedValue> args,
CanFunctionType formalApplyType,
SGFContext C) {
gen.B.createUnmanagedAutoreleaseValue(loc, args[0].getValue(),
gen.B.getDefaultAtomicity());
return ManagedValue::forUnmanaged(gen.emitEmptyTuple(loc));
}
示例11: formalAccessCopyUnmanaged
/// This is the same operation as 'copy', but works on +0 values that don't
/// have cleanups. It returns a +1 value with one.
ManagedValue ManagedValue::formalAccessCopyUnmanaged(SILGenFunction &SGF,
SILLocation loc) {
if (getType().isObject()) {
return SGF.B.createFormalAccessCopyValue(loc, *this);
}
SILValue result = SGF.emitTemporaryAllocation(loc, getType());
return SGF.B.createFormalAccessCopyAddr(loc, *this, result, IsNotTake,
IsInitialization);
}
示例12: emitUsingStorage
/// Emit a materializeForSet operation that projects storage, assuming
/// that no cleanups or callbacks are required.
SILValue MaterializeForSetEmitter::emitUsingStorage(SILGenFunction &gen,
SILLocation loc,
ManagedValue self,
RValue &&indices) {
LValue lvalue = buildLValue(gen, loc, self, std::move(indices),
AccessKind::ReadWrite);
ManagedValue address =
gen.emitAddressOfLValue(loc, std::move(lvalue), AccessKind::ReadWrite);
return address.getUnmanagedValue();
}
示例13: copyInto
/// Store a copy of this value with independent ownership into the given
/// uninitialized address.
void ManagedValue::copyInto(SILGenFunction &gen, SILValue dest, SILLocation L) {
auto &lowering = gen.getTypeLowering(getType());
if (lowering.isAddressOnly()) {
gen.B.createCopyAddr(L, getValue(), dest,
IsNotTake, IsInitialization);
return;
}
lowering.emitRetainValue(gen.B, L, getValue());
gen.B.createStore(L, getValue(), dest);
}
示例14: getAsSingleValue
ManagedValue ArgumentSource::getAsSingleValue(SILGenFunction &gen,
AbstractionPattern origFormalType,
SGFContext C) && {
auto loc = getLocation();
auto substFormalType = getSubstType();
ManagedValue outputValue = std::move(*this).getAsSingleValue(gen);
return gen.emitSubstToOrigValue(loc,
outputValue, origFormalType,
substFormalType, C);
}
示例15: forwardInto
void ArgumentSource::forwardInto(SILGenFunction &gen, Initialization *dest) && {
assert(!isLValue());
if (isRValue()) {
auto loc = getKnownRValueLocation();
return std::move(*this).asKnownRValue().forwardInto(gen, loc, dest);
}
auto e = std::move(*this).asKnownExpr();
return gen.emitExprInto(e, dest);
}