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 * TODO 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 * TODO is this constructor 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 {@link TypeReference#Long} 068 */ 069 @Override 070 public TypeReference getType() { 071 return TypeReference.Long; 072 } 073 074 /** 075 * @return <code>true</code> 076 */ 077 @Override 078 public boolean isLong() { 079 return true; 080 } 081 082 /** 083 * Return the lower 32 bits (as an int) of value 084 */ 085 public int lower32() { 086 return Bits.lower32(value); 087 } 088 089 /** 090 * Return the upper 32 bits (as an int) of value 091 */ 092 public int upper32() { 093 return Bits.upper32(value); 094 } 095 096 @Override 097 public Operand copy() { 098 return new LongConstantOperand(value, offset); 099 } 100 101 @Override 102 public boolean similar(Operand op) { 103 return (op instanceof LongConstantOperand) && (value == ((LongConstantOperand) op).value); 104 } 105 106 /** 107 * Returns the string representation of this operand. 108 * 109 * @return a string representation of this operand. 110 */ 111 @Override 112 public String toString() { 113 return Long.toString(value) + "L"; 114 } 115 116 }