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 */
013 package org.jikesrvm.compilers.opt.ir.operand;
014
015 import org.jikesrvm.VM;
016 import org.jikesrvm.compilers.opt.ir.Instruction;
017 import org.jikesrvm.compilers.opt.ir.Label;
018
019 /**
020 * Represents a branch target.
021 *
022 * @see Operand
023 */
024 public 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 public Operand copy() {
048 return new BranchOperand(target);
049 }
050
051 /**
052 * Are two operands semantically equivalent?
053 *
054 * @param op other operand
055 * @return <code>true</code> if <code>this</code> and <code>op</code>
056 * are semantically equivalent or <code>false</code>
057 * if they are not.
058 */
059 public boolean similar(Operand op) {
060 return (op instanceof BranchOperand) && (target == ((BranchOperand) op).target);
061 }
062
063 /**
064 * Returns the string representation of this operand.
065 *
066 * @return a string representation of this operand.
067 */
068 public String toString() {
069 return "LABEL" + Label.getBlock(target).block.getNumber();
070 }
071
072 }
073
074
075
076