List of usage examples for org.objectweb.asm Label Label
public Label()
From source file:fr.insalyon.citi.golo.compiler.JavaBytecodeGenerationGoloIrVisitor.java
License:Apache License
@Override public void visitConditionalBranching(ConditionalBranching conditionalBranching) { Label branchingElseLabel = new Label(); Label branchingExitLabel = new Label(); conditionalBranching.getCondition().accept(this); asmBooleanValue();//from ww w. j ava 2 s . com methodVisitor.visitJumpInsn(IFEQ, branchingElseLabel); conditionalBranching.getTrueBlock().accept(this); if (conditionalBranching.hasFalseBlock()) { if (!conditionalBranching.getTrueBlock().hasReturn()) { methodVisitor.visitJumpInsn(GOTO, branchingExitLabel); } methodVisitor.visitLabel(branchingElseLabel); conditionalBranching.getFalseBlock().accept(this); methodVisitor.visitLabel(branchingExitLabel); } else if (conditionalBranching.hasElseConditionalBranching()) { if (!conditionalBranching.getTrueBlock().hasReturn()) { methodVisitor.visitJumpInsn(GOTO, branchingExitLabel); } methodVisitor.visitLabel(branchingElseLabel); conditionalBranching.getElseConditionalBranching().accept(this); methodVisitor.visitLabel(branchingExitLabel); } else { methodVisitor.visitLabel(branchingElseLabel); } }
From source file:fr.insalyon.citi.golo.compiler.JavaBytecodeGenerationGoloIrVisitor.java
License:Apache License
@Override public void visitLoopStatement(LoopStatement loopStatement) { // TODO handle init and post statement and potential reference scoping issues Label loopStart = new Label(); Label loopEnd = new Label(); context.loopStartMap.put(loopStatement, loopStart); context.loopEndMap.put(loopStatement, loopEnd); if (loopStatement.hasInitStatement()) { loopStatement.getInitStatement().accept(this); }/*from ww w . ja v a 2 s . com*/ methodVisitor.visitLabel(loopStart); loopStatement.getConditionStatement().accept(this); asmBooleanValue(); methodVisitor.visitJumpInsn(IFEQ, loopEnd); loopStatement.getBlock().accept(this); if (loopStatement.hasPostStatement()) { loopStatement.getPostStatement().accept(this); } methodVisitor.visitJumpInsn(GOTO, loopStart); methodVisitor.visitLabel(loopEnd); }
From source file:fr.insalyon.citi.golo.compiler.JavaBytecodeGenerationGoloIrVisitor.java
License:Apache License
@Override public void visitTryCatchFinally(TryCatchFinally tryCatchFinally) { Label tryStart = new Label(); Label tryEnd = new Label(); Label catchStart = new Label(); Label catchEnd = new Label(); Label rethrowStart = null;/* w w w . j a v a 2s. co m*/ Label rethrowEnd = null; if (tryCatchFinally.isTryCatchFinally()) { rethrowStart = new Label(); rethrowEnd = new Label(); } methodVisitor.visitLabel(tryStart); tryCatchFinally.getTryBlock().accept(this); if (tryCatchFinally.isTryCatch() || tryCatchFinally.isTryCatchFinally()) { methodVisitor.visitJumpInsn(GOTO, catchEnd); } methodVisitor.visitTryCatchBlock(tryStart, tryEnd, catchStart, null); methodVisitor.visitLabel(tryEnd); if (tryCatchFinally.isTryFinally()) { tryCatchFinally.getFinallyBlock().accept(this); methodVisitor.visitJumpInsn(GOTO, catchEnd); } if (tryCatchFinally.isTryCatchFinally()) { methodVisitor.visitTryCatchBlock(catchStart, catchEnd, rethrowStart, null); } methodVisitor.visitLabel(catchStart); if (tryCatchFinally.isTryCatch() || tryCatchFinally.isTryCatchFinally()) { Block catchBlock = tryCatchFinally.getCatchBlock(); int exceptionRefIndex = catchBlock.getReferenceTable().get(tryCatchFinally.getExceptionId()).getIndex(); methodVisitor.visitVarInsn(ASTORE, exceptionRefIndex); tryCatchFinally.getCatchBlock().accept(this); } else { tryCatchFinally.getFinallyBlock().accept(this); methodVisitor.visitInsn(ATHROW); } methodVisitor.visitLabel(catchEnd); if (tryCatchFinally.isTryCatchFinally()) { tryCatchFinally.getFinallyBlock().accept(this); methodVisitor.visitJumpInsn(GOTO, rethrowEnd); methodVisitor.visitLabel(rethrowStart); tryCatchFinally.getFinallyBlock().accept(this); methodVisitor.visitInsn(ATHROW); methodVisitor.visitLabel(rethrowEnd); } }
From source file:fr.insalyon.citi.golo.compiler.JavaBytecodeGenerationGoloIrVisitor.java
License:Apache License
private void orOperator(BinaryOperation binaryOperation) { Label exitLabel = new Label(); Label trueLabel = new Label(); binaryOperation.getLeftExpression().accept(this); asmBooleanValue();/*from www .j ava 2s. c om*/ methodVisitor.visitJumpInsn(IFNE, trueLabel); binaryOperation.getRightExpression().accept(this); asmBooleanValue(); methodVisitor.visitJumpInsn(IFNE, trueLabel); asmFalseObject(); methodVisitor.visitJumpInsn(GOTO, exitLabel); methodVisitor.visitLabel(trueLabel); asmTrueObject(); methodVisitor.visitLabel(exitLabel); }
From source file:fr.insalyon.citi.golo.compiler.JavaBytecodeGenerationGoloIrVisitor.java
License:Apache License
private void andOperator(BinaryOperation binaryOperation) { Label exitLabel = new Label(); Label falseLabel = new Label(); binaryOperation.getLeftExpression().accept(this); asmBooleanValue();// w ww .ja v a 2 s. c om methodVisitor.visitJumpInsn(IFEQ, falseLabel); binaryOperation.getRightExpression().accept(this); asmBooleanValue(); methodVisitor.visitJumpInsn(IFEQ, falseLabel); asmTrueObject(); methodVisitor.visitJumpInsn(GOTO, exitLabel); methodVisitor.visitLabel(falseLabel); asmFalseObject(); methodVisitor.visitLabel(exitLabel); }
From source file:fr.insalyon.citi.golo.compiler.JavaBytecodeStructGenerator.java
License:Apache License
private void makeSetMethod(ClassWriter classWriter, Struct struct) { String owner = struct.getPackageAndClass().toJVMType(); MethodVisitor visitor = classWriter.visitMethod(ACC_PUBLIC, "set", "(Ljava/lang/String;Ljava/lang/Object;)Lgololang/GoloStruct;", null, null); visitor.visitCode();/*from w ww . j a v a 2 s . com*/ insertPrivateElementCheck(struct, visitor); Label nextCase = new Label(); for (String member : struct.getMembers()) { visitor.visitLdcInsn(member); visitor.visitVarInsn(ALOAD, 1); visitor.visitJumpInsn(IF_ACMPNE, nextCase); visitor.visitVarInsn(ALOAD, 0); visitor.visitVarInsn(ALOAD, 2); visitor.visitMethodInsn(INVOKEVIRTUAL, owner, member, "(Ljava/lang/Object;)Lgololang/GoloStruct;"); visitor.visitInsn(ARETURN); visitor.visitLabel(nextCase); nextCase = new Label(); } insertUnknowElementCode(struct, visitor); visitor.visitMaxs(0, 0); visitor.visitEnd(); }
From source file:fr.insalyon.citi.golo.compiler.JavaBytecodeStructGenerator.java
License:Apache License
private void makeGetMethod(ClassWriter classWriter, Struct struct) { String owner = struct.getPackageAndClass().toJVMType(); MethodVisitor visitor = classWriter.visitMethod(ACC_PUBLIC, "get", "(Ljava/lang/String;)Ljava/lang/Object;", null, null);//from w w w. j a v a 2 s . c o m visitor.visitCode(); insertPrivateElementCheck(struct, visitor); Label nextCase = new Label(); for (String member : struct.getMembers()) { visitor.visitLdcInsn(member); visitor.visitVarInsn(ALOAD, 1); visitor.visitJumpInsn(IF_ACMPNE, nextCase); visitor.visitVarInsn(ALOAD, 0); visitor.visitMethodInsn(INVOKEVIRTUAL, owner, member, "()Ljava/lang/Object;"); visitor.visitInsn(ARETURN); visitor.visitLabel(nextCase); nextCase = new Label(); } insertUnknowElementCode(struct, visitor); visitor.visitMaxs(0, 0); visitor.visitEnd(); }
From source file:fr.insalyon.citi.golo.compiler.JavaBytecodeStructGenerator.java
License:Apache License
private void insertPrivateElementCheck(Struct struct, MethodVisitor visitor) { Label afterPrivateCheck = new Label(); visitor.visitVarInsn(ALOAD, 1);//from w ww . j a v a 2 s. co m visitor.visitLdcInsn("_"); visitor.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "startsWith", "(Ljava/lang/String;)Z"); visitor.visitJumpInsn(IFEQ, afterPrivateCheck); visitor.visitTypeInsn(NEW, "java/lang/IllegalArgumentException"); visitor.visitInsn(DUP); visitor.visitLdcInsn("Private member of " + struct.getPackageAndClass().toString()); visitor.visitMethodInsn(INVOKESPECIAL, "java/lang/IllegalArgumentException", "<init>", "(Ljava/lang/String;)V"); visitor.visitInsn(ATHROW); visitor.visitLabel(afterPrivateCheck); }
From source file:fr.insalyon.citi.golo.compiler.JavaBytecodeStructGenerator.java
License:Apache License
private void makeEquals(ClassWriter classWriter, Struct struct) { String owner = struct.getPackageAndClass().toJVMType(); MethodVisitor visitor = classWriter.visitMethod(ACC_PUBLIC, "equals", "(Ljava/lang/Object;)Z", null, null); Label notFrozenLabel = new Label(); Label falseLabel = new Label(); Label sameTypeLabel = new Label(); visitor.visitCode();/* w ww. j a v a2 s. co m*/ visitor.visitVarInsn(ALOAD, 0); visitor.visitFieldInsn(GETFIELD, owner, $_frozen, "Z"); visitor.visitJumpInsn(IFNE, notFrozenLabel); // super.equals() visitor.visitVarInsn(ALOAD, 0); visitor.visitVarInsn(ALOAD, 1); visitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z"); visitor.visitInsn(IRETURN); // The receiver is frozen visitor.visitLabel(notFrozenLabel); visitor.visitVarInsn(ALOAD, 1); visitor.visitTypeInsn(INSTANCEOF, owner); visitor.visitJumpInsn(IFNE, sameTypeLabel); visitor.visitJumpInsn(GOTO, falseLabel); // The argument is of the same type, too visitor.visitLabel(sameTypeLabel); visitor.visitVarInsn(ALOAD, 1); visitor.visitTypeInsn(CHECKCAST, owner); visitor.visitFieldInsn(GETFIELD, owner, $_frozen, "Z"); visitor.visitJumpInsn(IFEQ, falseLabel); // The argument is not frozen for (String member : struct.getMembers()) { visitor.visitVarInsn(ALOAD, 0); visitor.visitFieldInsn(GETFIELD, owner, member, "Ljava/lang/Object;"); visitor.visitVarInsn(ALOAD, 1); visitor.visitTypeInsn(CHECKCAST, owner); visitor.visitFieldInsn(GETFIELD, owner, member, "Ljava/lang/Object;"); visitor.visitMethodInsn(INVOKESTATIC, "java/util/Objects", "equals", "(Ljava/lang/Object;Ljava/lang/Object;)Z"); visitor.visitJumpInsn(IFEQ, falseLabel); } visitor.visitInsn(ICONST_1); visitor.visitInsn(IRETURN); // False visitor.visitLabel(falseLabel); visitor.visitInsn(ICONST_0); visitor.visitInsn(IRETURN); visitor.visitMaxs(0, 0); visitor.visitEnd(); }