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