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

LOOKUPSWITCH.java

00001 package de.fub.bytecode.generic;
00002 
00003 import java.io.*;
00004 import de.fub.bytecode.util.ByteSequence;
00005 
00006 /** 
00007  * LOOKUPSWITCH - Switch with unordered set of values
00008  *
00009  * @version $Id: LOOKUPSWITCH.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 LOOKUPSWITCH extends Select {
00014   /**
00015    * Empty constructor needed for the Class.newInstance() statement in
00016    * Instruction.readInstruction(). Not to be used otherwise.
00017    */
00018   LOOKUPSWITCH() {}  
00019   public LOOKUPSWITCH(int[] match, InstructionHandle[] targets,
00020               InstructionHandle target) {
00021     super(LOOKUPSWITCH, match, targets, target);
00022     
00023     length = (short)(9 + match_length * 8); /* alignment remainder assumed
00024                          * 0 here, until dump time. */
00025     fixed_length = length;
00026   }  
00027   /**
00028    * Dump instruction as byte code to stream out.
00029    * @param out Output stream
00030    */
00031   public void dump(DataOutputStream out) throws IOException {
00032     super.dump(out);
00033     out.writeInt(match_length);       // npairs
00034 
00035     for(int i=0; i < match_length; i++) {
00036       out.writeInt(match[i]);         // match-offset pairs
00037       out.writeInt(indices[i] = getTargetOffset(targets[i]));
00038     }
00039   }  
00040   /**
00041    * Read needed data (e.g. index) from file.
00042    */
00043   protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
00044   {
00045     super.initFromFile(bytes, wide); // reads padding
00046 
00047     match_length = bytes.readInt();
00048     fixed_length = (short)(9 + match_length * 8);
00049     length       = (short)(fixed_length + padding);
00050       
00051     match   = new int[match_length];
00052     indices = new int[match_length];
00053     targets = new InstructionHandle[match_length];
00054 
00055     for(int i=0; i < match_length; i++) {
00056       match[i]   = bytes.readInt();
00057       indices[i] = bytes.readInt();
00058     }
00059   }  
00060 }

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