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 public class TABLESWITCH extends Select {
00014
00015
00016
00017
00018 TABLESWITCH() {}
00019
00020
00021
00022
00023
00024
00025 public TABLESWITCH(int[] match, InstructionHandle[] targets,
00026 InstructionHandle target) {
00027 super(de.fub.bytecode.Constants.TABLESWITCH, match, targets, target);
00028
00029 length = (short)(13 + match_length * 4);
00030
00031 fixed_length = length;
00032 }
00033
00034
00035
00036
00037
00038
00039
00040
00041 public void accept(Visitor v) {
00042 v.visitVariableLengthInstruction(this);
00043 v.visitStackProducer(this);
00044 v.visitInstructionTargeter(this);
00045 v.visitBranchInstruction(this);
00046 v.visitSelect(this);
00047 v.visitTABLESWITCH(this);
00048 }
00049
00050
00051
00052
00053 public void dump(DataOutputStream out) throws IOException {
00054 super.dump(out);
00055
00056 out.writeInt(match[0]);
00057 out.writeInt(match[match_length - 1]);
00058
00059 for(int i=0; i < match_length; i++)
00060 out.writeInt(indices[i] = getTargetOffset(targets[i]));
00061 }
00062
00063
00064
00065 protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
00066 {
00067 super.initFromFile(bytes, wide);
00068
00069 int low = bytes.readInt();
00070 int high = bytes.readInt();
00071
00072 match_length = high - low + 1;
00073 fixed_length = (short)(13 + match_length * 4);
00074 length = (short)(fixed_length + padding);
00075
00076 match = new int[match_length];
00077 indices = new int[match_length];
00078 targets = new InstructionHandle[match_length];
00079
00080 for(int i=low; i <= high; i++)
00081 match[i - low] = i;
00082
00083 for(int i=0; i < match_length; i++) {
00084 indices[i] = bytes.readInt();
00085 }
00086 }
00087 }