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.
Inherited Members
Namespace: Flame.Compiler.Flow
Assembly: Flame.Compiler.dll
Syntax
public sealed class SwitchFlow : BlockFlow
Constructors
| Improve this Doc View SourceSwitchFlow(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 SourceBranches
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
| Improve this Doc View SourceCases
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. |
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. |
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
| Improve this Doc View SourceIsIfElseFlow
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 |
IsIntegerSwitch
Tells if this switch flow contains only integer constants.
Declaration
public bool IsIntegerSwitch { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
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 |
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. |
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 SourceCreateConstantCheck(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 |
Branch | notEqualBranch | The branch to which flow is redirected if |
Returns
Type | Description |
---|---|
SwitchFlow | Switch flow that corresponds to a constant equality check. |
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. |
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 |
Branch | nullBranch | The branch to which flow is redirected if |
Branch | nonNullBranch | The branch to which flow is redirected if |
Returns
Type | Description |
---|---|
SwitchFlow | Switch flow that corresponds to a null check. |
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
| Improve this Doc View SourceWithBranches(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
| Improve this Doc View SourceWithInstructions(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. |