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 * <pre> 022 * VariableMap ---> LinkedList of VariableMapElement 023 * VariableMapElement ---> (OsrPoint, LinkedList of MethodVariables) 024 * MethodVariables ---> (Method, PC, List of LocalRegTuple) 025 * LocalRegTuple ---> ( LocalNum, regOp, Type ) or ( StackNum, regOp, Type ) 026 * </pre> 027 * * 028 */ 029 public 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 public void insertFirst(Instruction inst, LinkedList<MethodVariables> mvarList) { 052 list.addFirst(new VariableMapElement(inst, mvarList)); 053 } 054 055 /** 056 * Creates and returns an enumerator for this object 057 * @return an iterator for this object 058 */ 059 public ListIterator<VariableMapElement> iterator() { 060 return list.listIterator(0); 061 } 062 063 /** 064 * @return string version of this object 065 */ 066 @Override 067 public String toString() { 068 StringBuilder buf = new StringBuilder(""); 069 070 if (list.isEmpty()) { 071 buf.append("empty"); 072 } else { 073 for (VariableMapElement ptr : list) { 074 buf.append(ptr.toString()); 075 } 076 } 077 return buf.toString(); 078 } 079 } 080 081 082