1 cananian 1.1.2.1 // PGET.java, created Wed Jan 20 21:47:52 1999 by cananian
 2 cananian 1.1.2.1 // Copyright (C) 1999 C. Scott Ananian <cananian@alumni.princeton.edu>
 3 cananian 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details.
 4 cananian 1.1.2.1 package harpoon.IR.LowQuad;
 5 cananian 1.1.2.1 
 6 cananian 1.1.2.4 import harpoon.ClassFile.HClass;
 7 cananian 1.1.2.1 import harpoon.ClassFile.HCodeElement;
 8 cananian 1.1.2.1 import harpoon.Temp.Temp;
 9 cananian 1.1.2.1 import harpoon.Temp.TempMap;
10 cananian 1.1.2.1 import harpoon.Util.Util;
11 cananian 1.1.2.1 
12 cananian 1.1.2.1 /**
13 cananian 1.1.2.1  * <code>PGET</code> represents a <code>POINTER</code> dereference to
14 cananian 1.1.2.2  * get a field or array element.  The <code>ptr</code> <code>Temp</code>
15 cananian 1.1.2.2  * ought to contain a <code>POINTER</code> value.
16 cananian 1.1.2.1  * 
17 cananian 1.1.2.1  * @author  C. Scott Ananian <cananian@alumni.princeton.edu>
18 cananian 1.5      * @version $Id: PGET.java,v 1.5 2002/04/11 04:00:21 cananian Exp $
19 cananian 1.1.2.1  */
20 cananian 1.1.2.1 public class PGET extends LowQuad {
21 cananian 1.1.2.1     /** <code>Temp</code> in which to store the fetched field or array
22 cananian 1.1.2.1      *  element. */
23 cananian 1.1.2.1     protected final Temp dst;
24 cananian 1.1.2.1     /** <code>Temp</code> holding the <code>POINTER</code> value to
25 cananian 1.1.2.1      *  dereference and fetch. */
26 cananian 1.1.2.1     protected final Temp ptr;
27 cananian 1.1.2.4     /** The type of the object we are fetching.  This may be
28 cananian 1.1.2.4      *  a sub-integer type, and thus disagree with the type of
29 cananian 1.1.2.4      *  <code>dst</code>.  For non-primitive types, this may be
30 cananian 1.1.2.4      *  simply <code>Object</code>; use a typemap and the <code>dst</code>
31 cananian 1.1.2.4      *  field if you need accurate non-primitive types. */
32 cananian 1.1.2.4     protected final HClass type;
33 cananian 1.1.2.1     
34 cananian 1.1.2.2     /** Creates a <code>PGET</code> representing a pointer dereference and
35 cananian 1.1.2.2      *  fetch.
36 cananian 1.1.2.1      * @param dst
37 cananian 1.1.2.1      *        the <code>Temp</code> in which to store the fetched field or
38 cananian 1.1.2.1      *        element.
39 cananian 1.1.2.1      * @param ptr
40 cananian 1.1.2.1      *        the <code>Temp</code> holding the <code>POINTER</code> value
41 cananian 1.1.2.1      *        to dereference.
42 cananian 1.1.2.4      * @param type
43 cananian 1.1.2.4      *        the type of the object we are fetching; possibly a sub-integer
44 cananian 1.1.2.4      *        type.  Not necessarily precise if non-primitive.
45 cananian 1.1.2.1      */
46 cananian 1.1.2.4     public PGET(LowQuadFactory qf, HCodeElement source,
47 cananian 1.1.2.4                 Temp dst, Temp ptr, HClass type) {
48 cananian 1.1.2.1         super(qf, source);
49 cananian 1.1.2.1         this.dst = dst;
50 cananian 1.1.2.1         this.ptr = ptr;
51 cananian 1.1.2.4         this.type= type;
52 cananian 1.3.2.1         assert dst!=null && ptr!=null && type!=null;
53 cananian 1.1.2.1     }
54 cananian 1.1.2.1     // ACCESSOR METHODS:
55 cananian 1.1.2.1     /** Returns the <code>Temp</code> in which to store the fetched field or
56 cananian 1.1.2.1      *  array element. */
57 cananian 1.1.2.1     public Temp dst() { return dst; }
58 cananian 1.1.2.1     /** Returns the <code>Temp</code> holding the <code>POINTER</code> value
59 cananian 1.1.2.1      *  to dereference and fetch. */
60 cananian 1.1.2.1     public Temp ptr() { return ptr; }
61 cananian 1.1.2.4     /** Returns the type of the field or array element we are fetching.
62 cananian 1.1.2.4      *  Not necessarily precise if non-primitive.  May be a sub-integer
63 cananian 1.1.2.4      *  type. */
64 cananian 1.1.2.4     public HClass type() { return type; }
65 cananian 1.1.2.1 
66 cananian 1.1.2.1     public int kind() { return LowQuadKind.PGET; }
67 cananian 1.1.2.1 
68 cananian 1.1.2.1     public Temp[] use() { return new Temp[] { ptr }; }
69 cananian 1.1.2.1     public Temp[] def() { return new Temp[] { dst }; }
70 cananian 1.1.2.1 
71 cananian 1.1.2.1     public harpoon.IR.Quads.Quad rename(harpoon.IR.Quads.QuadFactory qf,
72 cananian 1.1.2.1                                         TempMap defMap, TempMap useMap) {
73 cananian 1.1.2.1         return new PGET((LowQuadFactory)qf, this,
74 cananian 1.1.2.4                         map(defMap, dst), map(useMap, ptr), type);
75 cananian 1.1.2.1     }
76 cananian 1.1.2.1 
77 cananian 1.1.2.3     void accept(LowQuadVisitor v) { v.visit(this); }
78 cananian 1.5         <T> T accept(LowQuadValueVisitor<T> v) { return v.visit(this); }
79 cananian 1.1.2.1 
80 cananian 1.1.2.1     public String toString() {
81 cananian 1.1.2.4         String r = dst.toString() + " = PGET *" + ptr.toString();
82 cananian 1.1.2.4         if (type.isPrimitive()) r+=" ("+type.toString()+")";
83 cananian 1.1.2.4         return r;
84 cananian 1.1.2.1     }
85 cananian 1.2     }