001
002/*
003 * THIS FILE IS MACHINE_GENERATED. DO NOT EDIT.
004 * See InstructionFormats.template, CommonOperands.dat,
005 * OperatorList.dat, etc.
006 */
007
008package org.jikesrvm.compilers.opt.ir;
009
010import org.jikesrvm.Configuration;
011import org.jikesrvm.VM;
012import org.jikesrvm.compilers.opt.ir.operand.*;
013
014/**
015 * InstructionFormats that have a Location (which is LocationOperand)
016 */
017public final class LocationCarrier extends InstructionFormat {
018
019  /**
020   * Performs table lookup
021   * @param index the index to lookup
022   * @return the index into the instruction operands that carries the Location
023   *   or -1 if not carried
024   */
025  public static int lookup(int index) {
026    if (VM.BuildForIA32) {
027      return org.jikesrvm.compilers.opt.ir.ia32.LocationCarrierLookup.lookup(index);
028    } else {
029      if (VM.VerifyAssertions) VM._assert(VM.BuildForPowerPC);
030      return org.jikesrvm.compilers.opt.ir.ppc.LocationCarrierLookup.lookup(index);
031    }
032  }
033
034  /**
035   * Does the instruction belong to an instruction format that
036   * has an operand called Location?
037   * @param i the instruction to test
038   * @return <code>true</code> if the instruction's instruction
039   *         format has an operand called Location and
040   *         <code>false</code> if it does not.
041   */
042  public static boolean conforms(Instruction i) {
043    return conforms(i.operator());
044  }
045  /**
046   * Does the operator belong to an instruction format that
047   * has an operand called Location?
048   * @param o the operator to test
049   * @return <code>true</code> if the instruction's instruction
050   *         format has an operand called Location and
051   *         <code>false</code> if it does not.
052   */
053  public static boolean conforms(Operator o) {
054    return lookup(o.format) != -1;
055  }
056
057  /**
058   * Get the operand called Location from the
059   * argument instruction. Note that the returned operand
060   * will still point to its containing instruction.
061   * @param i the instruction to fetch the operand from
062   * @return the operand called Location
063   */
064  public static LocationOperand getLocation(Instruction i) {
065    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LocationCarrier");
066    int index = lookup(i.operator().format);
067    return (LocationOperand) i.getOperand(index);
068  }
069  /**
070   * Get the operand called Location from the argument
071   * instruction clearing its instruction pointer. The returned
072   * operand will not point to any containing instruction.
073   * @param i the instruction to fetch the operand from
074   * @return the operand called Location
075   */
076  public static LocationOperand getClearLocation(Instruction i) {
077    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LocationCarrier");
078    int index = lookup(i.operator().format);
079    return (LocationOperand) i.getClearOperand(index);
080  }
081  /**
082   * Set the operand called Location in the argument
083   * instruction to the argument operand. The operand will
084   * now point to the argument instruction as its containing
085   * instruction.
086   * @param i the instruction in which to store the operand
087   * @param op the operand to store
088   */
089  public static void setLocation(Instruction i, LocationOperand op) {
090    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LocationCarrier");
091    int index = lookup(i.operator().format);
092    i.putOperand(index, op);
093  }
094  /**
095   * Return the index of the operand called Location
096   * in the argument instruction.
097   * @param i the instruction to access.
098   * @return the index of the operand called Location
099   *         in the argument instruction
100   */
101  public static int indexOfLocation(Instruction i) {
102    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LocationCarrier");
103    return lookup(i.operator().format);
104  }
105  /**
106   * Does the argument instruction have a non-null
107   * operand named Location?
108   * @param i the instruction to access.
109   * @return <code>true</code> if the instruction has an non-null
110   *         operand named Location or <code>false</code>
111   *         if it does not.
112   */
113  public static boolean hasLocation(Instruction i) {
114    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "LocationCarrier");
115    int index = lookup(i.operator().format);
116    return i.getOperand(index) != null;
117  }
118}
119