001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 */ 018package org.apache.bcel.generic; 019 020import org.apache.bcel.Const; 021 022/** 023 * This interface contains shareable instruction objects. 024 * <p> 025 * In order to save memory you can use some instructions multiply, since they have an immutable state and are directly 026 * derived from Instruction. I.e. they have no instance fields that could be changed. Since some of these instructions 027 * like ICONST_0 occur very frequently this can save a lot of time and space. This feature is an adaptation of the 028 * FlyWeight design pattern, we just use an array instead of a factory. 029 * </p> 030 * <p> 031 * The Instructions can also accessed directly under their names, so it's possible to write 032 * il.append(Instruction.ICONST_0); 033 * </p> 034 * 035 * @deprecated (since 6.0) Do not use. Use InstructionConst instead. 036 */ 037@Deprecated 038public interface InstructionConstants { 039 040 class Clinit { 041 042 Clinit() { 043 INSTRUCTIONS[Const.NOP] = NOP; 044 INSTRUCTIONS[Const.ACONST_NULL] = ACONST_NULL; 045 INSTRUCTIONS[Const.ICONST_M1] = ICONST_M1; 046 INSTRUCTIONS[Const.ICONST_0] = ICONST_0; 047 INSTRUCTIONS[Const.ICONST_1] = ICONST_1; 048 INSTRUCTIONS[Const.ICONST_2] = ICONST_2; 049 INSTRUCTIONS[Const.ICONST_3] = ICONST_3; 050 INSTRUCTIONS[Const.ICONST_4] = ICONST_4; 051 INSTRUCTIONS[Const.ICONST_5] = ICONST_5; 052 INSTRUCTIONS[Const.LCONST_0] = LCONST_0; 053 INSTRUCTIONS[Const.LCONST_1] = LCONST_1; 054 INSTRUCTIONS[Const.FCONST_0] = FCONST_0; 055 INSTRUCTIONS[Const.FCONST_1] = FCONST_1; 056 INSTRUCTIONS[Const.FCONST_2] = FCONST_2; 057 INSTRUCTIONS[Const.DCONST_0] = DCONST_0; 058 INSTRUCTIONS[Const.DCONST_1] = DCONST_1; 059 INSTRUCTIONS[Const.IALOAD] = IALOAD; 060 INSTRUCTIONS[Const.LALOAD] = LALOAD; 061 INSTRUCTIONS[Const.FALOAD] = FALOAD; 062 INSTRUCTIONS[Const.DALOAD] = DALOAD; 063 INSTRUCTIONS[Const.AALOAD] = AALOAD; 064 INSTRUCTIONS[Const.BALOAD] = BALOAD; 065 INSTRUCTIONS[Const.CALOAD] = CALOAD; 066 INSTRUCTIONS[Const.SALOAD] = SALOAD; 067 INSTRUCTIONS[Const.IASTORE] = IASTORE; 068 INSTRUCTIONS[Const.LASTORE] = LASTORE; 069 INSTRUCTIONS[Const.FASTORE] = FASTORE; 070 INSTRUCTIONS[Const.DASTORE] = DASTORE; 071 INSTRUCTIONS[Const.AASTORE] = AASTORE; 072 INSTRUCTIONS[Const.BASTORE] = BASTORE; 073 INSTRUCTIONS[Const.CASTORE] = CASTORE; 074 INSTRUCTIONS[Const.SASTORE] = SASTORE; 075 INSTRUCTIONS[Const.POP] = POP; 076 INSTRUCTIONS[Const.POP2] = POP2; 077 INSTRUCTIONS[Const.DUP] = DUP; 078 INSTRUCTIONS[Const.DUP_X1] = DUP_X1; 079 INSTRUCTIONS[Const.DUP_X2] = DUP_X2; 080 INSTRUCTIONS[Const.DUP2] = DUP2; 081 INSTRUCTIONS[Const.DUP2_X1] = DUP2_X1; 082 INSTRUCTIONS[Const.DUP2_X2] = DUP2_X2; 083 INSTRUCTIONS[Const.SWAP] = SWAP; 084 INSTRUCTIONS[Const.IADD] = IADD; 085 INSTRUCTIONS[Const.LADD] = LADD; 086 INSTRUCTIONS[Const.FADD] = FADD; 087 INSTRUCTIONS[Const.DADD] = DADD; 088 INSTRUCTIONS[Const.ISUB] = ISUB; 089 INSTRUCTIONS[Const.LSUB] = LSUB; 090 INSTRUCTIONS[Const.FSUB] = FSUB; 091 INSTRUCTIONS[Const.DSUB] = DSUB; 092 INSTRUCTIONS[Const.IMUL] = IMUL; 093 INSTRUCTIONS[Const.LMUL] = LMUL; 094 INSTRUCTIONS[Const.FMUL] = FMUL; 095 INSTRUCTIONS[Const.DMUL] = DMUL; 096 INSTRUCTIONS[Const.IDIV] = IDIV; 097 INSTRUCTIONS[Const.LDIV] = LDIV; 098 INSTRUCTIONS[Const.FDIV] = FDIV; 099 INSTRUCTIONS[Const.DDIV] = DDIV; 100 INSTRUCTIONS[Const.IREM] = IREM; 101 INSTRUCTIONS[Const.LREM] = LREM; 102 INSTRUCTIONS[Const.FREM] = FREM; 103 INSTRUCTIONS[Const.DREM] = DREM; 104 INSTRUCTIONS[Const.INEG] = INEG; 105 INSTRUCTIONS[Const.LNEG] = LNEG; 106 INSTRUCTIONS[Const.FNEG] = FNEG; 107 INSTRUCTIONS[Const.DNEG] = DNEG; 108 INSTRUCTIONS[Const.ISHL] = ISHL; 109 INSTRUCTIONS[Const.LSHL] = LSHL; 110 INSTRUCTIONS[Const.ISHR] = ISHR; 111 INSTRUCTIONS[Const.LSHR] = LSHR; 112 INSTRUCTIONS[Const.IUSHR] = IUSHR; 113 INSTRUCTIONS[Const.LUSHR] = LUSHR; 114 INSTRUCTIONS[Const.IAND] = IAND; 115 INSTRUCTIONS[Const.LAND] = LAND; 116 INSTRUCTIONS[Const.IOR] = IOR; 117 INSTRUCTIONS[Const.LOR] = LOR; 118 INSTRUCTIONS[Const.IXOR] = IXOR; 119 INSTRUCTIONS[Const.LXOR] = LXOR; 120 INSTRUCTIONS[Const.I2L] = I2L; 121 INSTRUCTIONS[Const.I2F] = I2F; 122 INSTRUCTIONS[Const.I2D] = I2D; 123 INSTRUCTIONS[Const.L2I] = L2I; 124 INSTRUCTIONS[Const.L2F] = L2F; 125 INSTRUCTIONS[Const.L2D] = L2D; 126 INSTRUCTIONS[Const.F2I] = F2I; 127 INSTRUCTIONS[Const.F2L] = F2L; 128 INSTRUCTIONS[Const.F2D] = F2D; 129 INSTRUCTIONS[Const.D2I] = D2I; 130 INSTRUCTIONS[Const.D2L] = D2L; 131 INSTRUCTIONS[Const.D2F] = D2F; 132 INSTRUCTIONS[Const.I2B] = I2B; 133 INSTRUCTIONS[Const.I2C] = I2C; 134 INSTRUCTIONS[Const.I2S] = I2S; 135 INSTRUCTIONS[Const.LCMP] = LCMP; 136 INSTRUCTIONS[Const.FCMPL] = FCMPL; 137 INSTRUCTIONS[Const.FCMPG] = FCMPG; 138 INSTRUCTIONS[Const.DCMPL] = DCMPL; 139 INSTRUCTIONS[Const.DCMPG] = DCMPG; 140 INSTRUCTIONS[Const.IRETURN] = IRETURN; 141 INSTRUCTIONS[Const.LRETURN] = LRETURN; 142 INSTRUCTIONS[Const.FRETURN] = FRETURN; 143 INSTRUCTIONS[Const.DRETURN] = DRETURN; 144 INSTRUCTIONS[Const.ARETURN] = ARETURN; 145 INSTRUCTIONS[Const.RETURN] = RETURN; 146 INSTRUCTIONS[Const.ARRAYLENGTH] = ARRAYLENGTH; 147 INSTRUCTIONS[Const.ATHROW] = ATHROW; 148 INSTRUCTIONS[Const.MONITORENTER] = MONITORENTER; 149 INSTRUCTIONS[Const.MONITOREXIT] = MONITOREXIT; 150 } 151 } 152 153 /* 154 * NOTE these are not currently immutable, because Instruction has mutable protected fields opcode and length. 155 */ 156 Instruction NOP = new NOP(); 157 Instruction ACONST_NULL = new ACONST_NULL(); 158 Instruction ICONST_M1 = new ICONST(-1); 159 Instruction ICONST_0 = new ICONST(0); 160 Instruction ICONST_1 = new ICONST(1); 161 Instruction ICONST_2 = new ICONST(2); 162 Instruction ICONST_3 = new ICONST(3); 163 Instruction ICONST_4 = new ICONST(4); 164 Instruction ICONST_5 = new ICONST(5); 165 Instruction LCONST_0 = new LCONST(0); 166 Instruction LCONST_1 = new LCONST(1); 167 Instruction FCONST_0 = new FCONST(0); 168 Instruction FCONST_1 = new FCONST(1); 169 Instruction FCONST_2 = new FCONST(2); 170 Instruction DCONST_0 = new DCONST(0); 171 Instruction DCONST_1 = new DCONST(1); 172 ArrayInstruction IALOAD = new IALOAD(); 173 ArrayInstruction LALOAD = new LALOAD(); 174 ArrayInstruction FALOAD = new FALOAD(); 175 ArrayInstruction DALOAD = new DALOAD(); 176 ArrayInstruction AALOAD = new AALOAD(); 177 ArrayInstruction BALOAD = new BALOAD(); 178 ArrayInstruction CALOAD = new CALOAD(); 179 ArrayInstruction SALOAD = new SALOAD(); 180 ArrayInstruction IASTORE = new IASTORE(); 181 ArrayInstruction LASTORE = new LASTORE(); 182 ArrayInstruction FASTORE = new FASTORE(); 183 ArrayInstruction DASTORE = new DASTORE(); 184 ArrayInstruction AASTORE = new AASTORE(); 185 ArrayInstruction BASTORE = new BASTORE(); 186 ArrayInstruction CASTORE = new CASTORE(); 187 ArrayInstruction SASTORE = new SASTORE(); 188 StackInstruction POP = new POP(); 189 StackInstruction POP2 = new POP2(); 190 StackInstruction DUP = new DUP(); 191 StackInstruction DUP_X1 = new DUP_X1(); 192 StackInstruction DUP_X2 = new DUP_X2(); 193 StackInstruction DUP2 = new DUP2(); 194 StackInstruction DUP2_X1 = new DUP2_X1(); 195 StackInstruction DUP2_X2 = new DUP2_X2(); 196 StackInstruction SWAP = new SWAP(); 197 ArithmeticInstruction IADD = new IADD(); 198 ArithmeticInstruction LADD = new LADD(); 199 ArithmeticInstruction FADD = new FADD(); 200 ArithmeticInstruction DADD = new DADD(); 201 ArithmeticInstruction ISUB = new ISUB(); 202 ArithmeticInstruction LSUB = new LSUB(); 203 ArithmeticInstruction FSUB = new FSUB(); 204 ArithmeticInstruction DSUB = new DSUB(); 205 ArithmeticInstruction IMUL = new IMUL(); 206 ArithmeticInstruction LMUL = new LMUL(); 207 ArithmeticInstruction FMUL = new FMUL(); 208 ArithmeticInstruction DMUL = new DMUL(); 209 ArithmeticInstruction IDIV = new IDIV(); 210 ArithmeticInstruction LDIV = new LDIV(); 211 ArithmeticInstruction FDIV = new FDIV(); 212 ArithmeticInstruction DDIV = new DDIV(); 213 ArithmeticInstruction IREM = new IREM(); 214 ArithmeticInstruction LREM = new LREM(); 215 ArithmeticInstruction FREM = new FREM(); 216 ArithmeticInstruction DREM = new DREM(); 217 ArithmeticInstruction INEG = new INEG(); 218 ArithmeticInstruction LNEG = new LNEG(); 219 ArithmeticInstruction FNEG = new FNEG(); 220 ArithmeticInstruction DNEG = new DNEG(); 221 ArithmeticInstruction ISHL = new ISHL(); 222 ArithmeticInstruction LSHL = new LSHL(); 223 ArithmeticInstruction ISHR = new ISHR(); 224 ArithmeticInstruction LSHR = new LSHR(); 225 ArithmeticInstruction IUSHR = new IUSHR(); 226 ArithmeticInstruction LUSHR = new LUSHR(); 227 ArithmeticInstruction IAND = new IAND(); 228 ArithmeticInstruction LAND = new LAND(); 229 ArithmeticInstruction IOR = new IOR(); 230 ArithmeticInstruction LOR = new LOR(); 231 ArithmeticInstruction IXOR = new IXOR(); 232 ArithmeticInstruction LXOR = new LXOR(); 233 ConversionInstruction I2L = new I2L(); 234 ConversionInstruction I2F = new I2F(); 235 ConversionInstruction I2D = new I2D(); 236 ConversionInstruction L2I = new L2I(); 237 ConversionInstruction L2F = new L2F(); 238 ConversionInstruction L2D = new L2D(); 239 ConversionInstruction F2I = new F2I(); 240 ConversionInstruction F2L = new F2L(); 241 ConversionInstruction F2D = new F2D(); 242 ConversionInstruction D2I = new D2I(); 243 ConversionInstruction D2L = new D2L(); 244 ConversionInstruction D2F = new D2F(); 245 ConversionInstruction I2B = new I2B(); 246 ConversionInstruction I2C = new I2C(); 247 ConversionInstruction I2S = new I2S(); 248 Instruction LCMP = new LCMP(); 249 Instruction FCMPL = new FCMPL(); 250 Instruction FCMPG = new FCMPG(); 251 Instruction DCMPL = new DCMPL(); 252 Instruction DCMPG = new DCMPG(); 253 ReturnInstruction IRETURN = new IRETURN(); 254 ReturnInstruction LRETURN = new LRETURN(); 255 ReturnInstruction FRETURN = new FRETURN(); 256 ReturnInstruction DRETURN = new DRETURN(); 257 ReturnInstruction ARETURN = new ARETURN(); 258 ReturnInstruction RETURN = new RETURN(); 259 Instruction ARRAYLENGTH = new ARRAYLENGTH(); 260 Instruction ATHROW = new ATHROW(); 261 Instruction MONITORENTER = new MONITORENTER(); 262 Instruction MONITOREXIT = new MONITOREXIT(); 263 264 /** 265 * You can use these constants in multiple places safely, if you can guarantee that you will never alter their internal 266 * values, e.g. call setIndex(). 267 */ 268 LocalVariableInstruction THIS = new ALOAD(0); 269 LocalVariableInstruction ALOAD_0 = THIS; 270 LocalVariableInstruction ALOAD_1 = new ALOAD(1); 271 LocalVariableInstruction ALOAD_2 = new ALOAD(2); 272 LocalVariableInstruction ILOAD_0 = new ILOAD(0); 273 LocalVariableInstruction ILOAD_1 = new ILOAD(1); 274 LocalVariableInstruction ILOAD_2 = new ILOAD(2); 275 LocalVariableInstruction ASTORE_0 = new ASTORE(0); 276 LocalVariableInstruction ASTORE_1 = new ASTORE(1); 277 LocalVariableInstruction ASTORE_2 = new ASTORE(2); 278 LocalVariableInstruction ISTORE_0 = new ISTORE(0); 279 LocalVariableInstruction ISTORE_1 = new ISTORE(1); 280 LocalVariableInstruction ISTORE_2 = new ISTORE(2); 281 282 /** 283 * Gets object via its opcode, for immutable instructions like branch instructions entries are set to null. 284 */ 285 Instruction[] INSTRUCTIONS = new Instruction[256]; 286 287 /** 288 * Interfaces may have no static initializers, so we simulate this with an inner class. 289 */ 290 Clinit bla = new Clinit(); 291}