Search in sources :

Example 6 with Textifier

use of org.jetbrains.org.objectweb.asm.util.Textifier in project kotlin by JetBrains.

the class CodegenTestCase method verifyWithAsm.

private static boolean verifyWithAsm(@NotNull OutputFile file, ClassLoader loader) {
    ClassNode classNode = new ClassNode();
    new ClassReader(file.asByteArray()).accept(classNode, 0);
    SimpleVerifier verifier = new SimpleVerifier();
    verifier.setClassLoader(loader);
    Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(verifier);
    boolean noErrors = true;
    for (MethodNode method : classNode.methods) {
        try {
            analyzer.analyze(classNode.name, method);
        } catch (Throwable e) {
            System.err.println(file.asText());
            System.err.println(classNode.name + "::" + method.name + method.desc);
            //noinspection InstanceofCatchParameter
            if (e instanceof AnalyzerException) {
                // Print the erroneous instruction
                TraceMethodVisitor tmv = new TraceMethodVisitor(new Textifier());
                ((AnalyzerException) e).node.accept(tmv);
                PrintWriter pw = new PrintWriter(System.err);
                tmv.p.print(pw);
                pw.flush();
            }
            e.printStackTrace();
            noErrors = false;
        }
    }
    return noErrors;
}
Also used : ClassNode(org.jetbrains.org.objectweb.asm.tree.ClassNode) AnalyzerException(org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException) SimpleVerifier(org.jetbrains.org.objectweb.asm.tree.analysis.SimpleVerifier) Analyzer(org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer) Textifier(org.jetbrains.org.objectweb.asm.util.Textifier) TraceMethodVisitor(org.jetbrains.org.objectweb.asm.util.TraceMethodVisitor) BasicValue(org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue) MethodNode(org.jetbrains.org.objectweb.asm.tree.MethodNode) ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) PrintWriter(java.io.PrintWriter)

Aggregations

Textifier (org.jetbrains.org.objectweb.asm.util.Textifier)6 PrintWriter (java.io.PrintWriter)5 TraceMethodVisitor (org.jetbrains.org.objectweb.asm.util.TraceMethodVisitor)5 StringWriter (java.io.StringWriter)4 NotNull (org.jetbrains.annotations.NotNull)2 ClassReader (org.jetbrains.org.objectweb.asm.ClassReader)2 Method (java.lang.reflect.Method)1 org.jetbrains.org.objectweb.asm (org.jetbrains.org.objectweb.asm)1 InstructionAdapter (org.jetbrains.org.objectweb.asm.commons.InstructionAdapter)1 ClassNode (org.jetbrains.org.objectweb.asm.tree.ClassNode)1 MethodNode (org.jetbrains.org.objectweb.asm.tree.MethodNode)1 Analyzer (org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer)1 AnalyzerException (org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException)1 BasicValue (org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue)1 SimpleVerifier (org.jetbrains.org.objectweb.asm.tree.analysis.SimpleVerifier)1 TraceClassVisitor (org.jetbrains.org.objectweb.asm.util.TraceClassVisitor)1