package IRT;
import Frame.Access;

/**
 * Information about accessing variables in the current frame,
 * computed during the Tiger compilation process.  
 * <p>
 * <strong>History</strong>
 * <dl>
 * <dt>8 December 1998 (version 0.1)
 * <dt>16 December 1998
 * <dd>Added the constructor
 * <dd>Added the <code>exp</code> method.
 * </dl>
 *
 * @author Samuel A. Rebelsky
 * @author Andrew Appel
 * @version 0.2 of 16 December 1998
 */
public class InFrame extends Access {
  // +--------+--------------------------------------------------
  // | Fields |
  // +--------+

  /**
   * The offset from the start of the frame, in words.
   */
  int offset;


  // +--------------+--------------------------------------------
  // | Constructors |
  // +--------------+

  /**
   * Create a new in-frame access, using a particular offset.
   */
  public InFrame(int offset) {
    this.offset = offset;
  } // InFrame(int)

  // +---------+-------------------------------------------------
  // | Methods |
  // +---------+

  /**
   * Build the tree expression used to get the variable.
   * Use the pointer to the frame that includes the variable.
   * <p>
   * Red book, p. 163.
   */
  public Tree.Exp exp(Tree.Exp framePtr) {
    return new Tree.MEM(new Tree.BINOP(Tree.BINOP.MINUS,
                                       framePtr,
                                       new Tree.CONST(offset)));
  } // exp(Tree.Exp)

} // class InFrame

