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