Show / Hide Table of Contents

    Class SwitchFlow

    Switch flow, which tries to match a value against a list of constants in cases and takes an appropriate branch based on which case is selected, if any.

    Inheritance
    System.Object
    BlockFlow
    SwitchFlow
    Inherited Members
    BlockFlow.BranchTargets
    BlockFlow.Values
    BlockFlow.GetInstructionBuilders(BasicBlockBuilder)
    BlockFlow.MapValues(Func<ValueTag, ValueTag>)
    BlockFlow.MapValues(IReadOnlyDictionary<ValueTag, ValueTag>)
    BlockFlow.MapBlocks(Func<BasicBlockTag, BasicBlockTag>)
    BlockFlow.MapBlocks(IReadOnlyDictionary<BasicBlockTag, BasicBlockTag>)
    BlockFlow.MapBranches(Func<Branch, Branch>)
    BlockFlow.MapArguments(Func<BranchArgument, BranchArgument>)
    BlockFlow.MapArguments(IReadOnlyDictionary<BranchArgument, BranchArgument>)
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: Flame.Compiler.Flow
    Assembly: Flame.Compiler.dll
    Syntax
    public sealed class SwitchFlow : BlockFlow

    Constructors

    | Improve this Doc View Source

    SwitchFlow(Instruction, IReadOnlyList<SwitchCase>, Branch)

    Creates switch flow.

    Declaration
    public SwitchFlow(Instruction switchValue, IReadOnlyList<SwitchCase> cases, Branch defaultBranch)
    Parameters
    Type Name Description
    Instruction switchValue

    An instruction that produces the value to switch on.

    System.Collections.Generic.IReadOnlyList<SwitchCase> cases

    A list of switch cases.

    Branch defaultBranch

    A branch to take if none of the switch cases match the value being switched on.

    Remarks

    This constructor will simplify cases by unifying cases that point to the same branch and eliminate cases that are associated with no constants or point to the default branch.

    Properties

    | Improve this Doc View Source

    Branches

    Gets a list of branches this flow may take.

    Declaration
    public override IReadOnlyList<Branch> Branches { get; }
    Property Value
    Type Description
    System.Collections.Generic.IReadOnlyList<Branch>

    A list of potential branches.

    Overrides
    BlockFlow.Branches
    | Improve this Doc View Source

    Cases

    Gets the list of switch cases in this switch flow.

    Declaration
    public IReadOnlyList<SwitchCase> Cases { get; }
    Property Value
    Type Description
    System.Collections.Generic.IReadOnlyList<SwitchCase>

    A list of switch cases.

    | Improve this Doc View Source

    DefaultBranch

    Gets the default branch, which is only taken when no case matches.

    Declaration
    public Branch DefaultBranch { get; }
    Property Value
    Type Description
    Branch

    The default branch.

    | Improve this Doc View Source

    Instructions

    Gets a list of inner instructions for this block flow.

    Declaration
    public override IReadOnlyList<Instruction> Instructions { get; }
    Property Value
    Type Description
    System.Collections.Generic.IReadOnlyList<Instruction>

    The inner instructions.

    Overrides
    BlockFlow.Instructions
    | Improve this Doc View Source

    IsIfElseFlow

    Tells if this switch flow represents if-else flow, that is, if it has a single case matching on a single value.

    Declaration
    public bool IsIfElseFlow { get; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    IsIntegerSwitch

    Tells if this switch flow contains only integer constants.

    Declaration
    public bool IsIntegerSwitch { get; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    IsJumpTable

    Tells if the switch flow can be implemented as a jump table, that is, its cases do not have any branches with arguments and all of its case values are integer constants.

    Declaration
    public bool IsJumpTable { get; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    SwitchValue

    Gets an instruction that produces the value to switch on.

    Declaration
    public Instruction SwitchValue { get; }
    Property Value
    Type Description
    Instruction

    An instruction that produces the value to switch on.

    | Improve this Doc View Source

    ValueToBranchMap

    Gets a mapping of values to branches for this switch. This mapping does not include the default branch.

    Declaration
    public IReadOnlyDictionary<Constant, Branch> ValueToBranchMap { get; }
    Property Value
    Type Description
    System.Collections.Generic.IReadOnlyDictionary<Constant, Branch>

    A mapping of values to branches.

    Methods

    | Improve this Doc View Source

    CreateConstantCheck(Instruction, Constant, Branch, Branch)

    Creates switch flow that redirects control to one branch if a value equals a particular constant and to another branch otherwise.

    Declaration
    public static SwitchFlow CreateConstantCheck(Instruction value, Constant constant, Branch equalBranch, Branch notEqualBranch)
    Parameters
    Type Name Description
    Instruction value

    The value to compare to a constant.

    Constant constant

    The constant to compare the value to.

    Branch equalBranch

    The branch to which flow is redirected if value equals constant.

    Branch notEqualBranch

    The branch to which flow is redirected if value does not equal constant.

    Returns
    Type Description
    SwitchFlow

    Switch flow that corresponds to a constant equality check.

    | Improve this Doc View Source

    CreateIfElse(Instruction, Branch, Branch)

    Creates switch flow that corresponds to if-else flow on a Boolean condition.

    Declaration
    public static SwitchFlow CreateIfElse(Instruction condition, Branch ifBranch, Branch elseBranch)
    Parameters
    Type Name Description
    Instruction condition

    An instruction that produces Boolean condition.

    Branch ifBranch

    The 'if' branch, which is taken when the value produced by the Boolean condition is not false.

    Branch elseBranch

    The 'else' branch, which is taken when the value produced by the Boolean condition is false.

    Returns
    Type Description
    SwitchFlow

    Switch flow that corresponds to if-else flow.

    | Improve this Doc View Source

    CreateNullCheck(Instruction, Branch, Branch)

    Creates switch flow that redirects control to one branch if a value equals null and to another branch otherwise.

    Declaration
    public static SwitchFlow CreateNullCheck(Instruction value, Branch nullBranch, Branch nonNullBranch)
    Parameters
    Type Name Description
    Instruction value

    A value to compare to null.

    Branch nullBranch

    The branch to which flow is redirected if value equals null.

    Branch nonNullBranch

    The branch to which flow is redirected if value does not equal null.

    Returns
    Type Description
    SwitchFlow

    Switch flow that corresponds to a null check.

    | Improve this Doc View Source

    GetInstructionBuilder(BasicBlockBuilder, Int32)

    Gets an instruction builder for the nth anonymous instruction in this block flow.

    Declaration
    public override InstructionBuilder GetInstructionBuilder(BasicBlockBuilder block, int instructionIndex)
    Parameters
    Type Name Description
    BasicBlockBuilder block

    The block that defines this flow.

    System.Int32 instructionIndex

    The index of the anonymous instruction to create a builder for.

    Returns
    Type Description
    InstructionBuilder

    An instruction builder for an anonymous instruction.

    Overrides
    BlockFlow.GetInstructionBuilder(BasicBlockBuilder, Int32)
    | Improve this Doc View Source

    WithBranches(IReadOnlyList<Branch>)

    Replaces this flow's branches with a particular list of branches.

    Declaration
    public override BlockFlow WithBranches(IReadOnlyList<Branch> branches)
    Parameters
    Type Name Description
    System.Collections.Generic.IReadOnlyList<Branch> branches

    The new branches.

    Returns
    Type Description
    BlockFlow

    A new flow.

    Overrides
    BlockFlow.WithBranches(IReadOnlyList<Branch>)
    | Improve this Doc View Source

    WithInstructions(IReadOnlyList<Instruction>)

    Replaces this flow's inner instructions.

    Declaration
    public override BlockFlow WithInstructions(IReadOnlyList<Instruction> instructions)
    Parameters
    Type Name Description
    System.Collections.Generic.IReadOnlyList<Instruction> instructions

    The new instructions.

    Returns
    Type Description
    BlockFlow

    A new flow.

    Overrides
    BlockFlow.WithInstructions(IReadOnlyList<Instruction>)
    • Improve this Doc
    • View Source
    Back to top Generated by DocFX