Source code: com/chaoswg/xtc4y/classdesc/code/instructions/Instruction.java
1 //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/code/instructions/Instruction.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.code.Code;
26
27 /**
28 * An instruction is a operation executed in java and consists either of
29 * no operand or one operand. The size of the operand my vary between a byte
30 * and a short. These specific instructions are implemented in the subclasses
31 * @author Mike Toggweiler
32 **/
33 public abstract class Instruction {
34 private byte command;
35 private short index;
36
37 /**
38 * Creates a Instruction for a specific command
39 * @param the opcode of the command
40 **/
41 protected Instruction(byte command) {
42 this.command = command;
43 }
44
45 /**
46 * Write the instruction onto the DataOutputStream, using the
47 * constant pool to register variables. .
48 * @param dos the DataOutputStream to write on
49 * @param cp The constant pool to register variables
50 **/
51 public void write(DataOutputStream dos, ConstantPool cp)
52 throws IOException {
53 dos.writeByte(command);
54 }
55
56 /**
57 * Resolve indices of instructions.
58 * By default do nothing
59 * @param code the code container where to resolve the indices
60 **/
61 public void resolveIndices(Code code) {
62 }
63
64 /**
65 * @return the number of bytes used in this command
66 **/
67 public abstract int getNumberOfUsedBytes();
68
69 /**
70 * Set the index of this instruction, is set by the code container
71 * @param index
72 **/
73 public void setIndex(short index) {
74 this.index = index;
75 }
76
77 /**
78 * @return the index of this instruction
79 **/
80 public short getIndex() {
81 return index;
82 }
83
84 /**
85 * Write code in a readable way
86 **/
87 public String toString() {
88 return index + " " + ((command<0)?256+command:command);
89 }
90
91 /**
92 * @return the opcode of the instruction
93 **/
94 public byte getOpcode() {
95 return command;
96 }
97
98 /**
99 * @return the command of the instruction
100 **/
101 public byte getCommand() {
102 return command;
103 }
104 }