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.classloader.TypeReference;
016 import org.jikesrvm.compilers.opt.util.Bits;
017 import org.jikesrvm.runtime.Statics;
018 import org.vmmagic.unboxed.Offset;
019
020 /**
021 * Represents a constant long operand.
022 *
023 * @see Operand
024 */
025 public final class LongConstantOperand extends ConstantOperand {
026
027 /**
028 * Constant 0, can be copied as convenient
029 */
030 public static final LongConstantOperand zero =
031 new LongConstantOperand(0, Statics.slotAsOffset(Statics.findOrCreateLongSizeLiteral(0)));
032
033 /**
034 * Value of this operand.
035 */
036 public long value;
037
038 /**
039 * Offset in JTOC where this long constant lives. (0 for constants
040 * obtained from constant folding)
041 * //KV: is this field still necessary
042 */
043 public Offset offset;
044
045 /**
046 * Constructs a new long constant operand with the specified value.
047 *
048 * @param v value
049 */
050 public LongConstantOperand(long v) {
051 value = v;
052 offset = Offset.zero();
053 }
054
055 /**
056 * Constructs a new long constant operand with the specified value and JTOC offset.
057 * //KV: is this method still necessary
058 * @param v value
059 * @param i offset in the jtoc
060 */
061 public LongConstantOperand(long v, Offset i) {
062 value = v;
063 offset = i;
064 }
065
066 /**
067 * Return the {@link TypeReference} of the value represented by the operand.
068 *
069 * @return TypeReference.Long
070 */
071 public TypeReference getType() {
072 return TypeReference.Long;
073 }
074
075 /**
076 * Does the operand represent a value of the long data type?
077 *
078 * @return <code>true</code>
079 */
080 public boolean isLong() {
081 return true;
082 }
083
084 /**
085 * Return the lower 32 bits (as an int) of value
086 */
087 public int lower32() {
088 return Bits.lower32(value);
089 }
090
091 /**
092 * Return the upper 32 bits (as an int) of value
093 */
094 public int upper32() {
095 return Bits.upper32(value);
096 }
097
098 /**
099 * Return a new operand that is semantically equivalent to <code>this</code>.
100 *
101 * @return a copy of <code>this</code>
102 */
103 public Operand copy() {
104 return new LongConstantOperand(value, offset);
105 }
106
107 /**
108 * Are two operands semantically equivalent?
109 *
110 * @param op other operand
111 * @return <code>true</code> if <code>this</code> and <code>op</code>
112 * are semantically equivalent or <code>false</code>
113 * if they are not.
114 */
115 public boolean similar(Operand op) {
116 return (op instanceof LongConstantOperand) && (value == ((LongConstantOperand) op).value);
117 }
118
119 /**
120 * Returns the string representation of this operand.
121 *
122 * @return a string representation of this operand.
123 */
124 public String toString() {
125 return Long.toString(value) + "L";
126 }
127
128 }