Class SwitchInstruction

  • All Implemented Interfaces:
    Constants, IInstruction, java.lang.Cloneable

    public final class SwitchInstruction
    extends Instruction
    This instruction represents all forms of switch instructions.
    • Method Detail

      • getDefaultLabel

        public int getDefaultLabel()
        Returns:
        the label which is branched to if none of the cases match
      • getCasesAndLabels

        public int[] getCasesAndLabels()
        Returns:
        an array of flattened (case, label) pairs, sorted in increasing order by case
      • make

        public static SwitchInstruction make​(int[] casesAndLabels,
                                             int defaultLabel)
        Make a switch instruction.
        Parameters:
        casesAndLabels - an array of flattened (case, label) pairs, sorted in increasing order by case
        defaultLabel - the default label to branch to if no cases match
        Throws:
        java.lang.IllegalArgumentException - if casesAndLabels is null
      • getBranchTargets

        public int[] getBranchTargets()
        Specified by:
        getBranchTargets in interface IInstruction
        Overrides:
        getBranchTargets in class Instruction
        Returns:
        an array containing the labels this instruction can branch to (not including the following instruction if this instruction 'falls through')
      • redirectTargets

        public IInstruction redirectTargets​(int[] targetMap)
                                     throws java.lang.IllegalArgumentException
        Specified by:
        redirectTargets in interface IInstruction
        Overrides:
        redirectTargets in class Instruction
        Returns:
        an Instruction equivalent to this one but with any branch labels updated by looking them up in the targetMap array
        Throws:
        java.lang.IllegalArgumentException
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • visit

        public void visit​(IInstruction.Visitor v)
                   throws java.lang.IllegalArgumentException
        Description copied from class: Instruction
        Apply a Visitor to this instruction. We invoke the appropriate Visitor method according to the type of this instruction.
        Specified by:
        visit in interface IInstruction
        Specified by:
        visit in class Instruction
        Throws:
        java.lang.IllegalArgumentException
      • isPEI

        public boolean isPEI()
        Description copied from interface: IInstruction
        PEI == "Potentially excepting instruction"
        Returns:
        true iff this instruction might throw an exception