Source code: com/chaoswg/xtc4y/classdesc/code/instructions/InvokeInterface.java
1 //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/code/instructions/InvokeInterface.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 import com.chaoswg.xtc4y.classdesc.InterfaceMethodrefCPEntry;
26
27 /**
28 * A invoke interface instruction is used by calling a interface method.
29 * It consists of the command, the number of arguments passed, a index
30 * to a MethodsInterfacerefCPEntry and the byte value 0. The number of
31 * used bytes is therefore 5 (4 byte operands and the command)
32 * TBD: add constructor for an instruction creation withou stream
33 * @author Mike Toggweiler
34 **/
35 public class InvokeInterface extends Instruction {
36 private InterfaceMethodrefCPEntry cpEntry;
37 private byte zero;
38 private byte args;
39
40 /**
41 * Opcode of the InvokeInterface insturction
42 **/
43 public static final byte INVOKEINTERFACE = (byte)185;
44
45 /**
46 * Creates an InvokeInterace and initializes it from a
47 * DataInputStream
48 * @param dis the DataInputStream to read from
49 * @param cp the constant pool to resolve indices
50 **/
51 protected InvokeInterface(DataInputStream dis,
52 ConstantPool cp) throws IOException {
53 super(INVOKEINTERFACE);
54
55 //read and resolve cp entry
56 short index = (short)dis.readUnsignedShort();
57 cpEntry = (InterfaceMethodrefCPEntry)cp.getCPEntryAt(index);
58
59 //read number of arguments
60 args = (byte)dis.readUnsignedByte();
61
62 //read zero value
63 zero = (byte)dis.readUnsignedByte();
64
65 if (zero != 0) {
66 throw new ClassFormatError("Last operand byte of InvokeInterface "+
67 "instruction should be '0', but is "+
68 zero);
69 }
70 }
71
72 /**
73 * Write the instruction onto the DataOutputStream, using the
74 * constant pool to register variables. .
75 * @param dos the DataOutputStream to write on
76 * @param cp The constant pool to register variables
77 **/
78 public void write(DataOutputStream dos, ConstantPool cp)
79 throws IOException {
80 super.write(dos, cp);
81
82 dos.writeShort(cp.addCPEntry(cpEntry));
83 dos.writeByte(args);
84 dos.writeByte(zero);
85 }
86
87 /**
88 * @return the number of bytes used in this command
89 **/
90 public int getNumberOfUsedBytes() {
91 return 5;
92 }
93 }