Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/chaoswg/xtc4y/classdesc/code/instructions/JumpInstruction.java


1   //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/code/instructions/JumpInstruction.java,v 1.2 2003/08/26 12:35:25 toggm Exp $
2   /******************************************************************************
3    * XTC4y - eXtreme Testing Collection 4 you                                   *
4    * -------------------------------------------------------------------------- *
5    * URL: http://www.chaoswg.com/xtc4y                                          *
6    * Author: Mike Toggweiler (2.dog@gmx.ch)                                     *
7    *                                                                            *
8    * Last Updated: $Date: 2003/08/26 12:35:25 $, by $Author: toggm $            *
9    * Version: $Revision: 1.2 $                                                  *
10   * -------------------------------------------------------------------------- *
11   * COPYRIGHT:   (c) 2003 by Mike Toggweiler                                   *
12   *                                                                            *
13   * This program is free software; you can redistribute it and/or modify       *
14   * it under the terms of the GNU General Public License as published by       *
15   * the Free Software Foundation; either version 2 of the License, or          *
16   * (at your option) any later version.                                        *
17   *****************************************************************************/
18  package com.chaoswg.xtc4y.classdesc.code.instructions;
19  
20  import java.io.DataInputStream;
21  import java.io.DataOutputStream;
22  import java.io.IOException;
23  
24  import com.chaoswg.xtc4y.classdesc.ConstantPool;
25  import com.chaoswg.xtc4y.classdesc.code.Code;
26  
27  /**
28   * a jump instruction refers to another instruction if expression evaluates
29   * to true
30   * @author Mike Toggweiler
31   **/
32  public class JumpInstruction extends WideBinaryInstruction {
33      private Instruction target;
34      private short targetIndex;
35  
36      /**
37       * Opcodes of jump instructions
38       **/
39      /**
40       * Jump if the last two value on the stack are equals
41       **/
42      public static final byte IFEQ = (byte)153; 
43      /**
44       * Jump if the last two value on the stack are not equals
45       **/
46      public static final byte IFNE = (byte)154; 
47      /**
48       * Jump if the second last value on the stack is lower than the last one
49       **/
50      public static final byte IFLT = (byte)155; 
51      /**
52       * Jump if the second last value on the stack is greater or equals the 
53       * last one
54       **/
55      public static final byte IFGE = (byte)156; 
56      /**
57       * Jump if the second last value on the stack is greater than the last one
58       **/
59      public static final byte IFGT = (byte)157; 
60      /**
61       * Jump if the second last value on the stack is lower or equals the last 
62       * one
63       **/
64      public static final byte IFLE = (byte)158; 
65      /**
66       * Jump if the last to int value on the stack are equals
67       **/
68      public static final byte IF_ICMPEQ = (byte)159; 
69      /**
70       * Jump if the last to int value on the stack are not equals
71       **/
72      public static final byte IF_ICMPNE = (byte)160; 
73      /**
74       * Jump if the second last int value on the stack is lower than the 
75       * last one
76       **/
77      public static final byte IF_ICMPLT = (byte)161; 
78      /**
79       * Jump if the second last int value on the stack is greater or equals the 
80       * last one
81       **/
82      public static final byte IF_ICMPGE = (byte)162; 
83      /**
84       * Jump if the second last int value on the stack is greater than the 
85       * last one
86       **/
87      public static final byte IF_ICMPGT = (byte)163; 
88      /**
89       * Jump if the second last int value on the stack is lower or equals the 
90       * last one
91       **/
92      public static final byte IF_ICMPLE = (byte)164; 
93      /**
94       * Jump if the last to objects on the stack are equals
95       **/
96      public static final byte IF_ACMPEQ = (byte)165; 
97      /**
98       * Jump if the last to objects on the stack are not equals
99       **/
100     public static final byte IF_ACMPNE = (byte)166; 
101     /**
102      * unconditional jump
103      **/
104     public static final byte GOTO = (byte)167; 
105     /**
106      * jump to subroutine
107      **/
108     public static final byte JSR = (byte)168; 
109     /**
110      * jump if null
111      **/
112     public static final byte IFNULL = (byte)198; 
113     /**
114      * jump if not null
115      **/
116     public static final byte IFNONNULL = (byte)199; 
117     /**
118      * a wide goto jump
119      **/
120     public static final byte GOTO_W = (byte)200; 
121     /**
122      * a wide jsr jump
123      **/
124     public static final byte JSR_W = (byte)201;     
125         
126     /**
127      * Creates an JumpInstruction and initializes it from a 
128      * DataInputStream
129      * @param the opcode of the command
130      * @param dis the DataInputStream to read from
131      * @param cp the constant pool to resolve indices
132      **/
133     protected JumpInstruction(byte command, DataInputStream dis, 
134         ConstantPool cp) throws IOException {
135   super(command, dis, cp);  
136     }
137 
138     /**
139      * Create a new jump instruction with a command and the target 
140      * instruction to jump as operand
141      * @param command
142      * @param operand
143      **/
144     public JumpInstruction(byte command, Instruction target) {
145   super(command);
146   this.target = target;
147     }
148 
149     /**
150      * Store the index for a later resolving
151      * @param operand to handle
152      * @param cp the constant pool to resolve indices
153      **/
154     protected final void handleOperand(short operand, ConstantPool cp) {
155   targetIndex = operand;
156     }
157 
158     /**
159      * Resolve indices of instructions.
160      * @param code the code container where to resolve the indices
161      **/
162     public void resolveIndices(Code code) {      
163   target = code.getInstructionAt((short)(targetIndex+getIndex()));
164     }
165 
166     /**
167      * Get index of instruction
168      * @param cp The constant pool to register variables
169      * @return the index of the stored cp entry
170      **/
171     protected final short getOperand(ConstantPool cp) {
172   return (short)(target.getIndex()-getIndex());
173     }
174 }