Class ReverseOperatorMapper


  • public final class ReverseOperatorMapper
    extends Object
    Maps AST operators to IR operators (reverse of OperatorMapper in recovery).
    • Method Detail

      • toIRBinaryOp

        public static BinaryOp toIRBinaryOp​(BinaryOperator op)
        Maps AST binary operator to IR binary op, treating a compound assignment as its base operator.
        Parameters:
        op - the AST operator
        Returns:
        the IR op, or null for comparison and logical operators (handled separately)
      • toCompareOp

        public static CompareOp toCompareOp​(BinaryOperator op)
        Maps AST comparison operator to IR compare op for integer comparisons.
        Parameters:
        op - the AST operator
        Returns:
        the two-operand compare op, or null if the operator is not relational
      • toSingleOperandCompareOp

        public static CompareOp toSingleOperandCompareOp​(BinaryOperator op)
        Gets the single-operand compare op for checking against zero.
        Parameters:
        op - the AST operator
        Returns:
        the IFxx compare op, or null if the operator is not relational
      • toIRUnaryOp

        public static UnaryOp toIRUnaryOp​(UnaryOperator op)
        Maps AST unary operator to IR unary op.
        Parameters:
        op - the AST operator
        Returns:
        the IR op, or null for any operator other than negation
      • getCastOp

        public static UnaryOp getCastOp​(SourceType from,
                                        SourceType to)
        Gets the IR unary op for type casting between primitives.
        Parameters:
        from - the source type
        to - the target type
        Returns:
        the conversion op, or null if either side is not primitive or no conversion is needed
      • getBaseOperator

        public static BinaryOperator getBaseOperator​(BinaryOperator compoundOp)
        Gets the base operator for compound assignment (e.g., ADD_ASSIGN -> ADD).
        Parameters:
        compoundOp - the compound assignment operator
        Returns:
        the underlying arithmetic or bitwise operator, or null if it is not a compound assignment
      • isComparison

        public static boolean isComparison​(BinaryOperator op)
        Checks if operator is a comparison.
        Parameters:
        op - the operator to test
        Returns:
        true for the relational and equality operators
      • isLogical

        public static boolean isLogical​(BinaryOperator op)
        Checks if operator is logical (short-circuit AND/OR).
        Parameters:
        op - the operator to test
        Returns:
        true for the short-circuit operators
      • isAssignment

        public static boolean isAssignment​(BinaryOperator op)
        Checks if operator is an assignment.
        Parameters:
        op - the operator to test
        Returns:
        true for plain and compound assignment
      • getLongCompareOp

        public static BinaryOp getLongCompareOp()
        Gets the comparison op for long values (LCMP instruction).
        Returns:
        LCMP
      • getFloatCompareOp

        public static BinaryOp getFloatCompareOp​(boolean nanBias)
        Gets the comparison op for float values.
        Parameters:
        nanBias - true for FCMPG (1 on NaN), false for FCMPL (-1 on NaN)
        Returns:
        FCMPG or FCMPL
      • getDoubleCompareOp

        public static BinaryOp getDoubleCompareOp​(boolean nanBias)
        Gets the comparison op for double values.
        Parameters:
        nanBias - true for DCMPG (1 on NaN), false for DCMPL (-1 on NaN)
        Returns:
        DCMPG or DCMPL