src/jdk/nashorn/internal/codegen/Condition.java

Print this page




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.codegen;
  27 
  28 import static jdk.internal.org.objectweb.asm.Opcodes.IFEQ;
  29 import static jdk.internal.org.objectweb.asm.Opcodes.IFGE;
  30 import static jdk.internal.org.objectweb.asm.Opcodes.IFGT;
  31 import static jdk.internal.org.objectweb.asm.Opcodes.IFLE;
  32 import static jdk.internal.org.objectweb.asm.Opcodes.IFLT;
  33 import static jdk.internal.org.objectweb.asm.Opcodes.IFNE;
  34 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ACMPEQ;
  35 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ACMPNE;
  36 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPEQ;
  37 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPGE;
  38 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPGT;
  39 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPLE;
  40 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPLT;
  41 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPNE;
  42 import jdk.nashorn.internal.ir.RuntimeNode;
  43 
  44 /**
  45  * Condition enum used for all kinds of jumps, regardless of type
  46  */
  47 enum Condition {
  48     EQ,
  49     NE,
  50     LE,
  51     LT,
  52     GE,
  53     GT;
  54 
  55     static Condition forRuntimeRequest(final RuntimeNode.Request request) {
  56         try {
  57             final String reqString = request.toString().replace("_STRICT", "");
  58             return Condition.valueOf(reqString);
  59         } catch (final IllegalArgumentException e) {
  60             return null;
  61         }
  62     }
  63 
  64     static int toUnary(final Condition c) {
  65         switch (c) {
  66         case EQ:
  67             return IFEQ;
  68         case NE:
  69             return IFNE;
  70         case LE:
  71             return IFLE;
  72         case LT:
  73             return IFLT;
  74         case GE:
  75             return IFGE;
  76         case GT:
  77             return IFGT;
  78         default:
  79             assert false;
  80             return -1;
  81         }
  82     }
  83 
  84     static int toBinary(final Condition c) {
  85         return toBinary(c, false);
  86     }
  87 
  88     static int toBinary(final Condition c, final boolean isObject) {
  89         switch (c) {
  90         case EQ:
  91             return isObject ? IF_ACMPEQ : IF_ICMPEQ;
  92         case NE:
  93             return isObject ? IF_ACMPNE : IF_ICMPNE;
  94         case LE:
  95             return IF_ICMPLE;
  96         case LT:
  97             return IF_ICMPLT;
  98         case GE:
  99             return IF_ICMPGE;
 100         case GT:
 101             return IF_ICMPGT;
 102         default:
 103             assert false;
 104             return -1;
 105         }


  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.codegen;
  27 
  28 import static jdk.internal.org.objectweb.asm.Opcodes.IFEQ;
  29 import static jdk.internal.org.objectweb.asm.Opcodes.IFGE;
  30 import static jdk.internal.org.objectweb.asm.Opcodes.IFGT;
  31 import static jdk.internal.org.objectweb.asm.Opcodes.IFLE;
  32 import static jdk.internal.org.objectweb.asm.Opcodes.IFLT;
  33 import static jdk.internal.org.objectweb.asm.Opcodes.IFNE;
  34 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ACMPEQ;
  35 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ACMPNE;
  36 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPEQ;
  37 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPGE;
  38 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPGT;
  39 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPLE;
  40 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPLT;
  41 import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPNE;

  42 
  43 /**
  44  * Condition enum used for all kinds of jumps, regardless of type
  45  */
  46 enum Condition {
  47     EQ,
  48     NE,
  49     LE,
  50     LT,
  51     GE,
  52     GT;
  53 









  54     static int toUnary(final Condition c) {
  55         switch (c) {
  56         case EQ:
  57             return IFEQ;
  58         case NE:
  59             return IFNE;
  60         case LE:
  61             return IFLE;
  62         case LT:
  63             return IFLT;
  64         case GE:
  65             return IFGE;
  66         case GT:
  67             return IFGT;
  68         default:
  69             assert false;
  70             return -1;
  71         }




  72     }
  73 
  74     static int toBinary(final Condition c, final boolean isObject) {
  75         switch (c) {
  76         case EQ:
  77             return isObject ? IF_ACMPEQ : IF_ICMPEQ;
  78         case NE:
  79             return isObject ? IF_ACMPNE : IF_ICMPNE;
  80         case LE:
  81             return IF_ICMPLE;
  82         case LT:
  83             return IF_ICMPLT;
  84         case GE:
  85             return IF_ICMPGE;
  86         case GT:
  87             return IF_ICMPGT;
  88         default:
  89             assert false;
  90             return -1;
  91         }