1 package serp.bytecode;
2
3 import java.io.*;
4 import java.util.*;
5
6 import serp.bytecode.lowlevel.*;
7 import serp.bytecode.visitor.*;
8
9
10
11
12
13
14 public class Instruction extends CodeEntry implements BCEntity, VisitAcceptor {
15 private Code _owner = null;
16 private int _opcode = Constants.NOP;
17
18 Instruction(Code owner) {
19 _owner = owner;
20 }
21
22 Instruction(Code owner, int opcode) {
23 _owner = owner;
24 _opcode = opcode;
25 }
26
27
28
29
30 public Code getCode() {
31 return _owner;
32 }
33
34
35
36
37 public String getName() {
38 return Constants.OPCODE_NAMES[_opcode];
39 }
40
41
42
43
44 public int getOpcode() {
45 return _opcode;
46 }
47
48
49
50
51
52
53 Instruction setOpcode(int opcode) {
54 _opcode = opcode;
55 return this;
56 }
57
58
59
60
61
62
63 public int getByteIndex() {
64 if (_owner != null)
65 return _owner.getByteIndex(this);
66 return 0;
67 }
68
69
70
71
72
73 void invalidateByteIndexes() {
74 if (_owner != null)
75 _owner.invalidateByteIndexes();
76 }
77
78
79
80
81
82
83
84 public LineNumber getLineNumber() {
85 LineNumberTable table = _owner.getLineNumberTable(false);
86 if (table == null)
87 return null;
88 return table.getLineNumber(this);
89 }
90
91
92
93
94
95 int getLength() {
96 return 1;
97 }
98
99
100
101
102
103
104 public int getLogicalStackChange() {
105 return getStackChange();
106 }
107
108
109
110
111
112
113
114
115
116 public int getStackChange() {
117 return 0;
118 }
119
120
121
122
123
124
125
126 public boolean equalsInstruction(Instruction other) {
127 if (other == this)
128 return true;
129 return other.getOpcode() == getOpcode();
130 }
131
132 public Project getProject() {
133 return _owner.getProject();
134 }
135
136 public ConstantPool getPool() {
137 return _owner.getPool();
138 }
139
140 public ClassLoader getClassLoader() {
141 return _owner.getClassLoader();
142 }
143
144 public boolean isValid() {
145 return _owner != null;
146 }
147
148 public void acceptVisit(BCVisitor visit) {
149 }
150
151 void invalidate() {
152 _owner = null;
153 }
154
155
156
157
158 void read(Instruction orig) {
159 }
160
161
162
163
164
165 void read(DataInput in) throws IOException {
166 }
167
168
169
170
171
172 void write(DataOutput out) throws IOException {
173 }
174 }