Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

TABLESWITCH.java

00001 package de.fub.bytecode.generic;
00002 
00003 import java.io.*;
00004 import de.fub.bytecode.util.ByteSequence;
00005 
00006 /** 
00007  * TABLESWITCH - Switch within given range of values, i.e. low..high
00008  *
00009  * @version $Id: TABLESWITCH.java,v 1.1.1.1 2002/01/24 03:44:06 pserver Exp $
00010  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00011  * @see SWITCH
00012  */
00013 public class TABLESWITCH extends Select {
00014   /**
00015    * Empty constructor needed for the Class.newInstance() statement in
00016    * Instruction.readInstruction(). Not to be used otherwise.
00017    */
00018   TABLESWITCH() {}  
00019   /**
00020    * @param match sorted array of match values, match[0] must be low value, 
00021    * match[match_length - 1] high value
00022    * @param targets where to branch for matched values
00023    * @param target default branch
00024    */
00025   public TABLESWITCH(int[] match, InstructionHandle[] targets,
00026              InstructionHandle target) {
00027     super(TABLESWITCH, match, targets, target);
00028     
00029     length = (short)(13 + match_length * 4); /* Alignment remainder assumed
00030                           * 0 here, until dump time */
00031     fixed_length = length;
00032   }  
00033   /**
00034    * Dump instruction as byte code to stream out.
00035    * @param out Output stream
00036    */
00037   public void dump(DataOutputStream out) throws IOException {
00038     super.dump(out);
00039 
00040     out.writeInt(match[0]);                 // low
00041     out.writeInt(match[match_length - 1]);  // high
00042 
00043     for(int i=0; i < match_length; i++)     // jump offsets
00044       out.writeInt(indices[i] = getTargetOffset(targets[i]));
00045   }  
00046   /**
00047    * Read needed data (e.g. index) from file.
00048    */
00049   protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
00050   {
00051     super.initFromFile(bytes, wide);
00052 
00053     int low    = bytes.readInt();
00054     int high   = bytes.readInt();
00055 
00056     match_length = high - low + 1;
00057     fixed_length = (short)(13 + match_length * 4);
00058     length       = (short)(fixed_length + padding);
00059 
00060     match   = new int[match_length];
00061     indices = new int[match_length];
00062     targets = new InstructionHandle[match_length];
00063 
00064     for(int i=low; i <= high; i++)
00065       match[i - low] = i;
00066 
00067     for(int i=0; i < match_length; i++) {
00068       indices[i] = bytes.readInt();
00069     }
00070   }  
00071 }

Generated at Thu Feb 7 06:56:08 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001