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