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.<p>
022     *
023     * NB we don't use an object constant operand
024     * because
025     * <ol>
026     *   <li>code doesn't form part of the object literals
027     *   <li>we need to support replacement
028     * </ol>
029     *
030     * @see Operand
031     */
032    public final class CodeConstantOperand extends ConstantOperand {
033    
034      /**
035       * The non-{@code null} method for the code represent
036       */
037      public final RVMMethod value;
038    
039      /**
040       * Construct a new code constant operand
041       *
042       * @param v the method of this TIB
043       */
044      public CodeConstantOperand(RVMMethod v) {
045        if (VM.VerifyAssertions) VM._assert(v != null);
046        value = v;
047      }
048    
049      @Override
050      public Operand copy() {
051        return new CodeConstantOperand(value);
052      }
053    
054      /**
055       * @return {@link TypeReference#CodeArray}
056       */
057      @Override
058      public TypeReference getType() {
059        return TypeReference.CodeArray;
060      }
061    
062      /**
063       * @return <code>true</code>
064       */
065      @Override
066      public boolean isRef() {
067        return true;
068      }
069    
070      @Override
071      public boolean similar(Operand op) {
072        return (op instanceof CodeConstantOperand) && value == ((CodeConstantOperand) op).value;
073      }
074    
075      /**
076       * Returns the string representation of this operand.
077       *
078       * @return a string representation of this operand.
079       */
080      @Override
081      public String toString() {
082        return "code \"" + value + "\"";
083      }
084    }