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 Guard (which is Operand)
016 */
017public final class GuardCarrier 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 Guard
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.GuardCarrierLookup.lookup(index);
028    } else {
029      if (VM.VerifyAssertions) VM._assert(VM.BuildForPowerPC);
030      return org.jikesrvm.compilers.opt.ir.ppc.GuardCarrierLookup.lookup(index);
031    }
032  }
033
034  /**
035   * Does the instruction belong to an instruction format that
036   * has an operand called Guard?
037   * @param i the instruction to test
038   * @return <code>true</code> if the instruction's instruction
039   *         format has an operand called Guard 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 Guard?
048   * @param o the operator to test
049   * @return <code>true</code> if the instruction's instruction
050   *         format has an operand called Guard 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 Guard 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 Guard
063   */
064  public static Operand getGuard(Instruction i) {
065    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "GuardCarrier");
066    int index = lookup(i.operator().format);
067    return (Operand) i.getOperand(index);
068  }
069  /**
070   * Get the operand called Guard 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 Guard
075   */
076  public static Operand getClearGuard(Instruction i) {
077    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "GuardCarrier");
078    int index = lookup(i.operator().format);
079    return (Operand) i.getClearOperand(index);
080  }
081  /**
082   * Set the operand called Guard 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 setGuard(Instruction i, Operand op) {
090    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "GuardCarrier");
091    int index = lookup(i.operator().format);
092    i.putOperand(index, op);
093  }
094  /**
095   * Return the index of the operand called Guard
096   * in the argument instruction.
097   * @param i the instruction to access.
098   * @return the index of the operand called Guard
099   *         in the argument instruction
100   */
101  public static int indexOfGuard(Instruction i) {
102    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "GuardCarrier");
103    return lookup(i.operator().format);
104  }
105  /**
106   * Does the argument instruction have a non-null
107   * operand named Guard?
108   * @param i the instruction to access.
109   * @return <code>true</code> if the instruction has an non-null
110   *         operand named Guard or <code>false</code>
111   *         if it does not.
112   */
113  public static boolean hasGuard(Instruction i) {
114    if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "GuardCarrier");
115    int index = lookup(i.operator().format);
116    return i.getOperand(index) != null;
117  }
118}
119