Class SwitchInstruction


  • public class SwitchInstruction
    extends IRInstruction
    A multi-way branch on an int key, covering both tableswitch and lookupswitch.
    • Constructor Detail

      • SwitchInstruction

        public SwitchInstruction​(Value key,
                                 IRBlock defaultTarget)
        Creates a switch with no cases yet and registers a use of an SSA key.
        Parameters:
        key - the value being switched on
        defaultTarget - the block taken when no case matches
    • Method Detail

      • getKey

        public Value getKey()
        Returns:
        the key
      • getDefaultTarget

        public IRBlock getDefaultTarget()
        Returns:
        the default target
      • setDefaultTarget

        public void setDefaultTarget​(IRBlock defaultTarget)
        Parameters:
        defaultTarget - the block taken when no case matches
      • addCase

        public void addCase​(int value,
                            IRBlock target)
        Adds a case to the switch instruction.
        Parameters:
        value - the case value
        target - the target block for this case
      • getCase

        public IRBlock getCase​(int value)
        Gets the target block for a specific case value.
        Parameters:
        value - the case value
        Returns:
        the target block, or default target if not found
      • replaceOperand

        public void replaceOperand​(Value oldValue,
                                   Value newValue)
        Description copied from class: IRInstruction
        Replaces an operand value with a new value.
        Specified by:
        replaceOperand in class IRInstruction
        Parameters:
        oldValue - the value to replace
        newValue - the replacement value
      • accept

        public <T> T accept​(IRVisitor<T> visitor)
        Description copied from class: IRInstruction
        Accepts a visitor for this instruction.
        Specified by:
        accept in class IRInstruction
        Type Parameters:
        T - the return type
        Parameters:
        visitor - the visitor to accept
        Returns:
        the visitor result
      • isTerminator

        public boolean isTerminator()
        Description copied from class: IRInstruction
        Checks if this instruction terminates a basic block.
        Overrides:
        isTerminator in class IRInstruction
        Returns:
        true if this is a terminator instruction
      • replaceTarget

        public void replaceTarget​(IRBlock oldTarget,
                                  IRBlock newTarget)
        Description copied from class: IRInstruction
        Replaces a target block in terminator instructions.
        Overrides:
        replaceTarget in class IRInstruction
        Parameters:
        oldTarget - the block to replace
        newTarget - the replacement block