1 cananian 1.1.2.1  // JUMP.java, created Wed Jan 13 21:14:57 1999 by cananian
 2 cananian 1.1.2.9  // Copyright (C) 1998 C. Scott Ananian <cananian@alumni.princeton.edu>
 3 cananian 1.1.2.9  // Licensed under the terms of the GNU GPL; see COPYING for details.
 4 cananian 1.1.2.1  package harpoon.IR.Tree;
 5 cananian 1.1.2.1  
 6 cananian 1.1.2.3  import harpoon.ClassFile.HCodeElement;
 7 cananian 1.1.2.14 import harpoon.Temp.TempMap;
 8 cananian 1.1.2.1  import harpoon.Temp.Label;
 9 cananian 1.1.2.1  import harpoon.Temp.LabelList;
10 cananian 1.1.2.3  import harpoon.Util.Util;
11 cananian 1.1.2.1  
12 cananian 1.1.2.1  /**
13 cananian 1.1.2.1   * <code>JUMP</code> objects are statements which stand for unconditional
14 cananian 1.1.2.1   * computed branches.
15 cananian 1.1.2.1   * 
16 cananian 1.1.2.1   * @author  C. Scott Ananian <cananian@alumni.princeton.edu>, based on
17 cananian 1.1.2.1   *          <i>Modern Compiler Implementation in Java</i> by Andrew Appel.
18 cananian 1.4       * @version $Id: JUMP.java,v 1.4 2002/04/10 03:05:45 cananian Exp $
19 cananian 1.1.2.1   */
20 cananian 1.1.2.1  public class JUMP extends Stm {
21 cananian 1.1.2.1      /** A list of possible branch targets. */
22 cananian 1.1.2.13     public final LabelList targets;
23 cananian 1.1.2.1      /** Full constructor. */
24 cananian 1.1.2.3      public JUMP(TreeFactory tf, HCodeElement source,
25 cananian 1.1.2.3                  Exp exp, LabelList targets) {
26 cananian 1.1.2.13         super(tf, source, 1);
27 cananian 1.3.2.1          assert exp!=null && targets!=null;
28 cananian 1.1.2.13         this.setExp(exp); this.targets=targets;
29 cananian 1.3.2.1          assert tf == exp.tf : "This and Exp must have same tree factory";
30 pnkfelix 1.1.2.7  
31 cananian 1.1.2.3      }
32 cananian 1.1.2.1      /** Abbreviated constructor for a non-computed branch. */
33 cananian 1.1.2.3      public JUMP(TreeFactory tf, HCodeElement source,
34 cananian 1.1.2.3                  Label target) {
35 cananian 1.1.2.3          this(tf, source,
36 cananian 1.1.2.3               new NAME(tf, source, target), new LabelList(target,null));
37 cananian 1.1.2.1      }
38 duncan   1.1.2.11 
39 cananian 1.1.2.13     /** Returns an expression giving the address to jump to. */
40 cananian 1.1.2.13     public Exp getExp() { return (Exp) getChild(0); }
41 cananian 1.1.2.13     /** Set the expression giving the address to jump to. */
42 cananian 1.1.2.13     public void setExp(Exp exp) { setChild(0, exp); }
43 duncan   1.1.2.11     
44 duncan   1.1.2.6      public int kind() { return TreeKind.JUMP; }
45 duncan   1.1.2.6  
46 duncan   1.1.2.8      public Stm build(TreeFactory tf, ExpList kids) {
47 cananian 1.3.2.1          assert kids!=null && kids.tail==null;
48 cananian 1.3.2.1          assert tf == kids.head.tf;
49 cananian 1.1.2.3          return new JUMP(tf, this, kids.head,targets);
50 cananian 1.1.2.1      }
51 duncan   1.1.2.2      /** Accept a visitor */
52 cananian 1.1.2.10     public void accept(TreeVisitor v) { v.visit(this); }
53 duncan   1.1.2.4  
54 cananian 1.1.2.14     public Tree rename(TreeFactory tf, TempMap tm, CloneCallback cb) {
55 cananian 1.1.2.15         return cb.callback(this, new JUMP(tf, this, (Exp)getExp().rename(tf, tm, cb), this.targets), tm);
56 duncan   1.1.2.4      }  
57 andyb    1.1.2.5  
58 andyb    1.1.2.5      public String toString() {
59 andyb    1.1.2.5          LabelList list = targets;
60 andyb    1.1.2.5          StringBuffer s = new StringBuffer();
61 andyb    1.1.2.5          
62 cananian 1.1.2.13         s.append("JUMP(#" + getExp().getID() + ", {");
63 andyb    1.1.2.5          while (list != null) {
64 andyb    1.1.2.5              s.append(" "+list.head);
65 andyb    1.1.2.5              if (list.tail != null) 
66 andyb    1.1.2.5                  s.append(",");
67 andyb    1.1.2.5              list = list.tail;
68 andyb    1.1.2.5          }
69 andyb    1.1.2.5          s.append(" })");
70 andyb    1.1.2.5          return new String(s);
71 andyb    1.1.2.5      }
72 cananian 1.1.2.1  }
73 cananian 1.2