001/*
002 *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 *  This file is licensed to You under the Eclipse Public License (EPL);
005 *  You may not use this file except in compliance with the License. You
006 *  may obtain a copy of the License at
007 *
008 *      http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 *  See the COPYRIGHT.txt file distributed with this work for information
011 *  regarding copyright ownership.
012 */
013package org.jikesrvm.compilers.opt.ir.operand;
014
015import org.jikesrvm.VM;
016import org.jikesrvm.compilers.opt.ir.Instruction;
017import org.jikesrvm.compilers.opt.ir.Label;
018
019/**
020 * Represents a branch target.
021 *
022 * @see Operand
023 */
024public final class BranchOperand extends Operand {
025
026  /**
027   * Target of this branch.
028   */
029  public Instruction target;
030
031  /**
032   * Construct a new branch operand with the given target.
033   * <STRONG> Precondition: </STRONG> targ must be a Label instruction.
034   *
035   * @param targ target of branch
036   */
037  public BranchOperand(Instruction targ) {
038    if (VM.VerifyAssertions) VM._assert(Label.conforms(targ));
039    target = targ;
040  }
041
042  /**
043   * Returns a copy of this branch operand.
044   *
045   * @return a copy of this operand
046   */
047  @Override
048  public Operand copy() {
049    return new BranchOperand(target);
050  }
051
052  @Override
053  public boolean similar(Operand op) {
054    return (op instanceof BranchOperand) && (target == ((BranchOperand) op).target);
055  }
056
057  /**
058   * Returns the string representation of this operand.
059   *
060   * @return a string representation of this operand.
061   */
062  @Override
063  public String toString() {
064    return "LABEL" + Label.getBlock(target).block.getNumber();
065  }
066
067}
068
069
070
071