1 cananian 1.3.2.7 // Label.java, created Tue Jul 28 1:09:44 1998 by cananian 2 cananian 1.3.2.6 // Copyright (C) 1998 C. Scott Ananian <cananian@alumni.princeton.edu> 3 cananian 1.3.2.6 // Licensed under the terms of the GNU GPL; see COPYING for details. 4 cananian 1.2 package harpoon.Temp; 5 cananian 1.1 6 cananian 1.1 /** 7 cananian 1.3.2.4 * A <code>Label</code> represents a (symbolic) address in assembly language. 8 cananian 1.3.2.5 * @author C. Scott Ananian <cananian@alumni.princeton.edu> 9 cananian 1.4 * @version $Id: Label.java,v 1.4 2002/02/25 21:07:05 cananian Exp $ 10 cananian 1.1 */ 11 cananian 1.1 12 cananian 1.1 public class Label { 13 cananian 1.3.2.9 public final String name; 14 cananian 1.1 private static int count; 15 cananian 1.1 16 cananian 1.1 /** 17 cananian 1.1 * a printable representation of the label, for use in assembly 18 pnkfelix 1.3.2.8 * language output. Note that the returned <code>String</code> 19 pnkfelix 1.3.2.8 * consists only of a name; any platform specific modifiers (such as 20 pnkfelix 1.3.2.8 * a colon) need to be appended by the code calling 21 pnkfelix 1.3.2.8 * <code>toString()</code>. 22 cananian 1.1 */ 23 cananian 1.1 public String toString() {return name;} 24 cananian 1.1 25 cananian 1.1 /** 26 cananian 1.1 * Makes a new label that prints as "name". 27 cananian 1.3.2.9 * Repeated calls to <tt>new Label(s)</tt> with 28 cananian 1.3.2.9 * the same name <tt>s</tt> will return labels which 29 cananian 1.3.2.9 * are equal to each other according to the <code>equals()</code> 30 cananian 1.3.2.9 * method, but not reference equivalent. 31 cananian 1.1 */ 32 cananian 1.1 public Label(String n) { 33 cananian 1.1 name=n; 34 cananian 1.1 } 35 cananian 1.1 36 cananian 1.1 /** 37 cananian 1.1 * Makes a new label with an arbitrary name. 38 cananian 1.1 */ 39 cananian 1.1 public Label() { 40 cananian 1.3.2.10 this(".L" + count++); 41 cananian 1.1 } 42 andyb 1.3.2.2 43 andyb 1.3.2.2 public boolean equals(Object o) { 44 cananian 1.3.2.3 Label l; 45 cananian 1.3.2.3 if (this==o) return true; 46 cananian 1.3.2.3 if (null==o) return false; 47 cananian 1.3.2.3 try { l=(Label) o; } catch (ClassCastException e) { return false; } 48 cananian 1.3.2.3 return name.equals(l.name); 49 cananian 1.1 } 50 cananian 1.3.2.11 // make hashCode consistent with equals() 51 cananian 1.3.2.11 public int hashCode() { return name.hashCode(); } 52 cananian 1.1 }