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.compilers.opt.ir.Instruction;
016 import org.jikesrvm.compilers.opt.ssa.HeapVariable;
017
018 /**
019 * Represents a heap variable for instructions in Heap Array SSA form.
020 *
021 * @see Operand
022 * @see HeapVariable
023 */
024 public final class HeapOperand<T> extends Operand {
025
026 /**
027 * The heap variable corresponding to this operand.
028 */
029 public final HeapVariable<T> value;
030
031 /**
032 * Return the heap variable corresponding to this operand.
033 * @return the heap variable corresponding to this operand.
034 */
035 public HeapVariable<T> getHeapVariable() {
036 return value;
037 }
038
039 /**
040 * Return the number of the heap variable corresponding to this
041 * operand.
042 * @return the number of the heap variable corresponding to this
043 * operand.
044 */
045 public int getNumber() {
046 return value.getNumber();
047 }
048
049 /**
050 * Return the type corresponding to the heap variable associated with
051 * this operand.
052 * @return the type corresponding to the heap variable associated with
053 * this operand.
054 */
055 public T getHeapType() {
056 return value.getHeapType();
057 }
058
059 /**
060 * Construct an operand corresponding to a heap variable.
061 * @param heap the heap variable corresponding to this operand.
062 */
063 public HeapOperand(HeapVariable<T> heap) {
064 value = heap;
065 }
066
067 /**
068 * Construct a new heap operand associated with the same heap variable as
069 * this operand
070 *
071 * @return a new heap operand associated with the same heap variable as
072 * this operand
073 */
074 public HeapOperand<T> copy() {
075 return new HeapOperand<T>(value);
076 }
077
078 /**
079 * Does this operand correspond to the same heap variable as another
080 * heap operand?
081 *
082 * @param op the second operand to compare with
083 * @return true or false
084 */
085 public boolean similar(Operand op) {
086 if (!(op instanceof HeapOperand<?>)) {
087 return false;
088 }
089 HeapOperand<?> h = (HeapOperand<?>) op;
090 return (h.value == value);
091 }
092
093 /**
094 * Return a string representation of this operand.
095 * @return a string representation of this operand.
096 */
097 public String toString() {
098 return value.toString();
099 }
100
101 /**
102 * Associate this operand with a given instruction.
103 * @param s the associated instruction
104 */
105 public void setInstruction(Instruction s) {
106 this.instruction = s;
107 }
108
109 /**
110 * Return the instruction associated with this operand.
111 * @return the instruction associated with this operand.
112 */
113 public Instruction getInstruction() {
114 return instruction;
115 }
116 }