Condition.java revision 953:221a84ef44c0
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
26package jdk.nashorn.internal.codegen;
27
28import static jdk.internal.org.objectweb.asm.Opcodes.IFEQ;
29import static jdk.internal.org.objectweb.asm.Opcodes.IFGE;
30import static jdk.internal.org.objectweb.asm.Opcodes.IFGT;
31import static jdk.internal.org.objectweb.asm.Opcodes.IFLE;
32import static jdk.internal.org.objectweb.asm.Opcodes.IFLT;
33import static jdk.internal.org.objectweb.asm.Opcodes.IFNE;
34import static jdk.internal.org.objectweb.asm.Opcodes.IF_ACMPEQ;
35import static jdk.internal.org.objectweb.asm.Opcodes.IF_ACMPNE;
36import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPEQ;
37import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPGE;
38import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPGT;
39import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPLE;
40import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPLT;
41import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPNE;
42
43/**
44 * Condition enum used for all kinds of jumps, regardless of type
45 */
46enum 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            throw new UnsupportedOperationException("toUnary:" + c.toString());
70        }
71    }
72
73    static int toBinary(final Condition c, final boolean isObject) {
74        switch (c) {
75        case EQ:
76            return isObject ? IF_ACMPEQ : IF_ICMPEQ;
77        case NE:
78            return isObject ? IF_ACMPNE : IF_ICMPNE;
79        case LE:
80            return IF_ICMPLE;
81        case LT:
82            return IF_ICMPLT;
83        case GE:
84            return IF_ICMPGE;
85        case GT:
86            return IF_ICMPGT;
87        default:
88            throw new UnsupportedOperationException("toBinary:" + c.toString());
89        }
90    }
91}
92