1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
//===--- GenCast.h - Swift IR generation for dynamic casts ------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file provides the private interface to the dynamic cast code.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_IRGEN_GENCAST_H
#define SWIFT_IRGEN_GENCAST_H
#include "swift/AST/Types.h"
namespace llvm {
class Value;
class BasicBlock;
}
namespace swift {
class SILType;
class ProtocolDecl;
enum class CastConsumptionKind : unsigned char;
namespace irgen {
class Address;
class IRGenFunction;
class Explosion;
/// Discriminator for checked cast modes.
enum class CheckedCastMode : uint8_t {
Unconditional,
Conditional,
};
llvm::Value *emitCheckedCast(IRGenFunction &IGF,
Address src,
CanType fromType,
Address dest,
CanType toType,
CastConsumptionKind consumptionKind,
CheckedCastMode mode);
void emitScalarCheckedCast(IRGenFunction &IGF, Explosion &value,
SILType sourceLoweredType,
CanType sourceFormalType,
SILType targetLoweredType,
CanType targetFormalType,
CheckedCastMode mode,
GenericSignature fnSig,
Explosion &out);
llvm::Value *emitFastClassCastIfPossible(
IRGenFunction &IGF, llvm::Value *instance, CanType sourceFormalType,
CanType targetFormalType, bool sourceWrappedInOptional,
llvm::BasicBlock *&nilCheckBB, llvm::BasicBlock *&nilMergeBB);
/// Convert a class object to the given destination type,
/// using a runtime-checked cast.
llvm::Value *emitClassDowncast(IRGenFunction &IGF,
llvm::Value *from,
CanType toType,
CheckedCastMode mode);
/// A result of a cast generation function.
struct FailableCastResult {
/// An i1 value that's set to True if the cast succeeded.
llvm::Value *succeeded;
/// On success, this value stores the result of the cast operation.
llvm::Value *casted;
};
/// Convert the given value to the exact destination type.
FailableCastResult emitClassIdenticalCast(IRGenFunction &IGF,
llvm::Value *from,
SILType fromType,
SILType toType,
GenericSignature fnSig);
/// Emit a checked cast of a metatype.
void emitMetatypeDowncast(IRGenFunction &IGF,
llvm::Value *metatype,
CanMetatypeType toMetatype,
CheckedCastMode mode,
Explosion &ex);
/// Emit a checked cast to a class-constrained protocol or protocol
/// composition.
///
/// If a metatype kind is provided, the cast is done as a metatype cast. If
/// not, the cast is done as a class instance cast.
void emitScalarExistentialDowncast(
IRGenFunction &IGF, llvm::Value *orig, SILType srcType, SILType destType,
CheckedCastMode mode, std::optional<MetatypeRepresentation> metatypeKind,
GenericSignature fnSig, Explosion &ex);
/// Emit a checked cast from a metatype to AnyObject.
llvm::Value *emitMetatypeToAnyObjectDowncast(IRGenFunction &IGF,
llvm::Value *metatypeValue,
CanAnyMetatypeType type,
CheckedCastMode mode);
/// Emit a Protocol* value referencing an ObjC protocol.
llvm::Value *emitReferenceToObjCProtocol(IRGenFunction &IGF,
ProtocolDecl *proto);
} // end namespace irgen
} // end namespace swift
#endif
|