1 cananian 1.1.2.1  // ESEQ.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.20 import harpoon.Temp.TempMap;
 8 cananian 1.1.2.3  import harpoon.Util.Util;
 9 cananian 1.1.2.3  
10 duncan   1.1.2.9  import java.util.HashSet;
11 duncan   1.1.2.9  import java.util.Set;
12 duncan   1.1.2.9  
13 cananian 1.1.2.1  /**
14 cananian 1.1.2.1   * <code>ESEQ</code> objects are expressions which chain a statement and
15 cananian 1.1.2.19  * an expression together.  The statement is evaluated for side effects, then
16 cananian 1.1.2.1   * the expression is evaluated.  The value of the expression is the value of
17 cananian 1.1.2.14  * the <code>ESEQ</code>.<p>
18 cananian 1.1.2.14  * <code>ESEQ</code>s are <code>PreciselyTyped</code> because the enclosed
19 cananian 1.1.2.14  * <code>Exp</code> may be <code>PreciselyTyped</code>.  In contexts such
20 cananian 1.1.2.17  * as <code>MOVE(ESEQ(stm, MEM&lt;small&gt;(e1)), e2)</code>, the
21 cananian 1.1.2.17  * <code>ESEQ</code> clearly has the same small type as the <code>MEM</code>.
22 cananian 1.1.2.1   * 
23 cananian 1.1.2.1   * @author  C. Scott Ananian <cananian@alumni.princeton.edu>, based on
24 cananian 1.1.2.1   *          <i>Modern Compiler Implementation in Java</i> by Andrew Appel.
25 salcianu 1.6       * @version $Id: ESEQ.java,v 1.6 2003/02/08 00:42:40 salcianu Exp $
26 cananian 1.1.2.1   */
27 cananian 1.1.2.14 public class ESEQ extends Exp implements PreciselyTyped {
28 cananian 1.1.2.1      /** Constructor. */
29 cananian 1.1.2.3      public ESEQ(TreeFactory tf, HCodeElement source,
30 cananian 1.1.2.3                  Stm stm, Exp exp) {
31 cananian 1.1.2.19         super(tf, source, 2);
32 cananian 1.3.2.1          assert stm!=null && exp!=null;
33 cananian 1.3.2.1          assert tf == exp.tf;
34 cananian 1.3.2.1          assert tf == stm.tf; 
35 cananian 1.1.2.19         setStm(stm); setExp(exp);
36 cananian 1.1.2.3      }
37 salcianu 1.5      
38 salcianu 1.5          /** Convenient constructor: the tree factory and the source
39 salcianu 1.5              arguments are identical to those for the statement and the
40 salcianu 1.6              expression.
41 salcianu 1.5      
42 salcianu 1.5              @param stm Statement executed first
43 salcianu 1.5      
44 salcianu 1.5              @param exp Expression evaluated next; its result is the value
45 salcianu 1.5              of the entire <code>ESEQ</code> expression. */
46 salcianu 1.5          public ESEQ(Stm stm, Exp exp) {
47 salcianu 1.5              this(stm.tf, stm, stm, exp);
48 salcianu 1.5          }
49 salcianu 1.5          
50 duncan   1.1.2.6  
51 cananian 1.1.2.19     /** Returns the statement to evaluate for side-effects. */
52 cananian 1.1.2.19     public Stm getStm() { return (Stm) getChild(0); } 
53 cananian 1.1.2.19     /** Returns the expression whose value is the the value of
54 cananian 1.1.2.19      *  the <code>ESEQ</code>.*/
55 cananian 1.1.2.19     public Exp getExp() { return (Exp) getChild(1); } 
56 cananian 1.1.2.19 
57 cananian 1.1.2.19     /** Sets the statement to evaluate for side-effects. */
58 cananian 1.1.2.19     public void setStm(Stm stm) { setChild(0, stm); }
59 cananian 1.1.2.19     /** Sets the expression whose value is the the value of
60 cananian 1.1.2.19      *  the <code>ESEQ</code>.*/
61 cananian 1.1.2.19     public void setExp(Exp exp) { setChild(1, exp); }
62 duncan   1.1.2.6  
63 cananian 1.1.2.1      public ExpList kids() {throw new Error("kids() not applicable to ESEQ");}
64 duncan   1.1.2.7  
65 duncan   1.1.2.7      public int kind() { return TreeKind.ESEQ; }
66 duncan   1.1.2.7  
67 duncan   1.1.2.11     public Exp build(TreeFactory tf, ExpList kids) {throw new Error("build() not applicable to ESEQ");}
68 duncan   1.1.2.11 
69 duncan   1.1.2.2      /** Accept a visitor */
70 cananian 1.1.2.16     public void accept(TreeVisitor v) { v.visit(this); }
71 duncan   1.1.2.4  
72 cananian 1.1.2.20     public Tree rename(TreeFactory tf, TempMap tm, CloneCallback cb) {
73 cananian 1.1.2.20         return cb.callback(this, new ESEQ(tf, this, 
74 cananian 1.1.2.20                                           (Stm)getStm().rename(tf, tm, cb), 
75 cananian 1.1.2.21                                           (Exp)getExp().rename(tf, tm, cb)),
76 cananian 1.1.2.21                            tm);
77 andyb    1.1.2.5      }
78 cananian 1.1.2.8  
79 cananian 1.1.2.19     public int type() { return getExp().type(); }
80 cananian 1.1.2.15     public boolean isSmall() { 
81 cananian 1.1.2.19         return (getExp() instanceof PreciselyTyped)
82 cananian 1.1.2.19             ? ((PreciselyTyped)getExp()).isSmall()
83 cananian 1.1.2.15             : false;
84 cananian 1.1.2.15     }
85 cananian 1.1.2.19     public int bitwidth() { return ((PreciselyTyped)getExp()).bitwidth(); }
86 cananian 1.1.2.19     public boolean signed() { return ((PreciselyTyped)getExp()).signed(); }
87 andyb    1.1.2.5  
88 andyb    1.1.2.5      public String toString() {
89 cananian 1.1.2.19         return "ESEQ(#" + getStm().getID() + ", #" + getExp().getID() + ")";
90 duncan   1.1.2.4      }
91 cananian 1.1.2.1  }
92 cananian 1.2