Search in sources :

Example 1 with PrimitiveArrayAnalyzer

use of edu.columbia.cs.psl.phosphor.instrumenter.PrimitiveArrayAnalyzer in project phosphor by gmu-swe.

the class DebugPrinter method main.

public static void main(String[] args) throws Exception {
    // Configuration.IMPLICIT_TRACKING = true;
    File clazz = new File(args[0]);
    final ClassReader cr1 = new ClassReader(new FileInputStream(clazz));
    PrintWriter pw = new PrintWriter(new FileWriter("z.txt"));
    ClassWriter cw1 = new ClassWriter(ClassWriter.COMPUTE_FRAMES) {

        @Override
        protected String getCommonSuperClass(String type1, String type2) {
            try {
                return super.getCommonSuperClass(type1, type2);
            } catch (Exception ex) {
                // System.err.println("err btwn " + type1 + " " +type2);
                return "java/lang/Unknown";
            }
        }
    };
    cr1.accept(new ClassVisitor(Opcodes.ASM4, cw1) {

        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            // TODO Auto-generated method stub
            return new JSRInlinerAdapter(super.visitMethod(access, name, desc, signature, exceptions), access, name, desc, signature, exceptions);
        }
    }, ClassReader.EXPAND_FRAMES);
    final ClassReader cr = new ClassReader(cw1.toByteArray());
    TraceClassVisitor tcv = new TraceClassVisitor(new ClassVisitor(Opcodes.ASM5, new ClassWriter(0)) {

        String className;

        @Override
        public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
            super.visit(version, access, name, signature, superName, interfaces);
            this.className = name;
        }

        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            // TODO Auto-generated method stub
            MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
            mv = new PrimitiveArrayAnalyzer(cr.getClassName(), access, name, desc, signature, exceptions, mv);
            NeverNullArgAnalyzerAdapter an = new NeverNullArgAnalyzerAdapter(cr.getClassName(), access, name, desc, mv);
            ((PrimitiveArrayAnalyzer) mv).setAnalyzer(an);
            mv = an;
            return mv;
        }
    }, pw);
    cr.accept(tcv, ClassReader.EXPAND_FRAMES);
    pw.flush();
}
Also used : FileWriter(java.io.FileWriter) TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) ClassVisitor(org.objectweb.asm.ClassVisitor) FileInputStream(java.io.FileInputStream) ClassWriter(org.objectweb.asm.ClassWriter) JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter) MethodVisitor(org.objectweb.asm.MethodVisitor) PrimitiveArrayAnalyzer(edu.columbia.cs.psl.phosphor.instrumenter.PrimitiveArrayAnalyzer) TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) NeverNullArgAnalyzerAdapter(edu.columbia.cs.psl.phosphor.instrumenter.analyzer.NeverNullArgAnalyzerAdapter) ClassReader(org.objectweb.asm.ClassReader) File(java.io.File) PrintWriter(java.io.PrintWriter)

Aggregations

PrimitiveArrayAnalyzer (edu.columbia.cs.psl.phosphor.instrumenter.PrimitiveArrayAnalyzer)1 NeverNullArgAnalyzerAdapter (edu.columbia.cs.psl.phosphor.instrumenter.analyzer.NeverNullArgAnalyzerAdapter)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 ClassReader (org.objectweb.asm.ClassReader)1 ClassVisitor (org.objectweb.asm.ClassVisitor)1 ClassWriter (org.objectweb.asm.ClassWriter)1 MethodVisitor (org.objectweb.asm.MethodVisitor)1 JSRInlinerAdapter (org.objectweb.asm.commons.JSRInlinerAdapter)1 TraceClassVisitor (org.objectweb.asm.util.TraceClassVisitor)1