View Javadoc
1   /*
2    * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.  Oracle designates this
8    * particular file as subject to the "Classpath" exception as provided
9    * by Oracle in the LICENSE file that accompanied this code.
10   *
11   * This code is distributed in the hope that it will be useful, but WITHOUT
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   * version 2 for more details (a copy is included in the LICENSE file that
15   * accompanied this code).
16   *
17   * You should have received a copy of the GNU General Public License version
18   * 2 along with this work; if not, write to the Free Software Foundation,
19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20   *
21   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
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          }
92      }
93  }