From 19f90d0d3297e61f19d0dea5efa4376fa9f10ff4 Mon Sep 17 00:00:00 2001 From: iga Date: Thu, 3 Apr 2014 21:48:16 +0900 Subject: [PATCH] save --- jcfa/src/jp/igapyon/jcfa/util/JcfaWriteUtil.java | 283 +++++++++++++++++---- .../output/test/TestJavaClass001.jcfa | 4 +- .../output/test/TestJavaClass011.jcfa | 4 +- 3 files changed, 243 insertions(+), 48 deletions(-) diff --git a/jcfa/src/jp/igapyon/jcfa/util/JcfaWriteUtil.java b/jcfa/src/jp/igapyon/jcfa/util/JcfaWriteUtil.java index 6c5d8fe..73c6e25 100644 --- a/jcfa/src/jp/igapyon/jcfa/util/JcfaWriteUtil.java +++ b/jcfa/src/jp/igapyon/jcfa/util/JcfaWriteUtil.java @@ -139,29 +139,24 @@ public class JcfaWriteUtil { final JavaClass jc = jcfaCode.getJavaClass(); switch (jcfaCode.getOpcode()) { - case Constants.ALOAD_0: { - final JcfaItemLocalVariable osLocalVariable = new JcfaItemLocalVariable(); - jcfaMethod.getFrame().getOperandStack().push(osLocalVariable); - osLocalVariable.setLocalVariable(jcfaMethod.getFrame() - .getLocalVariableList().get(0)); - - jcfaCode.getComment().getCommentList() - .add(osLocalVariable.getLocalVariable().getName()); - - break; - } - case Constants.RETURN: { - break; - } - case Constants.GETSTATIC: { - final JcfaItemReference osRef = new JcfaItemReference(); - jcfaMethod.getFrame().getOperandStack().push(osRef); - osRef.setObject(JcfaUtil.getConstantFieldrefString(jc, - codes[1], codes[2])); - - jcfaCode.getComment().getCommentList().add(osRef.getObject()); - break; - } + case Constants.NOP: + case Constants.ACONST_NULL: + case Constants.ICONST_M1: + case Constants.ICONST_0: + case Constants.ICONST_1: + case Constants.ICONST_2: + case Constants.ICONST_3: + case Constants.ICONST_4: + case Constants.ICONST_5: + case Constants.LCONST_0: + case Constants.LCONST_1: + case Constants.FCONST_0: + case Constants.FCONST_1: + case Constants.FCONST_2: + case Constants.DCONST_0: + case Constants.DCONST_1: + case Constants.BIPUSH: + case Constants.SIPUSH: case Constants.LDC: { final JcfaItemReference osString = new JcfaItemReference(); jcfaMethod.getFrame().getOperandStack().push(osString); @@ -169,32 +164,171 @@ public class JcfaWriteUtil { jcfaCode.getComment().getCommentList() .add(osString.getObject()); - } break; - case Constants.INVOKEVIRTUAL: - case Constants.INVOKESPECIAL: { - final int operand = JcfaUtil.byte2UnsignedShort(codes[1], - codes[2]); - jcfaCode.getComment().getCommentList() - .add(JcfaUtil.getConstantMethodRefString(jc, operand)); + } + case Constants.LDC_W: + case Constants.LDC2_W: + case Constants.ILOAD: + case Constants.LLOAD: + case Constants.FLOAD: + case Constants.DLOAD: + case Constants.ALOAD: { + final JcfaItemLocalVariable osLocalVariable = new JcfaItemLocalVariable(); + jcfaMethod.getFrame().getOperandStack().push(osLocalVariable); + osLocalVariable.setLocalVariable(jcfaMethod.getFrame() + .getLocalVariableList().get(0)); jcfaCode.getComment().getCommentList() - .add("TODO get args count from signature."); - // get n args. - final JcfaItem osNodeArg0 = jcfaMethod.getFrame() - .getOperandStack().pop(); - - final JcfaItemReference osRef = (JcfaItemReference) jcfaMethod - .getFrame().getOperandStack().pop(); - - jcfaCode.getComment() - .getCommentList() - .add("" + osRef.getObject() + "#" - + osNodeArg0.toString()); + .add(osLocalVariable.getLocalVariable().getName()); - } break; - case Constants.LOOKUPSWITCH: + } + case Constants.ILOAD_0: + case Constants.ILOAD_1: + case Constants.ILOAD_2: + case Constants.ILOAD_3: + case Constants.LLOAD_0: + case Constants.LLOAD_1: + case Constants.LLOAD_2: + case Constants.LLOAD_3: + case Constants.FLOAD_0: + case Constants.FLOAD_1: + case Constants.FLOAD_2: + case Constants.FLOAD_3: + case Constants.DLOAD_0: + case Constants.DLOAD_1: + case Constants.DLOAD_2: + case Constants.DLOAD_3: + case Constants.ALOAD_0: + case Constants.ALOAD_1: + case Constants.ALOAD_2: + case Constants.ALOAD_3: + case Constants.IALOAD: + case Constants.LALOAD: + case Constants.FALOAD: + case Constants.DALOAD: + case Constants.AALOAD: + case Constants.BALOAD: + case Constants.CALOAD: + case Constants.SALOAD: + case Constants.ISTORE: + case Constants.LSTORE: + case Constants.FSTORE: + case Constants.DSTORE: + case Constants.ASTORE: + case Constants.ISTORE_0: + case Constants.ISTORE_1: + case Constants.ISTORE_2: + case Constants.ISTORE_3: + case Constants.LSTORE_0: + case Constants.LSTORE_1: + case Constants.LSTORE_2: + case Constants.LSTORE_3: + case Constants.FSTORE_0: + case Constants.FSTORE_1: + case Constants.FSTORE_2: + case Constants.FSTORE_3: + case Constants.DSTORE_0: + case Constants.DSTORE_1: + case Constants.DSTORE_2: + case Constants.DSTORE_3: + case Constants.ASTORE_0: + case Constants.ASTORE_1: + case Constants.ASTORE_2: + case Constants.ASTORE_3: + case Constants.IASTORE: + case Constants.LASTORE: + case Constants.FASTORE: + case Constants.DASTORE: + case Constants.AASTORE: + case Constants.BASTORE: + case Constants.CASTORE: + case Constants.SASTORE: + case Constants.POP: + case Constants.POP2: + case Constants.DUP: + case Constants.DUP_X1: + case Constants.DUP_X2: + case Constants.DUP2: + case Constants.DUP2_X1: + case Constants.DUP2_X2: + case Constants.SWAP: + case Constants.IADD: + case Constants.LADD: + case Constants.FADD: + case Constants.DADD: + case Constants.ISUB: + case Constants.LSUB: + case Constants.FSUB: + case Constants.DSUB: + case Constants.IMUL: + case Constants.LMUL: + case Constants.FMUL: + case Constants.DMUL: + case Constants.IDIV: + case Constants.LDIV: + case Constants.FDIV: + case Constants.DDIV: + case Constants.IREM: + case Constants.LREM: + case Constants.FREM: + case Constants.DREM: + case Constants.INEG: + case Constants.LNEG: + case Constants.FNEG: + case Constants.DNEG: + case Constants.ISHL: + case Constants.LSHL: + case Constants.ISHR: + case Constants.LSHR: + case Constants.IUSHR: + case Constants.LUSHR: + case Constants.IAND: + case Constants.LAND: + case Constants.IOR: + case Constants.LOR: + case Constants.IXOR: + case Constants.LXOR: + case Constants.IINC: + case Constants.I2L: + case Constants.I2F: + case Constants.I2D: + case Constants.L2I: + case Constants.L2F: + case Constants.L2D: + case Constants.F2I: + case Constants.F2L: + case Constants.F2D: + case Constants.D2I: + case Constants.D2L: + case Constants.D2F: + case Constants.I2B: + case Constants.I2C: + case Constants.I2S: + case Constants.LCMP: + case Constants.FCMPL: + case Constants.FCMPG: + case Constants.DCMPL: + case Constants.DCMPG: + case Constants.IFEQ: + case Constants.IFNE: + case Constants.IFLT: + case Constants.IFGE: + case Constants.IFGT: + case Constants.IFLE: + case Constants.IF_ICMPEQ: + case Constants.IF_ICMPNE: + case Constants.IF_ICMPLT: + case Constants.IF_ICMPGE: + case Constants.IF_ICMPGT: + case Constants.IF_ICMPLE: + case Constants.IF_ACMPEQ: + case Constants.IF_ACMPNE: + case Constants.GOTO: + case Constants.JSR: + case Constants.RET: + case Constants.TABLESWITCH: + case Constants.LOOKUPSWITCH: { if (true) { jcfaCode.getComment().getCommentList() .add(" TODO temporary disabled."); @@ -233,6 +367,67 @@ public class JcfaWriteUtil { .add(" TODO skipping bytes: " + (diff2)); break; + } + case Constants.IRETURN: + case Constants.LRETURN: + case Constants.FRETURN: + case Constants.DRETURN: + case Constants.ARETURN: + case Constants.RETURN: { + break; + } + case Constants.GETSTATIC: { + final JcfaItemReference osRef = new JcfaItemReference(); + jcfaMethod.getFrame().getOperandStack().push(osRef); + osRef.setObject(JcfaUtil.getConstantFieldrefString(jc, + codes[1], codes[2])); + + jcfaCode.getComment().getCommentList().add(osRef.getObject()); + break; + } + case Constants.PUTSTATIC: + case Constants.GETFIELD: + case Constants.PUTFIELD: + case Constants.INVOKEVIRTUAL: + case Constants.INVOKESPECIAL: { + final int operand = JcfaUtil.byte2UnsignedShort(codes[1], + codes[2]); + jcfaCode.getComment().getCommentList() + .add(JcfaUtil.getConstantMethodRefString(jc, operand)); + + jcfaCode.getComment().getCommentList() + .add("TODO get args count from signature."); + // get n args. + final JcfaItem osNodeArg0 = jcfaMethod.getFrame() + .getOperandStack().pop(); + + final JcfaItemReference osRef = (JcfaItemReference) jcfaMethod + .getFrame().getOperandStack().pop(); + + jcfaCode.getComment() + .getCommentList() + .add("" + osRef.getObject() + "#" + + osNodeArg0.toString()); + + break; + } + case Constants.INVOKESTATIC: + case Constants.INVOKEINTERFACE: + case Constants.NEW: + case Constants.NEWARRAY: + case Constants.ANEWARRAY: + case Constants.ARRAYLENGTH: + case Constants.ATHROW: + case Constants.CHECKCAST: + case Constants.INSTANCEOF: + case Constants.MONITORENTER: + case Constants.MONITOREXIT: + case Constants.WIDE: + case Constants.MULTIANEWARRAY: + case Constants.IFNULL: + case Constants.IFNONNULL: + case Constants.GOTO_W: + case Constants.JSR_W: default: jcfaCode.getComment().getCommentList() .add("TODO unsupported opcode"); diff --git a/jcfa/testJavaClass/output/test/TestJavaClass001.jcfa b/jcfa/testJavaClass/output/test/TestJavaClass001.jcfa index df6ace8..a5e2bbe 100644 --- a/jcfa/testJavaClass/output/test/TestJavaClass001.jcfa +++ b/jcfa/testJavaClass/output/test/TestJavaClass001.jcfa @@ -5,12 +5,12 @@ public class TestJavaClass001 { /** Constructor. */ public TestJavaClass001() { /* - * 0: aload_0 this + * 0: aload_0 TODO temporary disabled. */ /* * 1: invokespecial java/lang/Object#()V TODO get args count from - * signature. null#jp.igapyon.jcfa.vo.item.JcfaItemLocalVariable@143c919 + * signature. null#jp.igapyon.jcfa.vo.item.JcfaItemReference@143c919 */ /* 4: return */ diff --git a/jcfa/testJavaClass/output/test/TestJavaClass011.jcfa b/jcfa/testJavaClass/output/test/TestJavaClass011.jcfa index 88a762b..358976f 100644 --- a/jcfa/testJavaClass/output/test/TestJavaClass011.jcfa +++ b/jcfa/testJavaClass/output/test/TestJavaClass011.jcfa @@ -5,12 +5,12 @@ public class TestJavaClass011 { /** Constructor. */ public TestJavaClass011() { /* - * 0: aload_0 this + * 0: aload_0 TODO temporary disabled. */ /* * 1: invokespecial java/lang/Object#()V TODO get args count from - * signature. null#jp.igapyon.jcfa.vo.item.JcfaItemLocalVariable@15c0729 + * signature. null#jp.igapyon.jcfa.vo.item.JcfaItemReference@15c0729 */ /* 4: return */ -- 2.11.0