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