KickJava   Java API By Example, From Geeks To Geeks.

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


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 an instruction that is followed by an immediate unsigned byte.
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 ImmediateByteInstruction extends AbstractInstruction {
22
23     /** Indicates whether the instuction is subject to a wide instruction or not. */
24     protected boolean wide;
25     
26     private int immediateByte;
27
28     /**
29         Constructor.
30         @param opcode the opcode
31         @param wide whether the instruction is a wide instruction.
32      */

33     public ImmediateByteInstruction(int opcode, boolean wide) {
34         super(opcode);
35         this.wide = wide;
36     }
37
38     /**
39         Constructor.
40         @param opcode the opcode
41         @param wide whether the instruction is a wide instruction.
42         @param immediateByte the immediate byte value.
43      */

44     public ImmediateByteInstruction(int opcode, boolean wide, int immediateByte) {
45         this(opcode, wide);
46         this.immediateByte = immediateByte;
47     }
48     
49     public int getSize() {
50         return super.getSize() + (wide ? 2 : 1);
51     }
52
53     /**
54         Get the immediate unsigned byte of this instruction.
55         @return the byte
56      */

57     public int getImmediateByte() {
58         return immediateByte;
59     }
60
61     /**
62         Set the immediate unsigned byte of this instruction.
63         @param immediateByte the byte
64      */

65      public void setImmediateByte(int immediateByte) {
66         this.immediateByte = immediateByte;
67     }
68     
69     /**
70         Check whether the instuction is subject to a wide instruction or not.
71         @return wide or not
72      */

73     public boolean isWide() {
74         return wide;
75     }
76     
77     /**
78         Set whether the instuction is subject to a wide instruction or not.
79         @param wide wide or not
80      */

81     public void setWide(boolean wide) {
82         this.wide = wide;
83     }
84     
85     public void read(ByteCodeInput in) throws IOException JavaDoc {
86         super.read(in);
87
88         if (wide) {
89             immediateByte = in.readUnsignedShort();
90         } else {
91             immediateByte = in.readUnsignedByte();
92         }
93     }
94
95     public void write(ByteCodeOutput out) throws IOException JavaDoc {
96         super.write(out);
97
98         if (wide) {
99             out.writeShort(immediateByte);
100         } else {
101             out.writeByte(immediateByte);
102         }
103     }
104     
105 }
106
Popular Tags