Search in sources :

Example 1 with SimpleVerifier

use of org.jetbrains.org.objectweb.asm.tree.analysis.SimpleVerifier 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

PrintWriter (java.io.PrintWriter)1 ClassReader (org.jetbrains.org.objectweb.asm.ClassReader)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 Textifier (org.jetbrains.org.objectweb.asm.util.Textifier)1 TraceMethodVisitor (org.jetbrains.org.objectweb.asm.util.TraceMethodVisitor)1