KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > bytecode > IncrementInstruction


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.bytecode;
9
10 import org.gjt.jclasslib.io.ByteCodeInput;
11 import org.gjt.jclasslib.io.ByteCodeOutput;
12
13 import java.io.IOException JavaDoc;
14
15 /**
16     Describes the <tt>iinc</tt> instruction.
17  
18     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
19     @version $Revision: 1.5 $ $Date: 2003/08/18 07:58:35 $
20 */

21 public class IncrementInstruction extends ImmediateByteInstruction {
22
23     private int incrementConst;
24     
25     /**
26         Constructor.
27         @param opcode the opcode
28         @param wide whether the instruction is a wide instruction.
29      */

30     public IncrementInstruction(int opcode, boolean wide) {
31         super(opcode, wide);
32     }
33
34     /**
35         Constructor.
36         @param opcode the opcode
37         @param wide whether the instruction is a wide instruction.
38         @param immediateByte the immediate byte value.
39         @param incrementConst the increment.
40      */

41     public IncrementInstruction(int opcode, boolean wide, int immediateByte, int incrementConst) {
42         super(opcode, wide, immediateByte);
43         this.incrementConst = incrementConst;
44     }
45     
46     
47     public int getSize() {
48         return super.getSize() + (wide ? 2 : 1);
49     }
50
51     /**
52         Get the increment of this instruction.
53         @return the increment
54      */

55     public int getIncrementConst() {
56         return incrementConst;
57     }
58
59     /**
60         Set the increment of this instruction.
61         @param incrementConst the increment
62      */

63     public void setIncrementConst(int incrementConst) {
64         this.incrementConst = incrementConst;
65     }
66     
67     public void read(ByteCodeInput in) throws IOException JavaDoc {
68         super.read(in);
69
70         if (wide) {
71             incrementConst = in.readUnsignedShort();
72         } else {
73             incrementConst = in.readUnsignedByte();
74         }
75     }
76
77     public void write(ByteCodeOutput out) throws IOException JavaDoc {
78         super.write(out);
79
80         if (wide) {
81             out.writeShort(incrementConst);
82         } else {
83             out.writeByte(incrementConst);
84         }
85     }
86     
87 }
88
Popular Tags