📄 processor.java
字号:
/* $Id: Processor.java,v 1.12 2004/12/11 16:35:23 eric Exp $ * * ProGuard -- shrinking, optimization, and obfuscation of Java class files. * * Copyright (c) 2002-2004 Eric Lafortune (eric@graphics.cornell.edu) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program 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 General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package proguard.optimize.evaluation;import proguard.classfile.*;import proguard.classfile.attribute.*;import proguard.classfile.instruction.*;import proguard.classfile.util.ClassUtil;import proguard.classfile.visitor.*;import proguard.optimize.evaluation.value.*;/** * This InstructionVisitor executes the instructions that it visits on a given * local variable frame and stack. * * @author Eric Lafortune */public class Processorimplements InstructionVisitor, CpInfoVisitor{ private Variables variables; private Stack stack; private BranchUnit branchUnit; // Fields acting as return parameters for the CpInfoVisitor methods. private int parameterCount; private Value cpValue; private ClassFile referencedClassFile; private int referencedTypeDimensionCount; /** * Creates a new processor that operates on the given environment. * @param variables the local variable frame. * @param stack the local stack. * @param branchUnit the class that can affect the program counter. */ public Processor(Variables variables, Stack stack, BranchUnit branchUnit) { this.variables = variables; this.stack = stack; this.branchUnit = branchUnit; } // Implementations for InstructionVisitor. public void visitSimpleInstruction(ClassFile classFile, MethodInfo methodInfo, CodeAttrInfo codeAttrInfo, int offset, SimpleInstruction simpleInstruction) { switch (simpleInstruction.opcode) { case InstructionConstants.OP_NOP: break; case InstructionConstants.OP_ACONST_NULL: stack.push(ReferenceValueFactory.createNull()); break; case InstructionConstants.OP_ICONST_M1: case InstructionConstants.OP_ICONST_0: case InstructionConstants.OP_ICONST_1: case InstructionConstants.OP_ICONST_2: case InstructionConstants.OP_ICONST_3: case InstructionConstants.OP_ICONST_4: case InstructionConstants.OP_ICONST_5: case InstructionConstants.OP_BIPUSH: case InstructionConstants.OP_SIPUSH: stack.push(IntegerValueFactory.create(simpleInstruction.constant)); break; case InstructionConstants.OP_LCONST_0: case InstructionConstants.OP_LCONST_1: stack.push(LongValueFactory.create(simpleInstruction.constant)); break; case InstructionConstants.OP_FCONST_0: case InstructionConstants.OP_FCONST_1: case InstructionConstants.OP_FCONST_2: stack.push(FloatValueFactory.create((float)simpleInstruction.constant)); break; case InstructionConstants.OP_DCONST_0: case InstructionConstants.OP_DCONST_1: stack.push(DoubleValueFactory.create((double)simpleInstruction.constant)); break; case InstructionConstants.OP_IALOAD: case InstructionConstants.OP_BALOAD: case InstructionConstants.OP_CALOAD: case InstructionConstants.OP_SALOAD: stack.ipop(); stack.apop(); stack.push(IntegerValueFactory.create()); break; case InstructionConstants.OP_LALOAD: stack.ipop(); stack.apop(); stack.push(LongValueFactory.create()); break; case InstructionConstants.OP_FALOAD: stack.ipop(); stack.apop(); stack.push(FloatValueFactory.create()); break; case InstructionConstants.OP_DALOAD: stack.ipop(); stack.apop(); stack.push(DoubleValueFactory.create()); break; case InstructionConstants.OP_AALOAD: stack.ipop(); stack.apop(); stack.push(ReferenceValueFactory.create(true)); break; case InstructionConstants.OP_IASTORE: case InstructionConstants.OP_BASTORE: case InstructionConstants.OP_CASTORE: case InstructionConstants.OP_SASTORE: stack.ipop(); stack.ipop(); stack.apop(); break; case InstructionConstants.OP_LASTORE: stack.lpop(); stack.ipop(); stack.apop(); break; case InstructionConstants.OP_FASTORE: stack.fpop(); stack.ipop(); stack.apop(); break; case InstructionConstants.OP_DASTORE: stack.dpop(); stack.ipop(); stack.apop(); break; case InstructionConstants.OP_AASTORE: stack.apop(); stack.ipop(); stack.apop(); break; case InstructionConstants.OP_POP: stack.pop1(); break; case InstructionConstants.OP_POP2: stack.pop2(); break; case InstructionConstants.OP_DUP: stack.dup(); break; case InstructionConstants.OP_DUP_X1: stack.dup_x1(); break; case InstructionConstants.OP_DUP_X2: stack.dup_x2(); break; case InstructionConstants.OP_DUP2: stack.dup2(); break; case InstructionConstants.OP_DUP2_X1: stack.dup2_x1(); break; case InstructionConstants.OP_DUP2_X2: stack.dup2_x2(); break; case InstructionConstants.OP_SWAP: stack.swap(); break; case InstructionConstants.OP_IADD: stack.push(stack.ipop().add(stack.ipop())); break; case InstructionConstants.OP_LADD: stack.push(stack.lpop().add(stack.lpop())); break; case InstructionConstants.OP_FADD: stack.push(stack.fpop().add(stack.fpop())); break; case InstructionConstants.OP_DADD: stack.push(stack.dpop().add(stack.dpop())); break; case InstructionConstants.OP_ISUB: stack.push(stack.ipop().subtractFrom(stack.ipop())); break; case InstructionConstants.OP_LSUB: stack.push(stack.lpop().subtractFrom(stack.lpop())); break; case InstructionConstants.OP_FSUB: stack.push(stack.fpop().subtractFrom(stack.fpop())); break; case InstructionConstants.OP_DSUB: stack.push(stack.dpop().subtractFrom(stack.dpop())); break; case InstructionConstants.OP_IMUL: stack.push(stack.ipop().multiply(stack.ipop())); break; case InstructionConstants.OP_LMUL: stack.push(stack.lpop().multiply(stack.lpop())); break; case InstructionConstants.OP_FMUL: stack.push(stack.fpop().multiply(stack.fpop())); break; case InstructionConstants.OP_DMUL: stack.push(stack.dpop().multiply(stack.dpop())); break; case InstructionConstants.OP_IDIV: try { stack.push(stack.ipop().divideOf(stack.ipop())); } catch (ArithmeticException ex) { stack.push(IntegerValueFactory.create()); // TODO: Forward ArithmeticExceptions. //stack.clear(); //stack.push(ReferenceValueFactory.create(false)); //branchUnit.throwException(); } break; case InstructionConstants.OP_LDIV: stack.push(stack.lpop().divideOf(stack.lpop())); break; case InstructionConstants.OP_FDIV: stack.push(stack.fpop().divideOf(stack.fpop())); break; case InstructionConstants.OP_DDIV: stack.push(stack.dpop().divideOf(stack.dpop())); break; case InstructionConstants.OP_IREM: try { stack.push(stack.ipop().remainderOf(stack.ipop())); } catch (ArithmeticException ex) { stack.push(IntegerValueFactory.create()); // TODO: Forward ArithmeticExceptions. //stack.clear(); //stack.push(ReferenceValueFactory.create(false)); //branchUnit.throwException(); } break; case InstructionConstants.OP_LREM: stack.push(stack.lpop().remainderOf(stack.lpop())); break; case InstructionConstants.OP_FREM: stack.push(stack.fpop().remainderOf(stack.fpop())); break; case InstructionConstants.OP_DREM: stack.push(stack.dpop().remainderOf(stack.dpop())); break; case InstructionConstants.OP_INEG: stack.push(stack.ipop().negate()); break; case InstructionConstants.OP_LNEG: stack.push(stack.lpop().negate()); break; case InstructionConstants.OP_FNEG: stack.push(stack.fpop().negate()); break; case InstructionConstants.OP_DNEG: stack.push(stack.dpop().negate()); break; case InstructionConstants.OP_ISHL: stack.push(stack.ipop().shiftLeftOf(stack.ipop())); break; case InstructionConstants.OP_LSHL: stack.push(stack.ipop().shiftLeftOf(stack.lpop()));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -