1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.interpreter;
11
12 import nl.tudelft.simulation.dsol.interpreter.classfile.MethodDescriptor;
13
14
15 /***
16 * Represents a Java virtual machine instruction. An operation is id-ed with a
17 * short opcode and has a predefined bytelength.
18 * <p>
19 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
20 * University of Technology </a>, the Netherlands. <br>
21 * See for project information <a
22 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
23 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
24 * License (GPL) </a>, no warranty <br>
25 *
26 * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
27 * Jacobs </a>
28 * @version 1.2 Apr 1, 2004
29 * @since 1.4
30 */
31 public abstract class Operation
32 {
33 /*** OPCODE_BYTE_LENGTH */
34 public static final int OPCODE_BYTE_LENGTH = 1;
35
36 /*** RESERVED OPCODE */
37 public static final int BREAKPOINT = 202;
38
39 /*** RESERVED OPCODE */
40 public static final int IMPDEP1 = 254;
41
42 /*** RESERVED OPCODE */
43 public static final int IMPDEP2 = 255;
44
45 /***
46 * @return Returns the opcode of the operation
47 */
48 public abstract int getOpcode();
49
50 /***
51 * @return Returs the byteLength
52 */
53 public abstract int getByteLength();
54
55 /***
56 * @see java.lang.Object#toString()
57 */
58 public String toString()
59 {
60 return this.getClass().getName().substring(
61 this.getClass().getName().lastIndexOf(".") + 1);
62 }
63
64 /***
65 * represents a set of operations as string.
66 *
67 * @param methodDescriptor the methodDescriptor
68 * @param operations the operations to represent
69 * @return The resulting string.
70 */
71 public static String toString(final MethodDescriptor methodDescriptor,
72 final Operation[] operations)
73 {
74 String result = "";
75 for (int i = 0; i < operations.length; i++)
76 {
77 result = result + i + ": " + " ("
78 + methodDescriptor.getBytePosition(i) + ")"
79 + operations[i].toString() + "\n";
80 }
81 return result;
82 }
83 }