Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/chaoswg/xtc4y/classdesc/code/instructions/TrinaryInstruction.java


1   //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/code/instructions/TrinaryInstruction.java,v 1.1.1.1 2003/08/07 13:40:31 toggm Exp $
2   /******************************************************************************
3    * XTC4y - eXtreme Testing Collection 4 you                                   *
4    * -------------------------------------------------------------------------- *
5    * URL: http://www.chaoswg.com/xtc4y                                          *
6    * Author: Mike Toggweiler (2.dog@gmx.ch)                                     *
7    *                                                                            *
8    * Last Updated: $Date: 2003/08/07 13:40:31 $, by $Author: toggm $            *
9    * Version: $Revision: 1.1.1.1 $                                                  *
10   * -------------------------------------------------------------------------- *
11   * COPYRIGHT:   (c) 2003 by Mike Toggweiler                                   *
12   *                                                                            *
13   * This program is free software; you can redistribute it and/or modify       *
14   * it under the terms of the GNU General Public License as published by       *
15   * the Free Software Foundation; either version 2 of the License, or          *
16   * (at your option) any later version.                                        *
17   *****************************************************************************/
18  package com.chaoswg.xtc4y.classdesc.code.instructions;
19  
20  import java.io.DataInputStream;
21  import java.io.DataOutputStream;
22  import java.io.IOException;
23  
24  import com.chaoswg.xtc4y.classdesc.ConstantPool;
25  
26  /**
27   * A binary instruction consists of a command and two one byte operands, 
28   * therefore its size is 3 bytes
29   * @author Mike Toggweiler
30   **/
31  public class TrinaryInstruction extends Instruction {
32      private byte operand1;
33      private byte operand2;
34  
35      /**
36       * Opcodes of byte trinary instructions
37       **/    
38      /**
39       * increment local indexed variable by the second operand
40       **/
41      public static final byte IINC = (byte)132;
42  
43      /**
44       * Creates an TrinaryInstruction and initializes it from a 
45       * DataInputStream. the operand is read from the stream and 
46       * provided to extending classes for a further handling of it
47       * @param the opcode of the command
48       * @param dis the DataInputStream to read from
49       * @param cp the constant pool to resolve indices
50       **/
51      public TrinaryInstruction(byte command, DataInputStream dis, 
52          ConstantPool cp) throws IOException {
53    super(command);
54    handleOperands((byte)dis.readUnsignedByte(), 
55             (byte)dis.readUnsignedByte(), cp);
56      }
57  
58      /**
59       * Create a new binary instruction with a command and the byte value 
60       * as operand
61       * @param command
62       * @param operand
63       **/
64      public TrinaryInstruction(byte command, byte operand1, byte operand2) {
65    super(command);
66    this.operand1 = operand1;
67    this.operand2 = operand2;
68      }
69  
70      /**
71       * Handle operands. By default, the operands values are stored. Another
72       * behaviour may be implemented in an extending class
73       * @param operand1 to handle
74       * @param operand2 to handle
75       * @param cp the constant pool to resolve indices
76       **/
77      protected void handleOperands(byte operand1, byte operand2, 
78            ConstantPool cp) {
79    this.operand1 = operand1;
80    this.operand2 = operand2;
81      }
82  
83      /**
84       * Write the instruction onto the DataOutputStream, using the 
85       * constant pool to register variables. .
86       * @param dos the DataOutputStream to write on
87       * @param cp The constant pool to register variables
88       **/
89      public final void write(DataOutputStream dos, ConstantPool cp) 
90    throws IOException {
91    super.write(dos, cp);
92    dos.writeByte(getOperand1(cp));
93    dos.writeByte(getOperand2(cp));
94      }
95  
96      /**
97       * @param cp The constant pool to register variables
98       * @return the byte value of the operand, by default, the previously 
99       * stored operands value will be returned. Another behiour may be 
100      * implemented in an extending class.
101      **/
102     protected byte getOperand1(ConstantPool cp) {
103   return operand1;
104     }
105 
106     /**
107      * @param cp The constant pool to register variables
108      * @return the byte value of the operand, by default, the previously 
109      * stored operands value will be returned. Another behiour may be 
110      * implemented in an extending class.
111      **/
112     protected byte getOperand2(ConstantPool cp) {
113   return operand2;
114     }
115 
116     /**
117      * @return the number of bytes used in this command
118      **/
119     public final int getNumberOfUsedBytes() {
120   return 3;
121     }
122 }