FileDocCategorySizeDatePackage
BasicRegisterMapper.javaAPI DocAndroid 1.5 API3637Wed May 06 22:41:02 BST 2009com.android.dx.ssa

BasicRegisterMapper

public class BasicRegisterMapper extends RegisterMapper
This class maps one register space into another, with each mapping built up individually and added via addMapping()

Fields Summary
private com.android.dx.util.IntList
oldToNew
indexed by old register, containing new name
private int
runningCountNewRegisters
Running count of used registers in new namespace
Constructors Summary
public BasicRegisterMapper(int countOldRegisters)
Creates a new OneToOneRegisterMapper

param
countOldRegisters the number of registers in the old name space

        oldToNew = new IntList(countOldRegisters);
    
Methods Summary
public voidaddMapping(int oldReg, int newReg, int category)
adds a mapping to the mapper. If oldReg has already been mapped, overwrites previous mapping with new mapping.

param
oldReg >=0
param
newReg >=0
param
category width of reg (1 or 2)

        if (oldReg >= oldToNew.size()) {
            // expand the array as necessary
            for (int i = oldReg - oldToNew.size(); i >= 0; i--) {
                oldToNew.add(-1);
            }
        }
        oldToNew.set(oldReg, newReg);

        if (runningCountNewRegisters < (newReg + category)) {
            runningCountNewRegisters = newReg + category;
        }
    
public intgetNewRegisterCount()
{@inheritDoc}

        return runningCountNewRegisters;
    
public com.android.dx.rop.code.RegisterSpecmap(com.android.dx.rop.code.RegisterSpec registerSpec)
{@inheritDoc}

        if (registerSpec == null) {
            return null;
        }

        int newReg;
        try {
            newReg = oldToNew.get(registerSpec.getReg());
        } catch (IndexOutOfBoundsException ex) {
            newReg = -1;
        }

        if (newReg < 0) {
            throw new RuntimeException("no mapping specified for register");
        }

        return registerSpec.withReg(newReg);
    
public intoldToNew(int oldReg)
Returns the new-namespace mapping for the specified old-namespace register, or -1 if one exists

param
oldReg >=0; old-namespace register
return
new-namespace register or -1 if none.

        if(oldReg >= oldToNew.size()) {
            return -1;
        }
        return oldToNew.get(oldReg);
    
public java.lang.StringtoHuman()
{@inheritDoc}

        StringBuilder sb = new StringBuilder();

        sb.append("Old\tNew\n");
        int sz = oldToNew.size();
        for(int i = 0; i < sz; i++) {
            sb.append(i);
            sb.append('\t");
            sb.append(oldToNew.get(i));
            sb.append('\n");
        }

        sb.append("new reg count:");

        sb.append(runningCountNewRegisters);
        sb.append('\n");

        return sb.toString();