//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// PLEASE DO NOT EDIT WITHOUT THE EXPLICIT CONSENT OF THE AUTHOR! \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\

package hlt.language.design.instructions;

/**
 * @version     Last modified on Wed Jun 20 14:29:51 2012 by hak
 * @author      <a href="mailto:hak@acm.org">Hassan A&iuml;t-Kaci</a>
 * @copyright   &copy; <a href="http://www.hassan-ait-kaci.net/">by the author</a>
 */

/**
 * This class is the mother of all instructions that refer to an
 * absolute address and that must be relocated upon inlining.
 */
public abstract class Relocatable extends Instruction
{
  protected int _address;

  Relocatable ()
    {
    }

  public abstract Relocatable relocate (int address);
  
  public final Relocatable setAddress (int address)
    {
      _address = address;
      return this;
    }

  public final int address ()
    {
      return _address;
    }

  public final int hashCode ()
    {
      return name().hashCode() + _address;
    }

  public final boolean equals (Object object)
    {
      if (this == object)
        return true;

      if (!(object instanceof Relocatable))
        return false;

      Relocatable other = (Relocatable)object;

      return name() == other.name() && _address == other.address();
    }

  public final String toString ()
    {
      return name()+"(" + _address + ")";
    }
}
