1 pnkfelix 1.1.2.1 // Web.java, created Fri Nov 5 15:05:24 1999 by pnkfelix 2 pnkfelix 1.1.2.1 // Copyright (C) 1999 Felix S. Klock II <pnkfelix@mit.edu> 3 pnkfelix 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details. 4 pnkfelix 1.1.2.1 package harpoon.Analysis.Instr; 5 pnkfelix 1.1.2.1 6 pnkfelix 1.1.2.1 import harpoon.Temp.Temp; 7 pnkfelix 1.1.2.1 import harpoon.ClassFile.HCodeElement; 8 pnkfelix 1.1.2.3 import harpoon.Util.Util; 9 pnkfelix 1.1.2.1 10 pnkfelix 1.1.2.1 import java.util.Iterator; 11 pnkfelix 1.1.2.1 import java.util.Set; 12 pnkfelix 1.1.2.1 import java.util.HashSet; 13 pnkfelix 1.1.2.1 14 pnkfelix 1.1.2.1 /** 15 pnkfelix 1.1.2.1 * <code>Web</code> is a helper class used in Register Allocation. 16 pnkfelix 1.1.2.1 * 17 pnkfelix 1.1.2.1 * @author Felix S. Klock II <pnkfelix@mit.edu> 18 cananian 1.4 * @version $Id: Web.java,v 1.4 2002/04/10 02:59:47 cananian Exp $ 19 pnkfelix 1.1.2.1 */ 20 pnkfelix 1.1.2.1 class Web extends harpoon.Analysis.GraphColoring.SparseNode { 21 pnkfelix 1.1.2.1 Temp var; 22 pnkfelix 1.1.2.1 23 cananian 1.1.2.4 /** Set of <code>Properties.UseDefable</code>s which use or define 24 pnkfelix 1.1.2.1 <code>this.var</code>. 25 pnkfelix 1.1.2.1 */ 26 pnkfelix 1.1.2.1 HashSet refs; 27 pnkfelix 1.1.2.2 28 pnkfelix 1.1.2.2 // We may want to consider making some sort of WebFactory so that 29 pnkfelix 1.1.2.2 // we can store a shared Reference->Web map. But for now we'll 30 pnkfelix 1.1.2.2 // force developers to construct such a map on their own. 31 pnkfelix 1.1.2.1 32 pnkfelix 1.1.2.1 static int counter=1; 33 pnkfelix 1.1.2.1 int id; 34 pnkfelix 1.1.2.1 35 pnkfelix 1.1.2.1 Web(Temp var) { 36 cananian 1.3.2.1 assert var != null; 37 pnkfelix 1.1.2.1 this.var = var; 38 pnkfelix 1.1.2.1 refs = new HashSet(); 39 pnkfelix 1.1.2.1 id = counter; 40 pnkfelix 1.1.2.1 counter++; 41 pnkfelix 1.1.2.1 } 42 pnkfelix 1.1.2.1 43 pnkfelix 1.1.2.1 Web(Temp var, Set refSet) { 44 pnkfelix 1.1.2.1 this(var); 45 pnkfelix 1.1.2.1 refs.addAll(refSet); 46 pnkfelix 1.1.2.1 } 47 pnkfelix 1.1.2.1 48 pnkfelix 1.1.2.1 public boolean equals(Object o) { 49 pnkfelix 1.1.2.1 try { 50 pnkfelix 1.1.2.1 Web w = (Web) o; 51 pnkfelix 1.1.2.1 return w.var.equals(this.var) && 52 pnkfelix 1.1.2.1 w.refs.equals(this.refs); 53 pnkfelix 1.1.2.1 } catch (ClassCastException e) { 54 pnkfelix 1.1.2.1 return false; 55 pnkfelix 1.1.2.1 } 56 pnkfelix 1.1.2.1 } 57 pnkfelix 1.1.2.1 58 pnkfelix 1.1.2.1 public int hashCode() { 59 pnkfelix 1.1.2.1 // reusing Temp's hash; we shouldn't be using both Webs and 60 pnkfelix 1.1.2.1 // Temps as keys in the same table anyway. 61 pnkfelix 1.1.2.1 return var.hashCode(); 62 pnkfelix 1.1.2.1 } 63 pnkfelix 1.1.2.1 64 pnkfelix 1.1.2.1 public String toString() { 65 pnkfelix 1.1.2.1 String ids = ""; 66 pnkfelix 1.1.2.1 Iterator iter = refs.iterator(); 67 pnkfelix 1.1.2.1 while(iter.hasNext()) { 68 pnkfelix 1.1.2.1 ids += ((HCodeElement)iter.next()).getID(); 69 pnkfelix 1.1.2.1 if (iter.hasNext()) ids+=", "; 70 pnkfelix 1.1.2.1 } 71 pnkfelix 1.1.2.1 return "Web[id: "+id+", Var: " + var + ", Refs: {"+ ids +"} ]"; 72 pnkfelix 1.1.2.1 } 73 pnkfelix 1.1.2.1 } 74 cananian 1.2