00001 package de.fub.bytecode.generic;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 public final class BranchHandle extends InstructionHandle {
00016 private BranchInstruction bi;
00017
00018
00019
00020 private static BranchHandle bh_list = null;
00021
00022 private BranchHandle(BranchInstruction i) {
00023 super(i);
00024 bi = i;
00025 }
00026
00027
00028 protected void addHandle() {
00029 next = bh_list;
00030 bh_list = this;
00031 }
00032 static final BranchHandle getBranchHandle(BranchInstruction i) {
00033 if(bh_list == null)
00034 return new BranchHandle(i);
00035 else {
00036 BranchHandle bh = bh_list;
00037 bh_list = (BranchHandle)bh.next;
00038
00039 bh.setInstruction(i);
00040
00041 return bh;
00042 }
00043 }
00044
00045
00046
00047
00048 public int getPosition() { return bi.position; }
00049
00050
00051
00052 public InstructionHandle getTarget() {
00053 return bi.getTarget();
00054 }
00055
00056
00057
00058 public void setInstruction(Instruction i) {
00059 super.setInstruction(i);
00060
00061 if(!(i instanceof BranchInstruction))
00062 throw new ClassGenException("Assigning " + i +
00063 " to branch handle which is not a branch instruction");
00064
00065 bi = (BranchInstruction)i;
00066 }
00067 void setPosition(int pos) {
00068 i_position = bi.position = pos;
00069 }
00070
00071
00072
00073 public void setTarget(InstructionHandle ih) {
00074 bi.setTarget(ih);
00075 }
00076 protected int updatePosition(int offset, int max_offset) {
00077 int x = bi.updatePosition(offset, max_offset);
00078 i_position = bi.position;
00079 return x;
00080 }
00081
00082
00083
00084 public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
00085 bi.updateTarget(old_ih, new_ih);
00086 }
00087 }