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.VM; 016 import org.jikesrvm.SizeConstants; 017 import org.jikesrvm.classloader.TypeReference; 018 import org.vmmagic.unboxed.Address; 019 import org.vmmagic.unboxed.Extent; 020 import org.vmmagic.unboxed.Offset; 021 import org.vmmagic.unboxed.Word; 022 023 /** 024 * Represents an address constant operand. 025 * 026 * @see Operand 027 */ 028 public final class AddressConstantOperand extends ConstantOperand { 029 030 /** 031 * Value of this operand. 032 */ 033 public final Address value; 034 035 /** 036 * Constructs a new address constant operand with the specified value. 037 * 038 * @param v value 039 */ 040 public AddressConstantOperand(Address v) { 041 value = v; 042 } 043 044 /** 045 * Constructs a new address constant operand with the specified offset value. 046 * 047 * @param v value 048 * TODO: make a separte OffsetConstantOperand 049 */ 050 public AddressConstantOperand(Offset v) { 051 this(v.toWord().toAddress()); 052 } 053 054 /** 055 * Constructs a new address constant operand with the specified offset value. 056 * 057 * @param v value 058 * TODO: make a separate OffsetConstantOperand 059 */ 060 public AddressConstantOperand(Extent v) { 061 this(v.toWord().toAddress()); 062 } 063 064 /** 065 * Constructs a new address constant operand with the specified offset value. 066 * 067 * @param v value 068 * TODO: make a separate OffsetConstantOperand 069 */ 070 public AddressConstantOperand(Word v) { 071 this(v.toAddress()); 072 } 073 074 @Override 075 public Operand copy() { 076 return new AddressConstantOperand(value); 077 } 078 079 /** 080 * @return {@link TypeReference#Address} 081 */ 082 @Override 083 public TypeReference getType() { 084 return TypeReference.Address; 085 } 086 087 /** 088 * @return <code>true</code> 089 */ 090 @Override 091 public boolean isAddress() { 092 return true; 093 } 094 095 @Override 096 public boolean similar(Operand op) { 097 return equals(op); 098 } 099 100 @Override 101 public boolean equals(Object o) { 102 return (o instanceof AddressConstantOperand) && (value.EQ(((AddressConstantOperand) o).value)); 103 } 104 105 @Override 106 public int hashCode() { 107 return value.toWord().rshl(SizeConstants.LOG_BYTES_IN_ADDRESS).toInt(); 108 } 109 110 /** 111 * Returns the string representation of this operand. 112 * 113 * @return a string representation of this operand. 114 */ 115 @Override 116 public String toString() { 117 return "Addr " + VM.addressAsHexString(value); 118 } 119 }