FileDocCategorySizeDatePackage
BasicRegisterMapper.javaAPI DocAndroid 5.1 API3649Thu Mar 12 22:18:30 GMT 2015com.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 {@code >= 0;} old register
param
newReg {@code >= 0;} new register
param
category {@code 1..2;} width of reg

        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 {@code >= 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();