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