PostInstructionRegisterInfoMethodItem.java revision 754b3c4dc009b7a02e39001560c3f0fd6a7cc2c0
1/* 2 * [The "BSD licence"] 3 * Copyright (c) 2010 Ben Gruver 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29package org.jf.baksmali.Adaptors; 30 31import org.jf.util.IndentingWriter; 32import org.jf.baksmali.baksmali; 33import org.jf.baksmali.main; 34import org.jf.dexlib.ClassDataItem; 35import org.jf.dexlib.Code.Analysis.AnalyzedInstruction; 36import org.jf.dexlib.Code.Analysis.MethodAnalyzer; 37import org.jf.dexlib.Code.Analysis.RegisterType; 38 39import java.io.IOException; 40import java.util.BitSet; 41 42//TODO: uncomment 43/*public class PostInstructionRegisterInfoMethodItem extends MethodItem { 44 private final AnalyzedInstruction analyzedInstruction; 45 private final MethodAnalyzer methodAnalyzer; 46 47 public PostInstructionRegisterInfoMethodItem(AnalyzedInstruction analyzedInstruction, MethodAnalyzer methodAnalyzer, 48 int codeAddress) { 49 super(codeAddress); 50 this.analyzedInstruction = analyzedInstruction; 51 this.methodAnalyzer = methodAnalyzer; 52 } 53 54 @Override 55 public double getSortOrder() { 56 return 100.1; 57 } 58 59 @Override 60 public boolean writeTo(IndentingWriter writer) throws IOException { 61 int registerInfo = baksmali.registerInfo; 62 int registerCount = analyzedInstruction.getRegisterCount(); 63 BitSet registers = new BitSet(registerCount); 64 65 if ((registerInfo & main.ALL) != 0) { 66 registers.set(0, registerCount); 67 } else { 68 if ((registerInfo & main.ALLPOST) != 0) { 69 registers.set(0, registerCount); 70 } else if ((registerInfo & main.DEST) != 0) { 71 addDestRegs(registers, registerCount); 72 } 73 } 74 75 return writeRegisterInfo(writer, registers); 76 } 77 78 private void addDestRegs(BitSet printPostRegister, int registerCount) { 79 for (int registerNum=0; registerNum<registerCount; registerNum++) { 80 if (analyzedInstruction.getPreInstructionRegisterType(registerNum) != 81 analyzedInstruction.getPostInstructionRegisterType(registerNum)) { 82 printPostRegister.set(registerNum); 83 } 84 } 85 } 86 87 private boolean writeRegisterInfo(IndentingWriter writer, BitSet registers) throws IOException { 88 ClassDataItem.EncodedMethod encodedMethod = methodAnalyzer.getMethod(); 89 90 int registerNum = registers.nextSetBit(0); 91 if (registerNum < 0) { 92 return false; 93 } 94 95 writer.write('#'); 96 for (; registerNum >= 0; registerNum = registers.nextSetBit(registerNum + 1)) { 97 98 RegisterType registerType = analyzedInstruction.getPostInstructionRegisterType(registerNum); 99 100 RegisterFormatter.writeTo(writer, encodedMethod.codeItem, registerNum); 101 writer.write('='); 102 103 if (registerType == null) { 104 writer.write("null"); 105 } else { 106 registerType.writeTo(writer); 107 } 108 writer.write(';'); 109 } 110 return true; 111 } 112}*/ 113