diff options
Diffstat (limited to 'dx')
5 files changed, 50 insertions, 1 deletions
diff --git a/dx/src/com/android/jack/dx/dex/code/DalvInsn.java b/dx/src/com/android/jack/dx/dex/code/DalvInsn.java index 9dcddd4..0cb8964 100644 --- a/dx/src/com/android/jack/dx/dex/code/DalvInsn.java +++ b/dx/src/com/android/jack/dx/dex/code/DalvInsn.java @@ -19,6 +19,7 @@ package com.android.jack.dx.dex.code; import com.android.jack.dx.rop.code.RegisterSpec; import com.android.jack.dx.rop.code.RegisterSpecList; import com.android.jack.dx.rop.code.SourcePosition; +import com.android.jack.dx.ssa.RegisterMapper; import com.android.jack.dx.util.AnnotatedOutput; import com.android.jack.dx.util.Hex; import com.android.jack.dx.util.TwoColumnOutput; @@ -380,6 +381,17 @@ public abstract class DalvInsn { } /** + * Returns an instance that is just like this one, except that the + * register list is mapped by using {@code mapper}. + * + * @param mapper {@code non-null;} used to map registers + * @return {@code non-null;} an appropriately-constructed instance + */ + public DalvInsn withMapper(RegisterMapper mapper) { + return withRegisters(mapper.map(getRegisters())); + } + + /** * Gets the size of this instruction, in 16-bit code units. * * @return {@code >= 0;} the code size of this instruction diff --git a/dx/src/com/android/jack/dx/dex/code/LocalSnapshot.java b/dx/src/com/android/jack/dx/dex/code/LocalSnapshot.java index d14a9a2..8b87e39 100644 --- a/dx/src/com/android/jack/dx/dex/code/LocalSnapshot.java +++ b/dx/src/com/android/jack/dx/dex/code/LocalSnapshot.java @@ -20,6 +20,7 @@ import com.android.jack.dx.rop.code.RegisterSpec; import com.android.jack.dx.rop.code.RegisterSpecList; import com.android.jack.dx.rop.code.RegisterSpecSet; import com.android.jack.dx.rop.code.SourcePosition; +import com.android.jack.dx.ssa.RegisterMapper; /** * Pseudo-instruction which is used to hold a snapshot of the @@ -93,4 +94,10 @@ public final class LocalSnapshot extends ZeroSizeInsn { return sb.toString(); } + + /** {@inheritDoc} */ + @Override + public DalvInsn withMapper(RegisterMapper mapper) { + return new LocalSnapshot(getPosition(), mapper.map(locals)); + } } diff --git a/dx/src/com/android/jack/dx/dex/code/LocalStart.java b/dx/src/com/android/jack/dx/dex/code/LocalStart.java index 5d5f6ab..60b7577 100644 --- a/dx/src/com/android/jack/dx/dex/code/LocalStart.java +++ b/dx/src/com/android/jack/dx/dex/code/LocalStart.java @@ -19,6 +19,7 @@ package com.android.jack.dx.dex.code; import com.android.jack.dx.rop.code.RegisterSpec; import com.android.jack.dx.rop.code.RegisterSpecList; import com.android.jack.dx.rop.code.SourcePosition; +import com.android.jack.dx.ssa.RegisterMapper; /** * Pseudo-instruction which is used to introduce a new local variable. That @@ -95,4 +96,10 @@ public final class LocalStart extends ZeroSizeInsn { protected String listingString0(boolean noteIndices) { return "local-start " + localString(local); } + + /** {@inheritDoc} */ + @Override + public DalvInsn withMapper(RegisterMapper mapper) { + return new LocalStart(getPosition(), mapper.map(local)); + } } diff --git a/dx/src/com/android/jack/dx/dex/code/OutputFinisher.java b/dx/src/com/android/jack/dx/dex/code/OutputFinisher.java index df18147..8e3cdcd 100644 --- a/dx/src/com/android/jack/dx/dex/code/OutputFinisher.java +++ b/dx/src/com/android/jack/dx/dex/code/OutputFinisher.java @@ -827,7 +827,7 @@ while (guess != null) { // Since there is no need to replace CodeAddress since it does not use registers, skips it to // avoid to update all TargetInsn that contain a reference to CodeAddress if (!(insn instanceof CodeAddress)) { - insns.set(i, insn.withRegisters(mapper.map(insn.getRegisters()))); + insns.set(i, insn.withMapper(mapper)); } } } diff --git a/dx/src/com/android/jack/dx/ssa/RegisterMapper.java b/dx/src/com/android/jack/dx/ssa/RegisterMapper.java index 2807fdb..dda2cf3 100644 --- a/dx/src/com/android/jack/dx/ssa/RegisterMapper.java +++ b/dx/src/com/android/jack/dx/ssa/RegisterMapper.java @@ -18,6 +18,7 @@ package com.android.jack.dx.ssa; import com.android.jack.dx.rop.code.RegisterSpec; import com.android.jack.dx.rop.code.RegisterSpecList; +import com.android.jack.dx.rop.code.RegisterSpecSet; /** * Represents a mapping between two register numbering schemes. @@ -57,4 +58,26 @@ public abstract class RegisterMapper { // Return the old sources if nothing has changed. return newSources.equals(sources) ? sources : newSources; } + + /** + * + * @param sources old register set + * @return new mapped register set, or old if nothing has changed. + */ + public final RegisterSpecSet map(RegisterSpecSet sources) { + int sz = sources.getMaxSize(); + RegisterSpecSet newSources = new RegisterSpecSet(getNewRegisterCount()); + + for (int i = 0; i < sz; i++) { + RegisterSpec registerSpec = sources.get(i); + if (registerSpec != null) { + newSources.put(map(registerSpec)); + } + } + + newSources.setImmutable(); + + // Return the old sources if nothing has changed. + return newSources.equals(sources) ? sources : newSources; + } } |