コード例 #1
0
 /**
  * Generate a boolean operation opcode
  *
  * <pre>
  * 1) IF br != 0 THEN x=1 ELSE x=0       replaced by INT_MOVE x=br
  *    IF br == 0 THEN x=0 ELSE x=1
  * 2) IF br == 0 THEN x=1 ELSE x=0       replaced by BOOLEAN_NOT x=br
  *    IF br != 0 THEN x=0 ELSE x=1
  * 3) IF v1 ~ v2 THEN x=1 ELSE x=0       replaced by BOOLEAN_CMP x=v1,v2,~
  * </pre>
  *
  * @param cb conditional branch instruction
  * @param res the operand for result
  * @param val1 value being compared
  * @param val2 value being compared with
  * @param cond comparison condition
  */
 private void booleanCompareHelper(
     Instruction cb, RegisterOperand res, Operand val1, Operand val2, ConditionOperand cond) {
   if ((val1 instanceof RegisterOperand)
       && ((RegisterOperand) val1).getType().isBooleanType()
       && (val2 instanceof IntConstantOperand)) {
     int value = ((IntConstantOperand) val2).value;
     if (VM.VerifyAssertions && (value != 0) && (value != 1)) {
       throw new OptimizingCompilerException("Invalid boolean value");
     }
     int c = cond.evaluate(value, 0);
     if (c == ConditionOperand.TRUE) {
       Unary.mutate(cb, BOOLEAN_NOT, res, val1);
       return;
     } else if (c == ConditionOperand.FALSE) {
       Move.mutate(cb, INT_MOVE, res, val1);
       return;
     }
   }
   BooleanCmp.mutate(
       cb,
       (cb.operator() == REF_IFCMP) ? BOOLEAN_CMP_ADDR : BOOLEAN_CMP_INT,
       res,
       val1,
       val2,
       cond,
       new BranchProfileOperand());
 }