151 * "<"<target instruction>">" "@"<branch target offset> |
152 * "<"<target instruction>">" "@"<branch target offset> |
152 * |
153 * |
153 * @param verbose long/short format switch |
154 * @param verbose long/short format switch |
154 * @return mnemonic for instruction |
155 * @return mnemonic for instruction |
155 */ |
156 */ |
|
157 @Override |
156 public String toString(boolean verbose) { |
158 public String toString(boolean verbose) { |
157 String s = super.toString(verbose); |
159 String s = super.toString(verbose); |
158 String t = "null"; |
160 String t = "null"; |
159 |
161 |
160 if(verbose) { |
162 if(verbose) { |
182 * |
184 * |
183 * @param bytes input stream |
185 * @param bytes input stream |
184 * @param wide wide prefix? |
186 * @param wide wide prefix? |
185 * @see InstructionList |
187 * @see InstructionList |
186 */ |
188 */ |
|
189 @Override |
187 protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException |
190 protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException |
188 { |
191 { |
189 length = 3; |
192 length = 3; |
190 index = bytes.readShort(); |
193 index = bytes.readShort(); |
191 } |
194 } |
202 |
205 |
203 /** |
206 /** |
204 * Set branch target |
207 * Set branch target |
205 * @param target branch target |
208 * @param target branch target |
206 */ |
209 */ |
207 public void setTarget(InstructionHandle target) { |
210 public final void setTarget(InstructionHandle target) { |
208 notifyTarget(this.target, target, this); |
211 notifyTargetChanging(this.target, this); |
209 this.target = target; |
212 this.target = target; |
210 } |
213 notifyTargetChanged(this.target, this); |
211 |
214 } |
212 /** |
215 |
213 * Used by BranchInstruction, LocalVariableGen, CodeExceptionGen |
216 /** |
214 */ |
217 * Used by BranchInstruction, LocalVariableGen, CodeExceptionGen. |
215 static final void notifyTarget(InstructionHandle old_ih, InstructionHandle new_ih, |
218 * Must be called before the target is actually changed in the |
|
219 * InstructionTargeter. |
|
220 */ |
|
221 static void notifyTargetChanging(InstructionHandle old_ih, |
216 InstructionTargeter t) { |
222 InstructionTargeter t) { |
217 if(old_ih != null) |
223 if(old_ih != null) { |
218 old_ih.removeTargeter(t); |
224 old_ih.removeTargeter(t); |
219 if(new_ih != null) |
225 } |
|
226 } |
|
227 |
|
228 /** |
|
229 * Used by BranchInstruction, LocalVariableGen, CodeExceptionGen. |
|
230 * Must be called after the target is actually changed in the |
|
231 * InstructionTargeter. |
|
232 */ |
|
233 static void notifyTargetChanged(InstructionHandle new_ih, |
|
234 InstructionTargeter t) { |
|
235 if(new_ih != null) { |
220 new_ih.addTargeter(t); |
236 new_ih.addTargeter(t); |
|
237 } |
221 } |
238 } |
222 |
239 |
223 /** |
240 /** |
224 * @param old_ih old target |
241 * @param old_ih old target |
225 * @param new_ih new target |
242 * @param new_ih new target |
226 */ |
243 */ |
|
244 @Override |
227 public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { |
245 public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { |
228 if(target == old_ih) |
246 if(target == old_ih) |
229 setTarget(new_ih); |
247 setTarget(new_ih); |
230 else |
248 else |
231 throw new ClassGenException("Not targeting " + old_ih + ", but " + target); |
249 throw new ClassGenException("Not targeting " + old_ih + ", but " + target); |
232 } |
250 } |
233 |
251 |
234 /** |
252 /** |
235 * @return true, if ih is target of this instruction |
253 * @return true, if ih is target of this instruction |
236 */ |
254 */ |
|
255 @Override |
237 public boolean containsTarget(InstructionHandle ih) { |
256 public boolean containsTarget(InstructionHandle ih) { |
238 return (target == ih); |
257 return (target == ih); |
239 } |
258 } |
240 |
259 |
241 /** |
260 /** |
242 * Inform target that it's not targeted anymore. |
261 * Inform target that it's not targeted anymore. |
243 */ |
262 */ |
|
263 @Override |
244 void dispose() { |
264 void dispose() { |
245 setTarget(null); |
265 setTarget(null); |
246 index=-1; |
266 index=-1; |
247 position=-1; |
267 position=-1; |
248 } |
268 } |