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.classloader.TypeReference;
016import org.jikesrvm.util.Bits;
017
018/**
019 * Represents a constant long operand.
020 *
021 * @see Operand
022 */
023public final class LongConstantOperand extends ConstantOperand {
024
025  /**
026   * Constant 0, can be copied as convenient
027   */
028  public static final LongConstantOperand zero =
029    new LongConstantOperand(0);
030
031  /**
032   * Value of this operand.
033   */
034  public long value;
035
036  /**
037   * Converted from a reference?
038   */
039  private boolean convertedFromRef;
040
041  /**
042   * Constructs a new long constant operand with the specified value.
043   *
044   * @param v value
045   */
046  public LongConstantOperand(long v) {
047    value = v;
048  }
049
050  public LongConstantOperand(long v, boolean convertedFromRef) {
051    this(v);
052    this.convertedFromRef = convertedFromRef;
053  }
054
055  /**
056   * @return {@link TypeReference#Long}
057   */
058  @Override
059  public TypeReference getType() {
060    return TypeReference.Long;
061  }
062
063  /**
064   * @return <code>true</code>
065   */
066  @Override
067  public boolean isLong() {
068    return true;
069  }
070
071  /**
072   * @return the lower 32 bits (as an int) of value
073   */
074  public int lower32() {
075    return Bits.lower32(value);
076  }
077  /**
078   * @return the upper 32 bits (as an int) of value
079   */
080  public int upper32() {
081    return Bits.upper32(value);
082  }
083
084  /**
085   * @return whether the operand was converted from a reference type
086   */
087  public boolean convertedFromRef() {
088    return convertedFromRef;
089  }
090
091  @Override
092  public Operand copy() {
093    return new LongConstantOperand(value);
094  }
095
096  @Override
097  public boolean similar(Operand op) {
098    return (op instanceof LongConstantOperand) && (value == ((LongConstantOperand) op).value);
099  }
100
101  /**
102   * Returns the string representation of this operand.
103   *
104   * @return a string representation of this operand.
105   */
106  @Override
107  public String toString() {
108    return Long.toString(value) + "L";
109  }
110
111}