00001 package de.fub.bytecode.generic;
00002
00003 import java.io.*;
00004 import de.fub.bytecode.util.ByteSequence;
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 public class RET extends Instruction {
00015 private boolean wide;
00016 private int index;
00017
00018
00019
00020
00021
00022 RET() {}
00023 public RET(int index) {
00024 super(RET, (short)2);
00025 setIndex(index);
00026 }
00027
00028
00029
00030
00031 public void dump(DataOutputStream out) throws IOException {
00032 if(wide)
00033 out.writeByte(WIDE);
00034
00035 out.writeByte(tag);
00036
00037 if(wide)
00038 out.writeShort(index);
00039 else
00040 out.writeByte(index);
00041 }
00042
00043
00044
00045 public final int getIndex() { return index; }
00046
00047
00048
00049 protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
00050 {
00051 this.wide = wide;
00052
00053 if(wide) {
00054 index = bytes.readUnsignedShort();
00055 length = 4;
00056 }
00057 else {
00058 index = bytes.readUnsignedByte();
00059 length = 2;
00060 }
00061 }
00062
00063
00064
00065 public final void setIndex(int n) {
00066 if(n < 0)
00067 throw new ClassGenException("Negative index value: " + n);
00068
00069 index = n;
00070 setWide();
00071 }
00072 private final void setWide() {
00073 if(wide = index > MAX_BYTE)
00074 length = 4;
00075 else
00076 length = 2;
00077 }
00078
00079
00080
00081 public String toString(boolean verbose) {
00082 return super.toString(verbose) + " " + index;
00083 }
00084 }