KickJava   Java API By Example, From Geeks To Geeks.

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


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 branches to a different offset.
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 BranchInstruction extends AbstractInstruction {
22
23     private int branchOffset;
24
25     /**
26         Constructor.
27         @param opcode the opcode.
28      */

29     public BranchInstruction(int opcode) {
30         super(opcode);
31     }
32
33     /**
34         Constructor.
35         @param opcode the opcode.
36         @param branchOffset the branch offset.
37      */

38     public BranchInstruction(int opcode, int branchOffset) {
39         super(opcode);
40         this.branchOffset = branchOffset;
41     }
42     
43     public int getSize() {
44         return super.getSize() + 2;
45     }
46
47     /**
48         Get the relative offset of the branch of this instruction.
49         @return the offset
50      */

51     public int getBranchOffset() {
52         return branchOffset;
53     }
54
55     /**
56         Set the relative offset of the branch of this instruction.
57         @param branchOffset the offset
58      */

59     public void setBranchOffset(int branchOffset) {
60         this.branchOffset = branchOffset;
61     }
62     
63     public void read(ByteCodeInput in) throws IOException JavaDoc {
64         super.read(in);
65
66         branchOffset = in.readShort();
67     }
68
69     public void write(ByteCodeOutput out) throws IOException JavaDoc {
70         super.write(out);
71
72         out.writeShort(branchOffset);
73     }
74     
75 }
76
Popular Tags