package edu.gac.max.mcs388.s2005.compiler_support; /** The Register class is used to represent a register of the target * architecture (MIPS). For now it is little more than the * $whatever name of the register, but this class might * well be evolved. * *
Written 7 Feb 1997 by
* Max Hailperin
* <max@gac.edu> */
public class Register{
String name;
/** The constructor that takes a single String argument expects it to be
the name of the register, without the $. */
public Register(String n){
name = "$" + n;
}
/** The constructor which takes a prefix String and then an integer is
for members of numbered families of registers, for example, one could do
new Register("t", 0)
to create $t0
. */
public Register(String prefix, int num){
this(prefix + num);
}
/** The toString conversion (which is automatically invoked if a Regiser
is added to a String) provides the name, inclusive of the $. */
public String toString(){
return name;
}
/** The equals method is overriden such that Registers are equal if their
names are equal */
public boolean equals(Object other){
if(other instanceof Register)
return name.equals(((Register)other).name);
else
return super.equals(other);
}
/** The hashCode method is overriden to reflect the name-based equality. */
public int hashCode(){
return name.hashCode();
}
}