KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jas > Label


1 /**
2  * Labels are implemented as Insn's, but are special (read
3  * unseemly blobs of hacked up code). First, they don't
4  * actually cause any code to be written, and second, are
5  * identified globally through a String label that is associated
6  * with them when they are created.
7  * @author $Author: fqian $
8  * @version $Revision: 1.1 $
9  */

10
11 package jas;
12
13 import java.io.*;
14
15
16 public class Label extends Insn implements RuntimeConstants
17 {
18   String JavaDoc id;
19
20   /**
21    * Create a new Label with this tag. Any label with this tag
22    * will be treated as being identical to this one. You can
23    * reuse labels if you like
24    */

25   public Label(String JavaDoc tag)
26   {
27     id = tag.intern();
28     opc = opc_label;
29     operand = null;
30   }
31                                 // override the write method to do nothing.
32
void write(ClassEnv e, CodeAttr ce, DataOutputStream out)
33   { return; }
34                                 // and the size method appropriately
35
int size(ClassEnv e, CodeAttr ce)
36   { return 0; }
37                                 // This is called from the LabelOperand
38
void writeOffset(CodeAttr ce, Insn source, DataOutputStream out)
39     throws jasError, IOException
40   { // write the offset (as a short)
41
// of source
42
int pc, tpc;
43     pc = ce.getPc(this);
44     if (source == null)
45       tpc = 0;
46     else
47       tpc = ce.getPc(source);
48     short offset = (short) (pc - tpc);
49     out.writeShort(offset);
50   }
51   void writeWideOffset(CodeAttr ce, Insn source, DataOutputStream out)
52      throws IOException, jasError
53   {
54     int pc, tpc;
55     pc = ce.getPc(this);
56     if (source == null)
57       tpc = 0;
58     else
59       tpc = ce.getPc(source);
60     out.writeInt(pc - tpc);
61   }
62   public String JavaDoc toString()
63   {
64     return ("Label: " + id);
65   }
66 }
67
68
Popular Tags