Class Switch

java.lang.Object
EDU.purdue.cs.bloat.editor.Switch

public class Switch extends Object
Switch is used to hold the lookup values and branch targets of a tableswitch or lookup switch instruction.

The tableswitch low-to-high range of values is represented by storing each lookup value in the range. This allows the tableswitch to be replaced with a lookupswitch if branches are deleted.

  • Constructor Details

    • Switch

      public Switch(Label defaultTarget, Label[] targets, int[] values)
      Constructor.
      Parameters:
      defaultTarget - The default target of the switch.
      targets - The non-default branch targets of the switch.
      values - The lookup values of the switch. This array must be the same size as the targets array.
  • Method Details

    • setDefaultTarget

      public void setDefaultTarget(Label target)
      Set the default target of the switch.
      Parameters:
      target - The default target of the switch.
    • defaultTarget

      public Label defaultTarget()
      Get the default target of the switch.
      Returns:
      The default target of the switch.
    • targets

      public Label[] targets()
      Get the non-default branch targets of the switch. The targets are sorted by the corresponding lookup value.
      Returns:
      The non-default branch targets of the switch.
    • values

      public int[] values()
      Get the lookup values of the switch, sorted low to high.
      Returns:
      The lookup values of the switch.
    • hasContiguousValues

      public boolean hasContiguousValues()
      Check if the all the values in the range of lookup values are contiguous. If they are, a table switch can be used. If not a lookupswitch can be used.
      Returns:
      true if contiguous, false if not.
    • lowValue

      public int lowValue()
      Get the low value in the range the lookup values.
      Returns:
      The low value.
    • highValue

      public int highValue()
      Get the high value in the range the lookup values.
      Returns:
      The high value.
    • toString

      public String toString()
      Convert the operand to a string.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the operand.