Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * fb-contrib - Auxiliary detectors for Java programs
   * Copyright (C) 2005-2015 Dave Brosius
   * 
   * 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
  */
 package com.mebigfatguy.fbcontrib.utils;
 
 
an auxiliary class for managing and manipulating registers
 
 public class RegisterUtils {

private to reinforce the helper status of the class
 
 	private RegisterUtils() {		
 	}

    
returns the register used to store a reference

Parameters:
dbc the dismantle byte code parsing the class
seen the opcode of the store
Returns:
the register stored into
 
     public static int getAStoreReg(final DismantleBytecode dbcfinal int seen) {
         if (seen == .)
             return dbc.getRegisterOperand();
         if ((seen >= .) && (seen <= .))
         	return seen - .;
         return -1;
     }
    
    
returns the register used to load a reference

Parameters:
dbc the dismantle byte code parsing the class
seen the opcode of the load
Returns:
the register loaded from
  
     public static int getALoadReg(DismantleBytecode dbcint seen) {
         if (seen == .)
             return dbc.getRegisterOperand();
         if ((seen >= .) && (seen <= .))
         	return seen - .;
         return -1;
     }  
    
    
returns the register used in a store operation

Parameters:
dbc the dismantle byte code parsing the class
seen the opcode of the store
Returns:
the register stored into
 
 	public static int getStoreReg(DismantleBytecode dbcint seen) {
 		if ((seen == .
 		||  (seen == .
 		||  (seen == .
 		||  (seen == .
 		||  (seen == .))
 			return dbc.getRegisterOperand(); 
 		if ((seen >= .) && (seen <= .))
 			return seen - .;
 		else if (seen <= .)
 			return seen - .;
 		else if (seen <= .)
 			return seen - .;
 		else if (seen <= .)
 			return seen - .;
 		else if (seen <= .)
 			return seen - .;
 		return -1;
 	}

    
returns the register used in a load operation

Parameters:
dbc the dismantle byte code parsing the class
seen the opcode of the load
Returns:
the register stored into
	public static int getLoadReg(DismantleBytecode dbcint seen) {
		if ((seen == .
		||  (seen == .
		||  (seen == .
		||  (seen == .
		||  (seen == .))
			return dbc.getRegisterOperand();
		if ((seen >= .) && (seen <= .))
			return seen - .;
		else if (seen <= .)
			return seen - .;
		else if (seen <= .)
			return seen - .;
		else if (seen <= .)
			return seen - .;
		else if (seen <= .)
			return seen - .;
		return -1;
	}

    
returns the end pc of the visible range of this register at this pc

Parameters:
lvt the local variable table for this method
reg the register to examine
curPC the pc of the current instruction
Returns:
the endpc
    public static int getLocalVariableEndRange(LocalVariableTable lvtint regint curPC) {
        int endRange = .;
        if (lvt != null) {
            LocalVariable lv = lvt.getLocalVariable(regcurPC);
            if (lv != null)
                endRange = lv.getStartPC() + lv.getLength();
        }
        return endRange;
    }
    
    
gets the set of registers used for parameters

Parameters:
obj the context object for the method to find the parameter registers of
Returns:
the set of registers that parameters are using
    public static int[] getParameterRegisters(Method obj) {
	    Type[] argTypes = obj.getArgumentTypes();
    	int[] regs = new int[argTypes.length];
    	
    	int curReg = obj.isStatic() ? 0 : 1;
    	for (int t = 0; t < argTypes.lengtht++) {
            String sig = argTypes[t].getSignature();
            regs[t] = curReg;
            if ("J".equals(sig) || "D".equals(sig))
                curReg++;
            curReg++;    	
        }
    	return regs;
    }
New to GrepCode? Check out our FAQ X