1 cananian 1.1.2.1 // ASET.java, created Wed Aug 26 19:12:32 1998 by cananian 2 cananian 1.1.2.1 // Copyright (C) 1998 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.Quads; 5 cananian 1.1.2.1 6 cananian 1.1.2.9 import harpoon.ClassFile.HClass; 7 cananian 1.1.2.6 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.2 import harpoon.Util.Util; 11 cananian 1.1.2.1 12 cananian 1.1.2.1 /** 13 cananian 1.1.2.1 * <code>ASET</code> represents an array element assignment. 14 cananian 1.1.2.1 * 15 cananian 1.1.2.1 * @author C. Scott Ananian <cananian@alumni.princeton.edu> 16 cananian 1.5 * @version $Id: ASET.java,v 1.5 2002/04/11 04:00:30 cananian Exp $ 17 cananian 1.1.2.1 * @see ANEW 18 cananian 1.1.2.1 * @see AGET 19 cananian 1.1.2.1 * @see ALENGTH 20 cananian 1.1.2.1 */ 21 cananian 1.1.2.1 public class ASET extends Quad { 22 cananian 1.1.2.1 /** The array reference */ 23 cananian 1.1.2.2 protected Temp objectref; 24 cananian 1.1.2.2 /** The <code>Temp</code> holding the index of the element to get. */ 25 cananian 1.1.2.2 protected Temp index; 26 cananian 1.1.2.1 /** The new value for the array element. */ 27 cananian 1.1.2.2 protected Temp src; 28 cananian 1.1.2.9 /** The component type of the referenced array. */ 29 cananian 1.1.2.9 protected HClass type; 30 cananian 1.1.2.1 31 cananian 1.1.2.2 /** Creates an <code>ASET</code> object representing an array element 32 cananian 1.1.2.2 * assignment. 33 cananian 1.1.2.2 * @param objectref 34 cananian 1.1.2.2 * the <code>Temp</code> holding the array reference. 35 cananian 1.1.2.2 * @param index 36 cananian 1.1.2.2 * the <code>Temp</code> holding the index of the element to get. 37 cananian 1.1.2.2 * @param src 38 cananian 1.1.2.2 * the <code>Temp</code> holding the new value for the array 39 cananian 1.1.2.2 * element. 40 cananian 1.1.2.9 * @param type 41 cananian 1.1.2.9 * the component type of the referenced array. 42 cananian 1.1.2.2 */ 43 cananian 1.1.2.4 public ASET(QuadFactory qf, HCodeElement source, 44 cananian 1.1.2.9 Temp objectref, Temp index, Temp src, HClass type) { 45 cananian 1.1.2.4 super(qf, source); 46 cananian 1.1.2.1 this.objectref = objectref; 47 cananian 1.1.2.1 this.index = index; 48 cananian 1.1.2.1 this.src = src; 49 cananian 1.1.2.9 this.type = type.isPrimitive() ? type : 50 cananian 1.1.2.9 type.getLinker().forDescriptor("Ljava/lang/Object;"); 51 cananian 1.1.2.2 // VERIFY legality of this ASET 52 cananian 1.3.2.1 assert objectref!=null && index!=null && src!=null; 53 cananian 1.1.2.1 } 54 cananian 1.1.2.2 // ACCESSOR FUNCTIONS: 55 cananian 1.1.2.2 /** Returns the <code>Temp</code> with the array reference. */ 56 cananian 1.1.2.2 public Temp objectref() { return objectref; } 57 cananian 1.1.2.2 /** Returns the <code>Temp</code> with the index of the element to get. */ 58 cananian 1.1.2.2 public Temp index() { return index; } 59 cananian 1.1.2.2 /** Returns the <code>Temp</code> holding the new value for the array 60 cananian 1.1.2.2 * element. */ 61 cananian 1.1.2.2 public Temp src() { return src; } 62 cananian 1.1.2.9 /** Returns the component type of the referenced array. All 63 cananian 1.1.2.9 * non-primitive types become <code>Object</code>. */ 64 cananian 1.1.2.9 public HClass type() { return type; } 65 cananian 1.1.2.1 66 cananian 1.1.2.1 /** Returns all the Temps used by this quad. 67 cananian 1.1.2.1 * @return the <code>objectref</code>, <code>index</code>, and 68 cananian 1.1.2.1 * <code>src</code> fields. 69 cananian 1.1.2.1 */ 70 cananian 1.1.2.1 public Temp[] use() { return new Temp[] { objectref, index, src }; } 71 cananian 1.1.2.1 72 cananian 1.1.2.3 public int kind() { return QuadKind.ASET; } 73 cananian 1.1.2.3 74 cananian 1.1.2.5 public Quad rename(QuadFactory qqf, TempMap defMap, TempMap useMap) { 75 cananian 1.1.2.5 return new ASET(qqf, this, map(useMap,objectref), 76 cananian 1.1.2.9 map(useMap,index), map(useMap,src), type); 77 cananian 1.1.2.3 } 78 cananian 1.1.2.5 /** Rename all used variables in this Quad according to a mapping. 79 cananian 1.1.2.5 * @deprecated does not preserve immutability. */ 80 cananian 1.1.2.3 void renameUses(TempMap tm) { 81 cananian 1.1.2.1 objectref = tm.tempMap(objectref); 82 cananian 1.1.2.1 index = tm.tempMap(index); 83 cananian 1.1.2.1 src = tm.tempMap(src); 84 cananian 1.1.2.1 } 85 cananian 1.1.2.5 /** Rename all defined variables in this Quad according to a mapping. 86 cananian 1.1.2.5 * @deprecated does not preserve immutability. */ 87 cananian 1.1.2.3 void renameDefs(TempMap tm) { } 88 cananian 1.1.2.1 89 cananian 1.1.2.7 public void accept(QuadVisitor v) { v.visit(this); } 90 cananian 1.5 public <T> T accept(QuadValueVisitor<T> v) { return v.visit(this); } 91 cananian 1.1.2.1 92 cananian 1.1.2.1 /** Returns a human-readable representation of this quad. */ 93 cananian 1.1.2.1 public String toString() { 94 cananian 1.1.2.9 return "ASET " + objectref + "["+index+"] = ("+type.getName()+") "+ src; 95 cananian 1.1.2.1 } 96 cananian 1.2 }