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.SizeConstants; 016 import org.jikesrvm.classloader.TypeReference; 017 import org.jikesrvm.runtime.Entrypoints; 018 import org.vmmagic.unboxed.Offset; 019 020 /** 021 * Represents a constant double operand. 022 * 023 * @see Operand 024 */ 025 public final class DoubleConstantOperand extends ConstantOperand implements SizeConstants { 026 027 /** 028 * Value of this operand. 029 */ 030 public double value; 031 032 /** 033 * Offset in JTOC where this double constant lives. (0 for constants 034 * obtained from constant folding) 035 */ 036 public Offset offset; 037 038 /** 039 * Constructs a new double constant operand with the specified value. 040 * 041 * @param v value 042 */ 043 public DoubleConstantOperand(double v) { 044 value = v; 045 if (v == 0.) { 046 offset = Entrypoints.zeroDoubleField.getOffset(); 047 } else if (v == 1.) { 048 offset = Entrypoints.oneDoubleField.getOffset(); 049 } else { 050 offset = Offset.zero(); 051 } 052 } 053 054 /** 055 * Constructs a new double constant operand with the specified value and JTOC offset. 056 * 057 * @param v value 058 * @param i offset in the jtoc 059 */ 060 public DoubleConstantOperand(double v, Offset i) { 061 value = v; 062 offset = i; 063 } 064 065 @Override 066 public Operand copy() { 067 return new DoubleConstantOperand(value, offset); 068 } 069 070 /** 071 * @return {@link TypeReference#Double} 072 */ 073 @Override 074 public TypeReference getType() { 075 return TypeReference.Double; 076 } 077 078 /** 079 * @return <code>true</code> 080 */ 081 @Override 082 public boolean isDouble() { 083 return true; 084 } 085 086 @Override 087 public boolean similar(Operand op) { 088 return (op instanceof DoubleConstantOperand) && (value == ((DoubleConstantOperand) op).value); 089 } 090 091 /** 092 * Returns the string representation of this operand. 093 * 094 * @return a string representation of this operand. 095 */ 096 @Override 097 public String toString() { 098 return Double.toString(value) + "D"; 099 } 100 101 }