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 java.util.Arrays;
016/**
017 * An OsrTypeInfoOperand object keeps type information of locals
018 * and stacks at a byte code index.
019 */
020public final class OsrTypeInfoOperand extends Operand {
021
022  /**
023   * The data type.
024   */
025  public byte[] localTypeCodes;
026  public byte[] stackTypeCodes;
027
028  public OsrTypeInfoOperand(byte[] ltcodes, byte[] stcodes) {
029    this.localTypeCodes = ltcodes;
030    this.stackTypeCodes = stcodes;
031  }
032
033  @Override
034  public Operand copy() {
035    return new OsrTypeInfoOperand(localTypeCodes, stackTypeCodes);
036  }
037
038  @Override
039  public boolean similar(Operand op) {
040    boolean result = true;
041
042    if (!(op instanceof OsrTypeInfoOperand)) {
043      return false;
044    }
045
046    OsrTypeInfoOperand other = (OsrTypeInfoOperand) op;
047
048    result =
049        Arrays.equals(this.localTypeCodes, other.localTypeCodes) &&
050        Arrays.equals(this.stackTypeCodes, other.stackTypeCodes);
051
052    return result;
053  }
054
055  /**
056   * Returns the string representation of this operand.
057   *
058   * @return a string representation of this operand.
059   */
060  @Override
061  public String toString() {
062    StringBuilder buf = new StringBuilder("OsrTypeInfo(");
063    for (int i = 0, n = localTypeCodes.length; i < n; i++) {
064      buf.append((char) localTypeCodes[i]);
065    }
066
067    buf.append(",");
068    for (int i = 0, n = stackTypeCodes.length; i < n; i++) {
069      buf.append((char) stackTypeCodes[i]);
070    }
071
072    buf.append(")");
073
074    return buf.toString();
075  }
076}