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.osr;
014
015import java.util.LinkedList;
016import java.util.ListIterator;
017import org.jikesrvm.compilers.opt.ir.Instruction;
018
019/**
020 * VariableMap, non-encoded yet
021 * <pre>
022 * VariableMap          ---&gt; LinkedList of VariableMapElement
023 * VariableMapElement   ---&gt; (OsrPoint, LinkedList of MethodVariables)
024 * MethodVariables      ---&gt; (Method, PC, List of LocalRegTuple)
025 * LocalRegTuple   ---&gt; ( LocalNum, regOp, Type ) or ( StackNum, regOp, Type )
026 * </pre>
027 * *
028 */
029public final class VariableMap {
030
031  /* A list of VariableMapElement */
032  public final LinkedList<VariableMapElement> list = new LinkedList<VariableMapElement>();
033
034  public int getNumberOfElements() {
035    return list.size();
036  }
037
038  /**
039   * Inserts a new entry into the GCIRMap
040   * @param inst      the IR instruction we care about
041   * @param mvarList  the set of symbolic registers as a list
042   */
043  public void insert(Instruction inst, LinkedList<MethodVariables> mvarList) {
044    // make a VariableMapElement and put it on the big list
045    list.add(new VariableMapElement(inst, mvarList));
046  }
047
048  /**
049   * Inserts a new entry at the begin of the list.
050   *
051   * @param inst      the IR instruction we care about
052   * @param mvarList  the set of symbolic registers as a list
053   */
054  public void insertFirst(Instruction inst, LinkedList<MethodVariables> mvarList) {
055    list.addFirst(new VariableMapElement(inst, mvarList));
056  }
057
058  /**
059   * Creates and returns an enumerator for this object
060   * @return an iterator for this object
061   */
062  public ListIterator<VariableMapElement> iterator() {
063    return list.listIterator(0);
064  }
065
066  /**
067   * @return string version of this object
068   */
069  @Override
070  public String toString() {
071    StringBuilder buf = new StringBuilder();
072
073    if (list.isEmpty()) {
074      buf.append("empty");
075    } else {
076      for (VariableMapElement ptr : list) {
077        buf.append(ptr.toString());
078      }
079    }
080    return buf.toString();
081  }
082}