Example usage for org.objectweb.asm Opcodes GOTO

List of usage examples for org.objectweb.asm Opcodes GOTO

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes GOTO.

Prototype

int GOTO

To view the source code for org.objectweb.asm Opcodes GOTO.

Click Source Link

Usage

From source file:org.evosuite.runtime.instrumentation.MethodCallReplacement.java

License:Open Source License

public void insertMethodCall(MethodCallReplacementMethodAdapter mv, int opcode) {
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, MockFramework.class.getCanonicalName().replace('.', '/'),
            "isEnabled", "()Z", false);
    Label origCallLabel = new Label();
    Label afterOrigCallLabel = new Label();

    Label annotationStartTag = new AnnotatedLabel(true, true);
    annotationStartTag.info = Boolean.TRUE;
    mv.visitLabel(annotationStartTag);/*from   w ww . ja v  a 2  s .  c  o m*/
    mv.visitJumpInsn(Opcodes.IFEQ, origCallLabel);
    Label annotationEndTag = new AnnotatedLabel(true, false);
    annotationEndTag.info = Boolean.FALSE;
    mv.visitLabel(annotationEndTag);

    if (popCallee) {
        Type[] args = Type.getArgumentTypes(desc);
        Map<Integer, Integer> to = new HashMap<Integer, Integer>();
        for (int i = args.length - 1; i >= 0; i--) {
            int loc = mv.newLocal(args[i]);
            mv.storeLocal(loc);
            to.put(i, loc);
        }

        mv.pop();//callee
        if (popUninitialisedReference)
            mv.pop();

        for (int i = 0; i < args.length; i++) {
            mv.loadLocal(to.get(i));
        }
    }
    if (opcode == Opcodes.INVOKESPECIAL && MockList.shouldBeMocked(className.replace('/', '.'))) {
        insertInvokeSpecialForMockedSuperclass(mv);
    } else {
        if (opcode == Opcodes.INVOKESPECIAL) {
            logger.info("Not mocking invokespecial: " + replacementMethodName + " for class " + className);
        }
        mv.visitMethodInsn(opcode, replacementClassName, replacementMethodName, replacementDesc, false);
    }
    mv.visitJumpInsn(Opcodes.GOTO, afterOrigCallLabel);
    mv.visitLabel(origCallLabel);
    mv.getNextVisitor().visitMethodInsn(origOpcode, className, methodName, desc, false); // TODO: What is itf here?
    mv.visitLabel(afterOrigCallLabel);
}

From source file:org.evosuite.runtime.instrumentation.MethodCallReplacement.java

License:Open Source License

public void insertConstructorCall(MethodCallReplacementMethodAdapter mv, MethodCallReplacement replacement,
        boolean isSelf) {
    Label origCallLabel = new Label();
    Label afterOrigCallLabel = new Label();

    if (!isSelf) {
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, MockFramework.class.getCanonicalName().replace('.', '/'),
                "isEnabled", "()Z", false);
        Label annotationStartTag = new AnnotatedLabel(true, true);
        annotationStartTag.info = Boolean.TRUE;
        mv.visitLabel(annotationStartTag);
        mv.visitJumpInsn(Opcodes.IFEQ, origCallLabel);
        Label annotationEndTag = new AnnotatedLabel(true, false);
        annotationEndTag.info = Boolean.FALSE;
        mv.visitLabel(annotationEndTag);

        Type[] args = Type.getArgumentTypes(desc);
        Map<Integer, Integer> to = new HashMap<Integer, Integer>();
        for (int i = args.length - 1; i >= 0; i--) {
            int loc = mv.newLocal(args[i]);
            mv.storeLocal(loc);/*from w  w w .ja v  a  2 s .  c o  m*/
            to.put(i, loc);
        }

        mv.pop2();//uninitialized reference (which is duplicated)
        mv.newInstance(Type.getType(replacement.replacementClassName));
        mv.dup();

        for (int i = 0; i < args.length; i++) {
            mv.loadLocal(to.get(i));
        }
    }
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, replacementClassName, replacementMethodName, replacementDesc,
            false);
    if (!isSelf) {
        mv.visitJumpInsn(Opcodes.GOTO, afterOrigCallLabel);
        mv.visitLabel(origCallLabel);
        mv.getNextVisitor().visitMethodInsn(Opcodes.INVOKESPECIAL, className, methodName, desc, false);
        mv.visitLabel(afterOrigCallLabel);
    }
}

From source file:org.evosuite.testcarver.instrument.Instrumenter.java

License:Open Source License

/**
 *    public int myMethod(int i)// w w  w . j  av  a 2 s .  c  o m
   {
 try
 {
    return _sw_prototype_original_myMethod(i)
 }
 finally
 {
    Capturer.enable();
 }
   }
        
 * @param classNode
 * @param className
 * @param methodNode
 */
@SuppressWarnings("unchecked")
private MethodNode wrapMethod(final ClassNode classNode, final String className, final MethodNode methodNode) {
    methodNode.maxStack += 4;

    // create wrapper for original method
    final MethodNode wrappingMethodNode = new MethodNode(methodNode.access, methodNode.name, methodNode.desc,
            methodNode.signature,
            (String[]) methodNode.exceptions.toArray(new String[methodNode.exceptions.size()]));
    wrappingMethodNode.maxStack = methodNode.maxStack;

    // assign annotations to wrapping method
    wrappingMethodNode.visibleAnnotations = methodNode.visibleAnnotations;
    wrappingMethodNode.visibleParameterAnnotations = methodNode.visibleParameterAnnotations;

    // remove annotations from wrapped method to avoid wrong behavior controlled by annotations
    methodNode.visibleAnnotations = null;
    methodNode.visibleParameterAnnotations = null;

    // rename original method
    methodNode.access = TransformerUtil.modifyVisibility(methodNode.access, Opcodes.ACC_PRIVATE);

    final LabelNode l0 = new LabelNode();
    final LabelNode l1 = new LabelNode();
    final LabelNode l2 = new LabelNode();

    final InsnList wInstructions = wrappingMethodNode.instructions;

    if ("<init>".equals(methodNode.name)) {
        // wrap a constructor 

        methodNode.name = WRAP_NAME_PREFIX + "init" + WRAP_NAME_PREFIX;

        // move call to other constructors to new method
        AbstractInsnNode ins = null;
        ListIterator<AbstractInsnNode> iter = methodNode.instructions.iterator();

        int numInvokeSpecials = 0; // number of invokespecial calls before actual constructor call

        while (iter.hasNext()) {
            ins = iter.next();
            iter.remove();
            wInstructions.add(ins);

            if (ins instanceof MethodInsnNode) {
                MethodInsnNode mins = (MethodInsnNode) ins;
                if (ins.getOpcode() == Opcodes.INVOKESPECIAL) {
                    if (mins.name.startsWith("<init>")) {
                        if (numInvokeSpecials == 0) {
                            break;
                        } else {
                            numInvokeSpecials--;
                        }
                    }
                }
            } else if (ins instanceof TypeInsnNode) {
                TypeInsnNode typeIns = (TypeInsnNode) ins;
                if (typeIns.getOpcode() == Opcodes.NEW || typeIns.getOpcode() == Opcodes.NEWARRAY) {
                    numInvokeSpecials++;
                }
            }
        }
    } else {
        methodNode.name = WRAP_NAME_PREFIX + methodNode.name;
    }

    int varReturnValue = 0;

    final Type returnType = Type.getReturnType(methodNode.desc);

    if (returnType.equals(Type.VOID_TYPE)) {
        wrappingMethodNode.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l1, "java/lang/Throwable"));

    } else {

        wrappingMethodNode.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l2, "java/lang/Throwable"));

        //--- create "Object returnValue = null;"

        if (!TransformerUtil.isStatic(methodNode.access)) {
            // load "this"
            varReturnValue++;
        }

        // consider method arguments to find right variable index
        final Type[] argTypes = Type.getArgumentTypes(methodNode.desc);
        for (int i = 0; i < argTypes.length; i++) {
            varReturnValue++;

            // long/double take two registers
            if (argTypes[i].equals(Type.LONG_TYPE) || argTypes[i].equals(Type.DOUBLE_TYPE)) {
                varReturnValue++;
            }
        }

        // push NULL on the stack and initialize variable for return value for it
        wInstructions.add(new InsnNode(Opcodes.ACONST_NULL));
        wInstructions.add(new VarInsnNode(Opcodes.ASTORE, varReturnValue));
    }

    int var = 0;

    // --- L0
    wInstructions.add(l0);

    wInstructions.add(this.addCaptureCall(TransformerUtil.isStatic(methodNode.access), className,
            wrappingMethodNode.name, wrappingMethodNode.desc, Type.getArgumentTypes(methodNode.desc)));

    // --- construct call to wrapped methode

    if (!TransformerUtil.isStatic(methodNode.access)) {
        // load "this" to call method
        wInstructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
        var++;
    }

    final Type[] argTypes = Type.getArgumentTypes(methodNode.desc);
    for (int i = 0; i < argTypes.length; i++) {
        this.addLoadInsn(wInstructions, argTypes[i], var++);

        // long/double take two registers
        if (argTypes[i].equals(Type.LONG_TYPE) || argTypes[i].equals(Type.DOUBLE_TYPE)) {
            var++;
        }
    }

    if (TransformerUtil.isStatic(methodNode.access)) {
        wInstructions.add(
                new MethodInsnNode(Opcodes.INVOKESTATIC, classNode.name, methodNode.name, methodNode.desc));
    } else {
        wInstructions.add(
                new MethodInsnNode(Opcodes.INVOKEVIRTUAL, classNode.name, methodNode.name, methodNode.desc));
    }

    var++;

    if (returnType.equals(Type.VOID_TYPE)) {
        wInstructions.add(new JumpInsnNode(Opcodes.GOTO, l2));

        // --- L1

        wInstructions.add(l1);

        wInstructions.add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }));

        wInstructions.add(new VarInsnNode(Opcodes.ASTORE, --var));

        this.addCaptureEnableStatement(className, methodNode, wInstructions, -1);

        wInstructions.add(new VarInsnNode(Opcodes.ALOAD, var));
        wInstructions.add(new InsnNode(Opcodes.ATHROW));

        // FIXME <--- DUPLICATE CODE

        // --- L2

        wInstructions.add(l2);
        wInstructions.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));

        this.addCaptureEnableStatement(className, methodNode, wInstructions, -1);

        wInstructions.add(new InsnNode(Opcodes.RETURN));
    } else {
        // construct store of the wrapped method call's result

        this.addBoxingStmt(wInstructions, returnType);

        wInstructions.add(new VarInsnNode(Opcodes.ASTORE, varReturnValue));
        wInstructions.add(new VarInsnNode(Opcodes.ALOAD, varReturnValue));

        this.addUnBoxingStmt(wInstructions, returnType);

        final int storeOpcode = returnType.getOpcode(Opcodes.ISTORE);
        wInstructions.add(new VarInsnNode(storeOpcode, ++var)); // might be only var

        // --- L1

        wInstructions.add(l1);

        this.addCaptureEnableStatement(className, methodNode, wInstructions, varReturnValue);

        // construct load of the wrapped method call's result
        int loadOpcode = returnType.getOpcode(Opcodes.ILOAD);
        wInstructions.add(new VarInsnNode(loadOpcode, var));

        // construct return of the wrapped method call's result
        this.addReturnInsn(wInstructions, returnType);

        //---- L2

        wInstructions.add(l2);

        wInstructions.add(
                new FrameNode(Opcodes.F_FULL, 2, new Object[] { className, this.getInternalName(returnType) },
                        1, new Object[] { "java/lang/Throwable" }));
        wInstructions.add(new VarInsnNode(Opcodes.ASTORE, --var));

        this.addCaptureEnableStatement(className, methodNode, wInstructions, varReturnValue);

        wInstructions.add(new VarInsnNode(Opcodes.ALOAD, var));
        wInstructions.add(new InsnNode(Opcodes.ATHROW));
    }
    transformWrapperCalls(methodNode);
    return wrappingMethodNode;
}

From source file:org.formulacompiler.compiler.internal.bytecode.ExpressionCompiler.java

License:Open Source License

private final void compileIf(ExpressionNode _test, ExpressionNode _ifTrue, ExpressionNode _ifFalse)
        throws CompilerException {
    final GeneratorAdapter mv = mv();
    final Label notMet = mv.newLabel();
    final Label done = mv.newLabel();

    method().numericCompiler().compileTest(_test, notMet);

    final Set<DelayedLet> outerSetsInTrueBranch = compileTrackingSetsOfOuterLets(_ifTrue);
    revertSetsOfOuterLets(outerSetsInTrueBranch, null);

    mv.visitJumpInsn(Opcodes.GOTO, done);
    mv.mark(notMet);/*from ww  w  .  j  a  va2s.  c  om*/

    final Set<DelayedLet> outerSetsInFalseBranch = compileTrackingSetsOfOuterLets(_ifFalse);
    revertSetsOfOuterLets(outerSetsInFalseBranch, outerSetsInTrueBranch);

    mv.mark(done);
}

From source file:org.graalvm.compiler.replacements.test.DeoptimizeOnExceptionTest.java

License:Open Source License

private static byte[] makeClazz() {
    // Code generated the class below using asm.
    String clazzName = DeoptimizeOnExceptionTest.class.getName().replace('.', '/');
    final ClassWriter w = new ClassWriter(0);
    w.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "t/TestJSR", null, "java/lang/Object",
            new String[] { "java/lang/Runnable" });
    MethodVisitor mv = w.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[] {});
    mv.visitCode();/*  www.  j  av  a 2  s  .  c o  m*/
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(10, 10);
    mv.visitEnd();

    mv = w.visitMethod(Opcodes.ACC_PUBLIC, "run", "()V", null, null);
    mv.visitCode();
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "getM", "()Ljava/lang/Object;", false);
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.JSR, l1);
    mv.visitInsn(Opcodes.RETURN);

    mv.visitLabel(l1);
    mv.visitVarInsn(Opcodes.ASTORE, 1);

    Label lElse = new Label();
    Label lEnd = new Label();
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false);
    mv.visitInsn(Opcodes.POP2);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "getM", "()Ljava/lang/Object;", false);
    mv.visitInsn(Opcodes.DUP);
    mv.visitJumpInsn(Opcodes.IFNULL, lElse);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "methodA", "()V", false);
    mv.visitJumpInsn(Opcodes.GOTO, lEnd);
    mv.visitLabel(lElse);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "methodB", "()V", false);
    mv.visitLabel(lEnd);

    mv.visitVarInsn(Opcodes.RET, 1);
    mv.visitMaxs(10, 10);
    mv.visitEnd();
    return w.toByteArray();
}

From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java

private void handleBooleanOperator(Expression node, Operator op, Type type) throws ASTVisitorException {
    List<JumpInsnNode> trueList = new ArrayList<JumpInsnNode>();
    System.out.println("***** handle boolean " + op);
    if (type.equals(TypeUtils.STRING_TYPE)) {
        mn.instructions.add(new InsnNode(Opcodes.SWAP));
        JumpInsnNode jmp = null;//ww  w  .  jav  a2s .co m
        mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals",
                "(Ljava/lang/Object;)Z", false));
        switch (op) {
        case EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFNE, null);
            break;
        case NOT_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFEQ, null);
            break;
        default:
            ASTUtils.error(node, "Operator not supported on strings");
            break;
        }
        mn.instructions.add(jmp);
        trueList.add(jmp);
    } else if (type.equals(Type.DOUBLE_TYPE)) {

        // FIXME: add DCMPG instruction
        // FIXME: add a JumpInsnNode with null label based on the operation
        //        IFEQ, IFNE, IFGT, IFGE, IFLT, IFLE
        // FIXME: add the jmp instruction into trueList
        mn.instructions.add(new InsnNode(Opcodes.DCMPG));
        JumpInsnNode jmp = null;
        switch (op) {
        case EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFEQ, null);
            mn.instructions.add(jmp);
            break;
        case NOT_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFNE, null);
            mn.instructions.add(jmp);
            break;
        case GREATER:
            jmp = new JumpInsnNode(Opcodes.IFGT, null);
            mn.instructions.add(jmp);
            break;
        case GREATER_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFGE, null);
            mn.instructions.add(jmp);
            break;
        case LESS:
            jmp = new JumpInsnNode(Opcodes.IFLT, null);
            mn.instructions.add(jmp);
            break;
        case LESS_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFLE, null);
            mn.instructions.add(jmp);
            break;
        }
        trueList.add(jmp);

    } else {
        System.out.println("here");
        JumpInsnNode jmp = null;
        switch (op) {
        case EQUAL:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPEQ, null);
            mn.instructions.add(jmp);
            break;
        case NOT_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPNE, null);
            mn.instructions.add(jmp);
            break;
        case GREATER:
            System.out.println("----- greater");
            jmp = new JumpInsnNode(Opcodes.IF_ICMPGT, null);
            mn.instructions.add(jmp);
            break;
        case GREATER_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPGE, null);
            mn.instructions.add(jmp);
            break;
        case LESS:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPLT, null);
            mn.instructions.add(jmp);
            break;
        case LESS_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPLE, null);
            mn.instructions.add(jmp);
            break;
        default:
            ASTUtils.error(node, "Operator not supported");
            break;
        }
        trueList.add(jmp);
    }
    ASTUtils.setTrueList(node, trueList);
    List<JumpInsnNode> falseList = new ArrayList<JumpInsnNode>();
    JumpInsnNode jmp = new JumpInsnNode(Opcodes.GOTO, null);
    mn.instructions.add(jmp);
    falseList.add(jmp);
    ASTUtils.setFalseList(node, falseList);
}

From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java

private void handleNumberOperator(ASTNode node, Operator op, Type type) throws ASTVisitorException {
    if (op.equals(Operator.PLUS)) {

        // FIXME: IADD or DADD, etc.
        //        use type.getOpcode(Opcodes.IADD) to avoid if-then
        mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IADD)));

    } else if (op.equals(Operator.MINUS)) {

        // FIXME: ISUB or DSUB, etc.
        //        use type.getOpcode() to avoid if-then
        mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.ISUB)));

    } else if (op.equals(Operator.MULTIPLY)) {

        // FIXME: IMUL or DMUL, etc.
        //        use type.getOpcode() to avoid if-then
        mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IMUL)));

    } else if (op.equals(Operator.DIVISION)) {

        // FIXME: IDIV or DDIV, etc.
        //        use type.getOpcode() to avoid if-then
        mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IDIV)));

    } else if (op.isRelational()) {
        if (type.equals(Type.DOUBLE_TYPE)) {
            mn.instructions.add(new InsnNode(Opcodes.DCMPG));
            JumpInsnNode jmp = null;/*w  w w  .  j a va  2 s. co m*/
            switch (op) {
            case EQUAL:
                jmp = new JumpInsnNode(Opcodes.IFEQ, null);
                mn.instructions.add(jmp);
                break;
            case NOT_EQUAL:
                jmp = new JumpInsnNode(Opcodes.IFNE, null);
                mn.instructions.add(jmp);
                break;
            case GREATER:
                jmp = new JumpInsnNode(Opcodes.IFGT, null);
                mn.instructions.add(jmp);
                break;
            case GREATER_EQUAL:
                jmp = new JumpInsnNode(Opcodes.IFGE, null);
                mn.instructions.add(jmp);
                break;
            case LESS:
                jmp = new JumpInsnNode(Opcodes.IFLT, null);
                mn.instructions.add(jmp);
                break;
            case LESS_EQUAL:
                jmp = new JumpInsnNode(Opcodes.IFLE, null);
                mn.instructions.add(jmp);
                break;
            default:
                ASTUtils.error(node, "Operator not supported");
                break;
            }
            mn.instructions.add(new InsnNode(Opcodes.ICONST_0));
            LabelNode endLabelNode = new LabelNode();
            mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode));
            LabelNode trueLabelNode = new LabelNode();
            jmp.label = trueLabelNode;
            mn.instructions.add(trueLabelNode);
            mn.instructions.add(new InsnNode(Opcodes.ICONST_1));
            mn.instructions.add(endLabelNode);
        } else if (type.equals(Type.INT_TYPE)) {
            LabelNode trueLabelNode = new LabelNode();
            switch (op) {
            case EQUAL:
                mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPEQ, trueLabelNode));
                break;
            case NOT_EQUAL:
                mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPNE, trueLabelNode));
                break;
            case GREATER:
                mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPGT, trueLabelNode));
                break;
            case GREATER_EQUAL:
                mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPGE, trueLabelNode));
                break;
            case LESS:
                mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPLT, trueLabelNode));
                break;
            case LESS_EQUAL:
                mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPLE, trueLabelNode));
                break;
            default:
                break;
            }
            mn.instructions.add(new InsnNode(Opcodes.ICONST_0));
            LabelNode endLabelNode = new LabelNode();
            mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode));
            mn.instructions.add(trueLabelNode);
            mn.instructions.add(new InsnNode(Opcodes.ICONST_1));
            mn.instructions.add(endLabelNode);
        } else {
            ASTUtils.error(node, "Cannot compare such types.");
        }
    } else {
        ASTUtils.error(node, "Operator not recognized.");
    }
}

From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java

/**
 * Assumes top of stack contains two strings
 *///from w  w  w .j a v a  2s  . co  m
private void handleStringOperator(ASTNode node, Operator op) throws ASTVisitorException {
    if (op.equals(Operator.PLUS)) {
        mn.instructions.add(new TypeInsnNode(Opcodes.NEW, "java/lang/StringBuilder"));
        mn.instructions.add(new InsnNode(Opcodes.DUP));
        mn.instructions.add(
                new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false));
        mn.instructions.add(new InsnNode(Opcodes.SWAP));
        mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false));
        mn.instructions.add(new InsnNode(Opcodes.SWAP));
        mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false));
        mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString",
                "()Ljava/lang/String;", false));
    } else if (op.isRelational()) {
        LabelNode trueLabelNode = new LabelNode();
        switch (op) {
        case EQUAL:
            mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals",
                    "(Ljava/lang/Object;)Z", false));
            mn.instructions.add(new JumpInsnNode(Opcodes.IFNE, trueLabelNode));
            break;
        case NOT_EQUAL:
            mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals",
                    "(Ljava/lang/Object;)Z", false));
            mn.instructions.add(new JumpInsnNode(Opcodes.IFEQ, trueLabelNode));
            break;
        default:
            ASTUtils.error(node, "Operator not supported on strings");
            break;
        }
        mn.instructions.add(new InsnNode(Opcodes.ICONST_0));
        LabelNode endLabelNode = new LabelNode();
        mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode));
        mn.instructions.add(trueLabelNode);
        mn.instructions.add(new InsnNode(Opcodes.ICONST_1));
        mn.instructions.add(endLabelNode);
    } else {
        ASTUtils.error(node, "Operator not recognized");
    }
}

From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java

@Override
public void visit(BreakStatement node) throws ASTVisitorException {
    JumpInsnNode jmp = new JumpInsnNode(Opcodes.GOTO, null);
    mn.instructions.add(jmp);//from   www  . java 2s . c  o m
    ASTUtils.getBreakList(node).add(jmp);
}

From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java

@Override
public void visit(ContinueStatement node) throws ASTVisitorException {
    JumpInsnNode jmp = new JumpInsnNode(Opcodes.GOTO, null);
    mn.instructions.add(jmp);/*  w  w  w. j  a v a  2 s  .c  o m*/
    ASTUtils.getContinueList(node).add(jmp);
}