1 cananian 1.1.2.1  // TEMP.java, created Wed Jan 13 21:14:57 1999 by cananian
 2 cananian 1.1.2.18 // Copyright (C) 1998 C. Scott Ananian <cananian@alumni.princeton.edu>
 3 cananian 1.1.2.18 // 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.6  import harpoon.ClassFile.HCodeElement;
 7 cananian 1.1.2.24 import harpoon.Temp.TempMap;
 8 cananian 1.1.2.1  import harpoon.Temp.Temp;
 9 cananian 1.1.2.5  import harpoon.Util.Util;
10 cananian 1.1.2.1  
11 duncan   1.1.2.15 import java.util.HashSet;
12 duncan   1.1.2.15 import java.util.Set;
13 duncan   1.1.2.15 
14 cananian 1.1.2.1  /**
15 cananian 1.1.2.3   * <code>TEMP</code> objects are expressions which stand for a
16 cananian 1.1.2.3   * value in a virtual register.
17 cananian 1.1.2.1   * 
18 cananian 1.1.2.1   * @author  C. Scott Ananian <cananian@alumni.princeton.edu>, based on
19 cananian 1.1.2.1   *          <i>Modern Compiler Implementation in Java</i> by Andrew Appel.
20 cananian 1.4       * @version $Id: TEMP.java,v 1.4 2002/04/10 03:05:45 cananian Exp $
21 cananian 1.1.2.1   */
22 cananian 1.1.2.14 public class TEMP extends Exp {
23 cananian 1.1.2.1      /** The <code>Temp</code> which this <code>TEMP</code> refers to. */
24 cananian 1.1.2.1      public final Temp temp;
25 cananian 1.1.2.5      /** The type of this <code>Temp</code> expression. */
26 cananian 1.1.2.5      public final int type;
27 cananian 1.1.2.1      /** Constructor. */
28 andyb    1.1.2.11     public TEMP(TreeFactory tf, HCodeElement source, int type, Temp temp) {
29 cananian 1.1.2.23         super(tf, source, 0);
30 cananian 1.1.2.5          this.type=type; this.temp=temp;
31 cananian 1.3.2.1          assert Type.isValid(type);
32 cananian 1.3.2.1          assert temp!=null;
33 cananian 1.3.2.1          assert (temp.tempFactory() == tf.tempFactory()) ||
34 cananian 1.3.2.1                      (tf.getFrame().getRegFileInfo().isRegister(temp)) : "Non-register temp with non-matching factory";
35 cananian 1.1.2.5      }
36 duncan   1.1.2.21 
37 duncan   1.1.2.13     public int kind() { return TreeKind.TEMP; }
38 duncan   1.1.2.17 
39 duncan   1.1.2.17     public Exp build(TreeFactory tf, ExpList kids) {
40 cananian 1.3.2.1          assert kids==null;
41 cananian 1.3.2.1          assert tf.tempFactory() == temp.tempFactory() ||
42 cananian 1.3.2.1                      tf.getFrame().getRegFileInfo().isRegister(temp);
43 duncan   1.1.2.17         return new TEMP(tf, this, type, temp); 
44 duncan   1.1.2.17     }
45 cananian 1.1.2.3  
46 cananian 1.1.2.3      // Typed interface:
47 cananian 1.1.2.5      public int type() { return type; }
48 cananian 1.1.2.5  
49 duncan   1.1.2.4      /** Accept a visitor */
50 cananian 1.1.2.20     public void accept(TreeVisitor v) { v.visit(this); }
51 duncan   1.1.2.8  
52 cananian 1.1.2.24     public Tree rename(TreeFactory tf, TempMap tm, CloneCallback cb) {
53 cananian 1.1.2.26         Temp newTemp = this.temp;
54 cananian 1.1.2.26         if (tm != null && // don't remap registers!
55 cananian 1.1.2.26             !getFactory().getFrame().getRegFileInfo().isRegister(this.temp))
56 cananian 1.1.2.26             newTemp = tm.tempMap(this.temp);
57 cananian 1.1.2.26         return cb.callback(this,
58 cananian 1.1.2.26                            new TEMP(tf, this, this.type, newTemp),
59 cananian 1.1.2.26                            tm);
60 andyb    1.1.2.10     }
61 andyb    1.1.2.10 
62 andyb    1.1.2.10     public String toString() {
63 andyb    1.1.2.10         return "TEMP<"+Type.toString(type)+">("+temp+")";
64 duncan   1.1.2.8      }
65 cananian 1.2      }