1 /*
   2  * Copyright (c) 2017, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package jdk.experimental.bytecode;
  25 
  26 import jdk.experimental.bytecode.MacroCodeBuilder.CondKind;
  27 
  28 public enum Opcode {
  29 
  30     NOP(0),
  31     ACONST_NULL(1),
  32     ICONST_M1(2),
  33     ICONST_0(3),
  34     ICONST_1(4),
  35     ICONST_2(5),
  36     ICONST_3(6),
  37     ICONST_4(7),
  38     ICONST_5(8),
  39     LCONST_0(9),
  40     LCONST_1(10),
  41     FCONST_0(11),
  42     FCONST_1(12),
  43     FCONST_2(13),
  44     DCONST_0(14),
  45     DCONST_1(15),
  46     BIPUSH(16),
  47     SIPUSH(17),
  48     LDC(18),
  49     LDC_W(19),
  50     LDC2_W(20),
  51     ILOAD(21),
  52     LLOAD(22),
  53     FLOAD(23),
  54     DLOAD(24),
  55     ALOAD(25),
  56     ILOAD_0(26),
  57     ILOAD_1(27),
  58     ILOAD_2(28),
  59     ILOAD_3(29),
  60     LLOAD_0(30),
  61     LLOAD_1(31),
  62     LLOAD_2(32),
  63     LLOAD_3(33),
  64     FLOAD_0(34),
  65     FLOAD_1(35),
  66     FLOAD_2(36),
  67     FLOAD_3(37),
  68     DLOAD_0(38),
  69     DLOAD_1(39),
  70     DLOAD_2(40),
  71     DLOAD_3(41),
  72     ALOAD_0(42),
  73     ALOAD_1(43),
  74     ALOAD_2(44),
  75     ALOAD_3(45),
  76     IALOAD(46),
  77     LALOAD(47),
  78     FALOAD(48),
  79     DALOAD(49),
  80     AALOAD(50),
  81     BALOAD(51),
  82     CALOAD(52),
  83     SALOAD(53),
  84     ISTORE(54),
  85     LSTORE(55),
  86     FSTORE(56),
  87     DSTORE(57),
  88     ASTORE(58),
  89     ISTORE_0(59),
  90     ISTORE_1(60),
  91     ISTORE_2(61),
  92     ISTORE_3(62),
  93     LSTORE_0(63),
  94     LSTORE_1(64),
  95     LSTORE_2(65),
  96     LSTORE_3(66),
  97     FSTORE_0(67),
  98     FSTORE_1(68),
  99     FSTORE_2(69),
 100     FSTORE_3(70),
 101     DSTORE_0(71),
 102     DSTORE_1(72),
 103     DSTORE_2(73),
 104     DSTORE_3(74),
 105     ASTORE_0(75),
 106     ASTORE_1(76),
 107     ASTORE_2(77),
 108     ASTORE_3(78),
 109     IASTORE(79),
 110     LASTORE(80),
 111     FASTORE(81),
 112     DASTORE(82),
 113     AASTORE(83),
 114     BASTORE(84),
 115     CASTORE(85),
 116     SASTORE(86),
 117     POP(87),
 118     POP2(88),
 119     DUP(89),
 120     DUP_X1(90),
 121     DUP_X2(91),
 122     DUP2(92),
 123     DUP2_X1(93),
 124     DUP2_X2(94),
 125     SWAP(95),
 126     IADD(96),
 127     LADD(97),
 128     FADD(98),
 129     DADD(99),
 130     ISUB(100),
 131     LSUB(101),
 132     FSUB(102),
 133     DSUB(103),
 134     IMUL(104),
 135     LMUL(105),
 136     FMUL(106),
 137     DMUL(107),
 138     IDIV(108),
 139     LDIV(109),
 140     FDIV(110),
 141     DDIV(111),
 142     IREM(112),
 143     LREM(113),
 144     FREM(114),
 145     DREM(115),
 146     INEG(116),
 147     LNEG(117),
 148     FNEG(118),
 149     DNEG(119),
 150     ISHL(120),
 151     LSHL(121),
 152     ISHR(122),
 153     LSHR(123),
 154     IUSHR(124),
 155     LUSHR(125),
 156     IAND(126),
 157     LAND(127),
 158     IOR(128),
 159     LOR(129),
 160     IXOR(130),
 161     LXOR(131),
 162     IINC(132),
 163     I2L(133),
 164     I2F(134),
 165     I2D(135),
 166     L2I(136),
 167     L2F(137),
 168     L2D(138),
 169     F2I(139),
 170     F2L(140),
 171     F2D(141),
 172     D2I(142),
 173     D2L(143),
 174     D2F(144),
 175     I2B(145),
 176     I2C(146),
 177     I2S(147),
 178     LCMP(148),
 179     FCMPL(149),
 180     FCMPG(150),
 181     DCMPL(151),
 182     DCMPG(152),
 183     IFEQ(153),
 184     IFNE(154),
 185     IFLT(155),
 186     IFGE(156),
 187     IFGT(157),
 188     IFLE(158),
 189     IF_ICMPEQ(159),
 190     IF_ICMPNE(160),
 191     IF_ICMPLT(161),
 192     IF_ICMPGE(162),
 193     IF_ICMPGT(163),
 194     IF_ICMPLE(164),
 195     IF_ACMPEQ(165),
 196     IF_ACMPNE(166),
 197     GOTO_(167),
 198     JSR(168),
 199     RET(169),
 200     TABLESWITCH(170),
 201     LOOKUPSWITCH(171),
 202     IRETURN(172),
 203     LRETURN(173),
 204     FRETURN(174),
 205     DRETURN(175),
 206     ARETURN(176),
 207     RETURN(177),
 208     GETSTATIC(178),
 209     PUTSTATIC(179),
 210     GETFIELD(180),
 211     PUTFIELD(181),
 212     INVOKEVIRTUAL(182),
 213     INVOKESPECIAL(183),
 214     INVOKESTATIC(184),
 215     INVOKEINTERFACE(185),
 216     INVOKEDYNAMIC(186),
 217     NEW(187),
 218     NEWARRAY(188),
 219     ANEWARRAY(189),
 220     ARRAYLENGTH(190),
 221     ATHROW(191),
 222     CHECKCAST(192),
 223     INSTANCEOF(193),
 224     MONITORENTER(194),
 225     MONITOREXIT(195),
 226     WIDE(196),
 227     MULTIANEWARRAY(197),
 228     IF_NULL(198),
 229     IF_NONNULL(199),
 230     GOTO_W(200),
 231     JSR_W(201),
 232     VLOAD(203),
 233     VSTORE(204),
 234     VALOAD(205),
 235     VASTORE(206),
 236     VNEW(207),
 237     VNEWARRAY(208),
 238     MULTIVNEWARRAY(209),
 239     VRETURN(210),
 240     VGETFIELD(211),
 241     TYPED(212),
 242     VBOX(216),
 243     VUNBOX(217);
 244 
 245     int code;
 246 
 247     Opcode(int code) {
 248         this.code = code;
 249     }
 250 
 251     protected Opcode at(TypeTag type) {
 252         return at(type, 1);
 253     }
 254 
 255     protected Opcode at(CondKind cond) {
 256         return at(cond.offset, 1);
 257     }
 258 
 259     protected Opcode at(TypeTag type, int multiplier) {
 260         return at(type.offset, multiplier);
 261     }
 262 
 263     private Opcode at(int offset, int multiplier) {
 264         if (offset < 0) throw new AssertionError();
 265         return Opcode.values()[code + (multiplier * offset)];
 266     }
 267 }