gt:                         localToSlot.put(l, new Integer(slot));
context: /* Soot - a J*va Optimization Framework
   * Copyright (C) 1997-1999 Raja Vallee-Rai
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
   * This library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this library; if not, write to the
   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   * Boston, MA 02111-1307, USA.
   */
  
  /*
   * Modified by the Sable Research Group and others 1997-1999.  
   * See the 'credits' file distributed with Soot for the complete list of
   * contributors.  (Soot is distributed at http://www.sable.mcgill.ca/soot)
   */
  
  
  package soot.jimple;
  import soot.options.*;
  import soot.*;
  import soot.jimple.internal.*;
  import soot.toolkits.graph.*;
  import soot.toolkits.scalar.*;
  import soot.util.*;
  import java.util.*;
  import soot.grimp.*;
  
  /** Methods for producing Jasmin code from Jimple. */
  public class JasminClass extends AbstractJasminClass
  {
      void emit(String s, int stackChange)
      {
          modifyStackHeight(stackChange);        
          okayEmit(s);
      }
      
      void modifyStackHeight(int stackChange)
      {
          if(currentStackHeight > maxStackHeight)
              maxStackHeight = currentStackHeight;
  
          currentStackHeight += stackChange;
          
          if(currentStackHeight < 0)
              throw new RuntimeException("Stack height is negative!");
              
          if(currentStackHeight > maxStackHeight)
              maxStackHeight = currentStackHeight;
      }
      
      public JasminClass(SootClass sootClass)
      {
          super(sootClass);
      }
  
      protected void assignColorsToLocals(Body body)
      {
          super.assignColorsToLocals(body);
          
          // Call the graph colorer.
              FastColorer.assignColorsToLocals(body, localToGroup,
                  localToColor, groupToColorCount);
  
          if(Options.v().time())
              Timers.v().packTimer.end();
                      
      }
      
      
      protected void emitMethodBody(SootMethod method)//, Map options)
      {
          if(Options.v().time())
              Timers.v().buildJasminTimer.end();
                      
       
          Body activeBody = method.getActiveBody();
          
          if(!(activeBody instanceof StmtBody))
              throw new RuntimeException("method: " + method.getName() + " has an invalid active body!");
          
          StmtBody body = (StmtBody) activeBody;
          
          body.validate();
              
          if(body == null)
              
          if(Options.v().time())
              Timers.v().buildJasminTimer.start();
          
          Chain units = body.getUnits();
  
          ExceptionalUnitGraph stmtGraph = null;
          LocalDefs ld = null;
          LocalUses lu = null;
  
          
          // let's create a u-d web for the ++ peephole optimization.
  
          if(Options.v().verbose())
              G.v().out.println("[" + body.getMethod().getName() +
                  "] Performing peephole optimizations...");
  
          //boolean disablePeephole = PhaseOptions.getBoolean(options, "no-peephole");
          boolean disablePeephole = true;
  
          if (!disablePeephole)
          {
              stmtGraph = new ExceptionalUnitGraph(body);
              ld = new SmartLocalDefs(stmtGraph, new SimpleLiveLocals(stmtGraph));
              lu = new SimpleLocalUses(stmtGraph, ld);
          }
  
          int stackLimitIndex = -1;
          
          subroutineToReturnAddressSlot = new HashMap<Unit, Integer>(10, 0.7f);
  
          // Determine the unitToLabel map
          {
              Iterator boxIt = body.getUnitBoxes(true).iterator();
  
              unitToLabel = new HashMap(units.size() * 2 + 1, 0.7f);
              labelCount = 0;
  
              while(boxIt.hasNext())
              {
                  // Assign a label for each statement reference
                  {
                      StmtBox box = (StmtBox) boxIt.next();
  
                      if(!unitToLabel.containsKey(box.getUnit()))
                          unitToLabel.put(box.getUnit(), "label" + labelCount++);
                  }
              }
          }
  
          // Emit the exceptions
          {
              Iterator trapIt = body.getTraps().iterator();
  
              while(trapIt.hasNext())
              {
                  Trap trap = (Trap) trapIt.next();
  
                  if(trap.getBeginUnit() != trap.getEndUnit())
                      emit(".catch " + slashify(trap.getException().getName()) + " from " +
                          unitToLabel.get(trap.getBeginUnit()) + " to " + unitToLabel.get(trap.getEndUnit()) +
                          " using " + unitToLabel.get(trap.getHandlerUnit()));
              }
          }
  
          // Determine where the locals go
          {
              int localCount = 0;
              int[] paramSlots = new int[method.getParameterCount()];
              int thisSlot = 0;
              Set<Local> assignedLocals = new HashSet<Local>();
              Map<GroupIntPair, Integer> groupColorPairToSlot = new HashMap<GroupIntPair, Integer>(body.getLocalCount() * 2 + 1, 0.7f);
              
              localToSlot = new HashMap<Local, Integer>(body.getLocalCount() * 2 + 1, 0.7f);
  
              assignColorsToLocals(body);
              
              // Determine slots for 'this' and parameters
              {
                  List paramTypes = method.getParameterTypes();
  
                  if(!method.isStatic())
                  {
                      thisSlot = 0;
                      localCount++;
                  }
  
                  for(int i = 0; i < paramTypes.size(); i++)
                  {
                      paramSlots[i] = localCount;
                      localCount += sizeOfType((Type) paramTypes.get(i));
                  }
              }
  
              // Handle identity statements
              {
                  Iterator stmtIt = units.iterator();
  
                  while(stmtIt.hasNext())
                  {
                      Stmt s = (Stmt) stmtIt.next();
  
                      if(s instanceof IdentityStmt && ((IdentityStmt) s).getLeftOp() instanceof Local)
                      {
                          Local l = (Local) ((IdentityStmt) s).getLeftOp();
                          IdentityRef identity = (IdentityRef) ((IdentityStmt) s).getRightOp();
  
                          int slot = 0;
                                                  
                          if(identity instanceof ThisRef)
                          {
                              if(method.isStatic())
                                  throw new RuntimeException("Attempting to use 'this' in static method");
  
                              slot = thisSlot;
                          }
                          else if(identity instanceof ParameterRef)
                              slot = paramSlots[((ParameterRef) identity).getIndex()];
                          else {
                              // Exception ref.  Skip over this
                              continue;
                          }
                          
                          // Make this (group, color) point to the given slot,
                          // so that all locals of the same color can be pointed here too
                          {
                              
                              GroupIntPair pair = new GroupIntPair(localToGroup.get(l), 
                                  localToColor.get(l).intValue());
                                  
                              groupColorPairToSlot.put(pair, new Integer(slot));
                          }
                              
  