1. package com.sun.org.apache.bcel.internal.generic;
  2. /* ====================================================================
  3. * The Apache Software License, Version 1.1
  4. *
  5. * Copyright (c) 2001 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Apache" and "Apache Software Foundation" and
  28. * "Apache BCEL" must not be used to endorse or promote products
  29. * derived from this software without prior written permission. For
  30. * written permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * "Apache BCEL", nor may "Apache" appear in their name, without
  34. * prior written permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation. For more
  52. * information on the Apache Software Foundation, please see
  53. * <http://www.apache.org/>.
  54. */
  55. import com.sun.org.apache.bcel.internal.Constants;
  56. /**
  57. * This interface contains shareable instruction objects.
  58. *
  59. * In order to save memory you can use some instructions multiply,
  60. * since they have an immutable state and are directly derived from
  61. * Instruction. I.e. they have no instance fields that could be
  62. * changed. Since some of these instructions like ICONST_0 occur
  63. * very frequently this can save a lot of time and space. This
  64. * feature is an adaptation of the FlyWeight design pattern, we
  65. * just use an array instead of a factory.
  66. *
  67. * The Instructions can also accessed directly under their names, so
  68. * it's possible to write il.append(Instruction.ICONST_0);
  69. *
  70. * @version $Id: InstructionConstants.java,v 1.1.1.1 2001/10/29 20:00:18 jvanzyl Exp $
  71. * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
  72. */
  73. public interface InstructionConstants {
  74. /** Predefined instruction objects
  75. */
  76. public static final Instruction NOP = new NOP();
  77. public static final Instruction ACONST_NULL = new ACONST_NULL();
  78. public static final Instruction ICONST_M1 = new ICONST(-1);
  79. public static final Instruction ICONST_0 = new ICONST(0);
  80. public static final Instruction ICONST_1 = new ICONST(1);
  81. public static final Instruction ICONST_2 = new ICONST(2);
  82. public static final Instruction ICONST_3 = new ICONST(3);
  83. public static final Instruction ICONST_4 = new ICONST(4);
  84. public static final Instruction ICONST_5 = new ICONST(5);
  85. public static final Instruction LCONST_0 = new LCONST(0);
  86. public static final Instruction LCONST_1 = new LCONST(1);
  87. public static final Instruction FCONST_0 = new FCONST(0);
  88. public static final Instruction FCONST_1 = new FCONST(1);
  89. public static final Instruction FCONST_2 = new FCONST(2);
  90. public static final Instruction DCONST_0 = new DCONST(0);
  91. public static final Instruction DCONST_1 = new DCONST(1);
  92. public static final ArrayInstruction IALOAD = new IALOAD();
  93. public static final ArrayInstruction LALOAD = new LALOAD();
  94. public static final ArrayInstruction FALOAD = new FALOAD();
  95. public static final ArrayInstruction DALOAD = new DALOAD();
  96. public static final ArrayInstruction AALOAD = new AALOAD();
  97. public static final ArrayInstruction BALOAD = new BALOAD();
  98. public static final ArrayInstruction CALOAD = new CALOAD();
  99. public static final ArrayInstruction SALOAD = new SALOAD();
  100. public static final ArrayInstruction IASTORE = new IASTORE();
  101. public static final ArrayInstruction LASTORE = new LASTORE();
  102. public static final ArrayInstruction FASTORE = new FASTORE();
  103. public static final ArrayInstruction DASTORE = new DASTORE();
  104. public static final ArrayInstruction AASTORE = new AASTORE();
  105. public static final ArrayInstruction BASTORE = new BASTORE();
  106. public static final ArrayInstruction CASTORE = new CASTORE();
  107. public static final ArrayInstruction SASTORE = new SASTORE();
  108. public static final StackInstruction POP = new POP();
  109. public static final StackInstruction POP2 = new POP2();
  110. public static final StackInstruction DUP = new DUP();
  111. public static final StackInstruction DUP_X1 = new DUP_X1();
  112. public static final StackInstruction DUP_X2 = new DUP_X2();
  113. public static final StackInstruction DUP2 = new DUP2();
  114. public static final StackInstruction DUP2_X1 = new DUP2_X1();
  115. public static final StackInstruction DUP2_X2 = new DUP2_X2();
  116. public static final StackInstruction SWAP = new SWAP();
  117. public static final ArithmeticInstruction IADD = new IADD();
  118. public static final ArithmeticInstruction LADD = new LADD();
  119. public static final ArithmeticInstruction FADD = new FADD();
  120. public static final ArithmeticInstruction DADD = new DADD();
  121. public static final ArithmeticInstruction ISUB = new ISUB();
  122. public static final ArithmeticInstruction LSUB = new LSUB();
  123. public static final ArithmeticInstruction FSUB = new FSUB();
  124. public static final ArithmeticInstruction DSUB = new DSUB();
  125. public static final ArithmeticInstruction IMUL = new IMUL();
  126. public static final ArithmeticInstruction LMUL = new LMUL();
  127. public static final ArithmeticInstruction FMUL = new FMUL();
  128. public static final ArithmeticInstruction DMUL = new DMUL();
  129. public static final ArithmeticInstruction IDIV = new IDIV();
  130. public static final ArithmeticInstruction LDIV = new LDIV();
  131. public static final ArithmeticInstruction FDIV = new FDIV();
  132. public static final ArithmeticInstruction DDIV = new DDIV();
  133. public static final ArithmeticInstruction IREM = new IREM();
  134. public static final ArithmeticInstruction LREM = new LREM();
  135. public static final ArithmeticInstruction FREM = new FREM();
  136. public static final ArithmeticInstruction DREM = new DREM();
  137. public static final ArithmeticInstruction INEG = new INEG();
  138. public static final ArithmeticInstruction LNEG = new LNEG();
  139. public static final ArithmeticInstruction FNEG = new FNEG();
  140. public static final ArithmeticInstruction DNEG = new DNEG();
  141. public static final ArithmeticInstruction ISHL = new ISHL();
  142. public static final ArithmeticInstruction LSHL = new LSHL();
  143. public static final ArithmeticInstruction ISHR = new ISHR();
  144. public static final ArithmeticInstruction LSHR = new LSHR();
  145. public static final ArithmeticInstruction IUSHR = new IUSHR();
  146. public static final ArithmeticInstruction LUSHR = new LUSHR();
  147. public static final ArithmeticInstruction IAND = new IAND();
  148. public static final ArithmeticInstruction LAND = new LAND();
  149. public static final ArithmeticInstruction IOR = new IOR();
  150. public static final ArithmeticInstruction LOR = new LOR();
  151. public static final ArithmeticInstruction IXOR = new IXOR();
  152. public static final ArithmeticInstruction LXOR = new LXOR();
  153. public static final ConversionInstruction I2L = new I2L();
  154. public static final ConversionInstruction I2F = new I2F();
  155. public static final ConversionInstruction I2D = new I2D();
  156. public static final ConversionInstruction L2I = new L2I();
  157. public static final ConversionInstruction L2F = new L2F();
  158. public static final ConversionInstruction L2D = new L2D();
  159. public static final ConversionInstruction F2I = new F2I();
  160. public static final ConversionInstruction F2L = new F2L();
  161. public static final ConversionInstruction F2D = new F2D();
  162. public static final ConversionInstruction D2I = new D2I();
  163. public static final ConversionInstruction D2L = new D2L();
  164. public static final ConversionInstruction D2F = new D2F();
  165. public static final ConversionInstruction I2B = new I2B();
  166. public static final ConversionInstruction I2C = new I2C();
  167. public static final ConversionInstruction I2S = new I2S();
  168. public static final Instruction LCMP = new LCMP();
  169. public static final Instruction FCMPL = new FCMPL();
  170. public static final Instruction FCMPG = new FCMPG();
  171. public static final Instruction DCMPL = new DCMPL();
  172. public static final Instruction DCMPG = new DCMPG();
  173. public static final ReturnInstruction IRETURN = new IRETURN();
  174. public static final ReturnInstruction LRETURN = new LRETURN();
  175. public static final ReturnInstruction FRETURN = new FRETURN();
  176. public static final ReturnInstruction DRETURN = new DRETURN();
  177. public static final ReturnInstruction ARETURN = new ARETURN();
  178. public static final ReturnInstruction RETURN = new RETURN();
  179. public static final Instruction ARRAYLENGTH = new ARRAYLENGTH();
  180. public static final Instruction ATHROW = new ATHROW();
  181. public static final Instruction MONITORENTER = new MONITORENTER();
  182. public static final Instruction MONITOREXIT = new MONITOREXIT();
  183. /** You can use these constants in multiple places safely, if you can guarantee
  184. * that you will never alter their internal values, e.g. call setIndex().
  185. */
  186. public static final LocalVariableInstruction THIS = new ALOAD(0);
  187. public static final LocalVariableInstruction ALOAD_0 = THIS;
  188. public static final LocalVariableInstruction ALOAD_1 = new ALOAD(1);
  189. public static final LocalVariableInstruction ALOAD_2 = new ALOAD(2);
  190. public static final LocalVariableInstruction ILOAD_0 = new ILOAD(0);
  191. public static final LocalVariableInstruction ILOAD_1 = new ILOAD(1);
  192. public static final LocalVariableInstruction ILOAD_2 = new ILOAD(2);
  193. public static final LocalVariableInstruction ASTORE_0 = new ASTORE(0);
  194. public static final LocalVariableInstruction ASTORE_1 = new ASTORE(1);
  195. public static final LocalVariableInstruction ASTORE_2 = new ASTORE(2);
  196. public static final LocalVariableInstruction ISTORE_0 = new ISTORE(0);
  197. public static final LocalVariableInstruction ISTORE_1 = new ISTORE(1);
  198. public static final LocalVariableInstruction ISTORE_2 = new ISTORE(2);
  199. /** Get object via its opcode, for immutable instructions like
  200. * branch instructions entries are set to null.
  201. */
  202. public static final Instruction[] INSTRUCTIONS = new Instruction[256];
  203. /** Interfaces may have no static initializers, so we simulate this
  204. * with an inner class.
  205. */
  206. static final Clinit bla = new Clinit();
  207. static class Clinit {
  208. Clinit() {
  209. INSTRUCTIONS[Constants.NOP] = NOP;
  210. INSTRUCTIONS[Constants.ACONST_NULL] = ACONST_NULL;
  211. INSTRUCTIONS[Constants.ICONST_M1] = ICONST_M1;
  212. INSTRUCTIONS[Constants.ICONST_0] = ICONST_0;
  213. INSTRUCTIONS[Constants.ICONST_1] = ICONST_1;
  214. INSTRUCTIONS[Constants.ICONST_2] = ICONST_2;
  215. INSTRUCTIONS[Constants.ICONST_3] = ICONST_3;
  216. INSTRUCTIONS[Constants.ICONST_4] = ICONST_4;
  217. INSTRUCTIONS[Constants.ICONST_5] = ICONST_5;
  218. INSTRUCTIONS[Constants.LCONST_0] = LCONST_0;
  219. INSTRUCTIONS[Constants.LCONST_1] = LCONST_1;
  220. INSTRUCTIONS[Constants.FCONST_0] = FCONST_0;
  221. INSTRUCTIONS[Constants.FCONST_1] = FCONST_1;
  222. INSTRUCTIONS[Constants.FCONST_2] = FCONST_2;
  223. INSTRUCTIONS[Constants.DCONST_0] = DCONST_0;
  224. INSTRUCTIONS[Constants.DCONST_1] = DCONST_1;
  225. INSTRUCTIONS[Constants.IALOAD] = IALOAD;
  226. INSTRUCTIONS[Constants.LALOAD] = LALOAD;
  227. INSTRUCTIONS[Constants.FALOAD] = FALOAD;
  228. INSTRUCTIONS[Constants.DALOAD] = DALOAD;
  229. INSTRUCTIONS[Constants.AALOAD] = AALOAD;
  230. INSTRUCTIONS[Constants.BALOAD] = BALOAD;
  231. INSTRUCTIONS[Constants.CALOAD] = CALOAD;
  232. INSTRUCTIONS[Constants.SALOAD] = SALOAD;
  233. INSTRUCTIONS[Constants.IASTORE] = IASTORE;
  234. INSTRUCTIONS[Constants.LASTORE] = LASTORE;
  235. INSTRUCTIONS[Constants.FASTORE] = FASTORE;
  236. INSTRUCTIONS[Constants.DASTORE] = DASTORE;
  237. INSTRUCTIONS[Constants.AASTORE] = AASTORE;
  238. INSTRUCTIONS[Constants.BASTORE] = BASTORE;
  239. INSTRUCTIONS[Constants.CASTORE] = CASTORE;
  240. INSTRUCTIONS[Constants.SASTORE] = SASTORE;
  241. INSTRUCTIONS[Constants.POP] = POP;
  242. INSTRUCTIONS[Constants.POP2] = POP2;
  243. INSTRUCTIONS[Constants.DUP] = DUP;
  244. INSTRUCTIONS[Constants.DUP_X1] = DUP_X1;
  245. INSTRUCTIONS[Constants.DUP_X2] = DUP_X2;
  246. INSTRUCTIONS[Constants.DUP2] = DUP2;
  247. INSTRUCTIONS[Constants.DUP2_X1] = DUP2_X1;
  248. INSTRUCTIONS[Constants.DUP2_X2] = DUP2_X2;
  249. INSTRUCTIONS[Constants.SWAP] = SWAP;
  250. INSTRUCTIONS[Constants.IADD] = IADD;
  251. INSTRUCTIONS[Constants.LADD] = LADD;
  252. INSTRUCTIONS[Constants.FADD] = FADD;
  253. INSTRUCTIONS[Constants.DADD] = DADD;
  254. INSTRUCTIONS[Constants.ISUB] = ISUB;
  255. INSTRUCTIONS[Constants.LSUB] = LSUB;
  256. INSTRUCTIONS[Constants.FSUB] = FSUB;
  257. INSTRUCTIONS[Constants.DSUB] = DSUB;
  258. INSTRUCTIONS[Constants.IMUL] = IMUL;
  259. INSTRUCTIONS[Constants.LMUL] = LMUL;
  260. INSTRUCTIONS[Constants.FMUL] = FMUL;
  261. INSTRUCTIONS[Constants.DMUL] = DMUL;
  262. INSTRUCTIONS[Constants.IDIV] = IDIV;
  263. INSTRUCTIONS[Constants.LDIV] = LDIV;
  264. INSTRUCTIONS[Constants.FDIV] = FDIV;
  265. INSTRUCTIONS[Constants.DDIV] = DDIV;
  266. INSTRUCTIONS[Constants.IREM] = IREM;
  267. INSTRUCTIONS[Constants.LREM] = LREM;
  268. INSTRUCTIONS[Constants.FREM] = FREM;
  269. INSTRUCTIONS[Constants.DREM] = DREM;
  270. INSTRUCTIONS[Constants.INEG] = INEG;
  271. INSTRUCTIONS[Constants.LNEG] = LNEG;
  272. INSTRUCTIONS[Constants.FNEG] = FNEG;
  273. INSTRUCTIONS[Constants.DNEG] = DNEG;
  274. INSTRUCTIONS[Constants.ISHL] = ISHL;
  275. INSTRUCTIONS[Constants.LSHL] = LSHL;
  276. INSTRUCTIONS[Constants.ISHR] = ISHR;
  277. INSTRUCTIONS[Constants.LSHR] = LSHR;
  278. INSTRUCTIONS[Constants.IUSHR] = IUSHR;
  279. INSTRUCTIONS[Constants.LUSHR] = LUSHR;
  280. INSTRUCTIONS[Constants.IAND] = IAND;
  281. INSTRUCTIONS[Constants.LAND] = LAND;
  282. INSTRUCTIONS[Constants.IOR] = IOR;
  283. INSTRUCTIONS[Constants.LOR] = LOR;
  284. INSTRUCTIONS[Constants.IXOR] = IXOR;
  285. INSTRUCTIONS[Constants.LXOR] = LXOR;
  286. INSTRUCTIONS[Constants.I2L] = I2L;
  287. INSTRUCTIONS[Constants.I2F] = I2F;
  288. INSTRUCTIONS[Constants.I2D] = I2D;
  289. INSTRUCTIONS[Constants.L2I] = L2I;
  290. INSTRUCTIONS[Constants.L2F] = L2F;
  291. INSTRUCTIONS[Constants.L2D] = L2D;
  292. INSTRUCTIONS[Constants.F2I] = F2I;
  293. INSTRUCTIONS[Constants.F2L] = F2L;
  294. INSTRUCTIONS[Constants.F2D] = F2D;
  295. INSTRUCTIONS[Constants.D2I] = D2I;
  296. INSTRUCTIONS[Constants.D2L] = D2L;
  297. INSTRUCTIONS[Constants.D2F] = D2F;
  298. INSTRUCTIONS[Constants.I2B] = I2B;
  299. INSTRUCTIONS[Constants.I2C] = I2C;
  300. INSTRUCTIONS[Constants.I2S] = I2S;
  301. INSTRUCTIONS[Constants.LCMP] = LCMP;
  302. INSTRUCTIONS[Constants.FCMPL] = FCMPL;
  303. INSTRUCTIONS[Constants.FCMPG] = FCMPG;
  304. INSTRUCTIONS[Constants.DCMPL] = DCMPL;
  305. INSTRUCTIONS[Constants.DCMPG] = DCMPG;
  306. INSTRUCTIONS[Constants.IRETURN] = IRETURN;
  307. INSTRUCTIONS[Constants.LRETURN] = LRETURN;
  308. INSTRUCTIONS[Constants.FRETURN] = FRETURN;
  309. INSTRUCTIONS[Constants.DRETURN] = DRETURN;
  310. INSTRUCTIONS[Constants.ARETURN] = ARETURN;
  311. INSTRUCTIONS[Constants.RETURN] = RETURN;
  312. INSTRUCTIONS[Constants.ARRAYLENGTH] = ARRAYLENGTH;
  313. INSTRUCTIONS[Constants.ATHROW] = ATHROW;
  314. INSTRUCTIONS[Constants.MONITORENTER] = MONITORENTER;
  315. INSTRUCTIONS[Constants.MONITOREXIT] = MONITOREXIT;
  316. }
  317. }
  318. }