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.classloader.RVMMethod;
017    import org.jikesrvm.classloader.TypeReference;
018    
019    /**
020     * Represents a constant code operand, found for example, from an
021     * TIBConstantOperand. NB we don't use an object constant operand
022     * because: 1) code doesn't form part of the object literals 2) we
023     * need to support replacement
024     *
025     * @see Operand
026     */
027    public final class CodeConstantOperand extends ConstantOperand {
028    
029      /**
030       * The non-null method for the code represent
031       */
032      public final RVMMethod value;
033    
034      /**
035       * Construct a new code constant operand
036       *
037       * @param v the method of this TIB
038       */
039      public CodeConstantOperand(RVMMethod v) {
040        if (VM.VerifyAssertions) VM._assert(v != null);
041        value = v;
042      }
043    
044      /**
045       * Return a new operand that is semantically equivalent to <code>this</code>.
046       *
047       * @return a copy of <code>this</code>
048       */
049      public Operand copy() {
050        return new CodeConstantOperand(value);
051      }
052    
053      /**
054       * Return the {@link TypeReference} of the value represented by the operand.
055       *
056       * @return TypeReference.JavaLangObjectArray
057       */
058      public TypeReference getType() {
059        return TypeReference.CodeArray;
060      }
061    
062      /**
063       * Does the operand represent a value of the reference data type?
064       *
065       * @return <code>true</code>
066       */
067      public boolean isRef() {
068        return true;
069      }
070    
071      /**
072       * Are two operands semantically equivalent?
073       *
074       * @param op other operand
075       * @return   <code>true</code> if <code>this</code> and <code>op</code>
076       *           are semantically equivalent or <code>false</code>
077       *           if they are not.
078       */
079      public boolean similar(Operand op) {
080        return (op instanceof CodeConstantOperand) && value == ((CodeConstantOperand) op).value;
081      }
082    
083      /**
084       * Returns the string representation of this operand.
085       *
086       * @return a string representation of this operand.
087       */
088      public String toString() {
089        return "code \"" + value + "\"";
090      }
091    }