1 cananian 1.1.2.5  // CJUMP.java, created Wed Jan 13 21:14:57 1999 by cananian
 2 cananian 1.1.2.12 // Copyright (C) 1998 C. Scott Ananian <cananian@alumni.princeton.edu>
 3 cananian 1.1.2.12 // 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.17 import harpoon.Temp.TempMap;
 8 cananian 1.1.2.1  import harpoon.Temp.Label;
 9 cananian 1.1.2.3  import harpoon.Util.Util;
10 cananian 1.1.2.1  
11 cananian 1.1.2.1  /**
12 cananian 1.1.2.5   * <code>CJUMP</code> objects are statements which stand for conditional
13 cananian 1.1.2.5   * branches.
14 cananian 1.1.2.1   * 
15 cananian 1.1.2.1   * @author  C. Scott Ananian <cananian@alumni.princeton.edu>, based on
16 cananian 1.1.2.1   *          <i>Modern Compiler Implementation in Java</i> by Andrew Appel.
17 cananian 1.4       * @version $Id: CJUMP.java,v 1.4 2002/04/10 03:05:39 cananian Exp $
18 cananian 1.1.2.1   */
19 cananian 1.1.2.1  public class CJUMP extends Stm {
20 cananian 1.1.2.1      /** The label to jump to if <code>test</code> is <code>true</code>. */
21 cananian 1.1.2.16     public final Label iftrue;
22 cananian 1.1.2.1      /** The label to jump to if <code>test</code> is <code>false</code>. */
23 cananian 1.1.2.16     public final Label iffalse;
24 duncan   1.1.2.14     
25 cananian 1.1.2.1      /** Constructor. */
26 cananian 1.1.2.3      public CJUMP(TreeFactory tf, HCodeElement source,
27 cananian 1.1.2.3                   Exp test, Label iftrue, Label iffalse) {
28 cananian 1.1.2.16         super(tf, source, 1);
29 cananian 1.3.2.1          assert test!=null && iftrue!=null && iffalse!=null;
30 cananian 1.1.2.16         this.setTest(test); this.iftrue = iftrue; this.iffalse = iffalse;
31 cananian 1.3.2.1          assert tf == test.tf : "This and Test must have same tree factory";
32 duncan   1.1.2.14     }
33 duncan   1.1.2.14 
34 cananian 1.1.2.16     /** Returns the test condition for this <code>CJUMP</code>.
35 cananian 1.1.2.16      *  The expression should evaluate into a boolean result. */
36 cananian 1.1.2.16     public Exp getTest() { return (Exp) getChild(0); } 
37 cananian 1.1.2.16 
38 cananian 1.1.2.16     /** Returns the test condition for this <code>CJUMP</code>.
39 cananian 1.1.2.16      *  The given expression should evaluate into a boolean result. */
40 cananian 1.1.2.16     public void setTest(Exp test) { setChild(0, test); }
41 duncan   1.1.2.7      
42 duncan   1.1.2.8      public int kind() { return TreeKind.CJUMP; }
43 duncan   1.1.2.8  
44 duncan   1.1.2.11     public Stm build(TreeFactory tf, ExpList kids) {
45 cananian 1.3.2.1          assert kids!=null && kids.tail==null;
46 cananian 1.3.2.1          assert tf == kids.head.tf;
47 cananian 1.1.2.3          return new CJUMP(tf, this, kids.head, iftrue, iffalse);
48 cananian 1.1.2.1      }
49 duncan   1.1.2.2      /** Accept a visitor */
50 cananian 1.1.2.13     public void accept(TreeVisitor v) { v.visit(this); }
51 duncan   1.1.2.4  
52 cananian 1.1.2.17     public Tree rename(TreeFactory tf, TempMap tm, CloneCallback cb) {
53 cananian 1.1.2.17         return cb.callback(this, new CJUMP(tf, this,
54 cananian 1.1.2.17                                            (Exp)getTest().rename(tf, tm, cb),
55 cananian 1.1.2.18                                            iftrue, iffalse),
56 cananian 1.1.2.18                            tm);
57 andyb    1.1.2.6      }
58 andyb    1.1.2.6  
59 andyb    1.1.2.6      public String toString() {
60 cananian 1.1.2.16         return "CJUMP(#"+getTest().getID()+", "+iftrue+", "+iffalse+")";
61 duncan   1.1.2.4      }
62 cananian 1.1.2.1  }
63 cananian 1.2