Example usage for org.objectweb.asm Label Label

List of usage examples for org.objectweb.asm Label Label

Introduction

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

Prototype

public Label() 

Source Link

Document

Constructs a new label.

Usage

From source file:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java

public void emitInstanceCheck(TypeWidget targetType, Class<?> clazz, Label isNotInstance) {
    Label is = new Label();
    Label not = new Label();
    nullTest(targetType, isNotInstance);
    emitInstanceOf(targetType, clazz, not);
    getMethodVisitor().visitJumpInsn(Opcodes.GOTO, is);
    getMethodVisitor().visitLabel(not);/*  www.  j  a  v  a  2s .  co  m*/
    pop(targetType);
    getMethodVisitor().visitJumpInsn(Opcodes.GOTO, isNotInstance);
    getMethodVisitor().visitLabel(is);
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java

public void emitStringSwitch(Map<String, Label> labels, Label defaultCase, boolean caseInsensitive) {
    MethodVisitor mv = getMethodVisitor();
    if (caseInsensitive) {
        mv.visitFieldInsn(GETSTATIC, "java/util/Locale", "ENGLISH", "Ljava/util/Locale;");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "toUpperCase",
                "(Ljava/util/Locale;)Ljava/lang/String;", false);
    }// w  ww.j  a  v a  2  s.c o m
    mv.visitInsn(DUP);
    AssignableValue tmp = allocate(String.class);
    tmp.write(BaseTypeAdapter.STRING).generate(this);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false);
    Multimap<Integer, SwitchLabel> keys = ArrayListMultimap.create();
    for (Map.Entry<String, Label> e : labels.entrySet()) {
        String name = e.getKey();
        if (caseInsensitive) {
            name = name.toUpperCase(Locale.ENGLISH);
        }
        keys.put(name.hashCode(), new SwitchLabel(name, e.getValue()));
    }
    List<Integer> codes = Lists.newArrayList(keys.keySet());
    Collections.sort(codes);
    int[] k = new int[codes.size()];
    Label[] kl = new Label[codes.size()];
    for (int i = 0; i < k.length; ++i) {
        k[i] = codes.get(i);
        kl[i] = new Label();
    }
    mv.visitLookupSwitchInsn(defaultCase, k, kl);
    for (int i = 0; i < k.length; ++i) {
        mv.visitLabel(kl[i]);
        for (SwitchLabel switchLabel : keys.get(k[i])) {
            mv.visitLdcInsn(switchLabel.name);
            tmp.read().generate(this);
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
            mv.visitJumpInsn(IFNE, switchLabel.label);
        }
        mv.visitJumpInsn(GOTO, defaultCase);
    }
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.CompareExpression.java

@Override
public void generate(CodeEmitter code) {
    // a bit of a hack; should not need to go to dynamic invocation for this unless one arg is ANY
    Label done = new Label();
    MethodVisitor mv = code.getMethodVisitor();
    Label leftNull = new Label();
    Label rightNull = new Label();
    Label bothNull = new Label();
    CodeEmitter.Unification unified = code.unifiedEmit(leftExpr, rightExpr, leftNull, rightNull, bothNull);
    if (unified.type.isPrimitive()) {
        emitPrimitiveCompare(code, unified.type);
    } else {/*  w w w  .j  a  v  a 2 s .  c  o m*/
        // TODO: statically determine if the unified type is Comparable -- for now treat them all like "any"
        CodeEmitter scope = code.createScope();
        MethodVisitor mv2 = scope.getMethodVisitor();
        AssignableValue right = scope.allocate(unified.type);
        AssignableValue left = scope.allocate(unified.type);
        scope.exec(right.write(unified.type));
        scope.exec(left.write(unified.type));
        scope.exec(left.read());
        Label leftIsNotComparable = new Label();
        scope.emitInstanceCheck(unified.type, Comparable.class, leftIsNotComparable);
        scope.exec(right.read());
        mv2.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Comparable.class), "compareTo",
                Type.getMethodDescriptor(Type.INT_TYPE, Type.getType(Object.class)), true);
        scope.gotoExitScope();
        mv2.visitLabel(leftIsNotComparable);
        scope.exec(scope.getLocal("$program").read());
        scope.exec(left.read());
        scope.emitIntConstant((loc != null) ? loc.getLineNumber() : -1);
        scope.emitIntConstant((loc != null) ? loc.getCharacterOffset() : 0);
        mv2.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(ProgramInvocation.class),
                "notComparable", Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(Object.class),
                        Type.INT_TYPE, Type.INT_TYPE),
                false);
        // this bit is not reachable, notComparable throws
        mv2.visitInsn(Opcodes.ICONST_0);
        mv2.visitJumpInsn(Opcodes.GOTO, done);
        scope.endScope();
    }
    if (unified.nullPossible) {
        mv.visitJumpInsn(Opcodes.GOTO, done);
        mv.visitLabel(leftNull);
        mv.visitInsn(Opcodes.ICONST_M1);
        mv.visitJumpInsn(Opcodes.GOTO, done);
        mv.visitLabel(rightNull);
        mv.visitInsn(Opcodes.ICONST_1);
        mv.visitJumpInsn(Opcodes.GOTO, done);
        mv.visitLabel(bothNull);
        mv.visitInsn(Opcodes.ICONST_0);
    }
    mv.visitLabel(done);
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.EqualsExpression.java

@Override
public void generate(CodeEmitter code) {
    // a bit of a hack; should not need to go to dynamic invocation for this unless one arg is ANY
    MethodVisitor mv = code.getMethodVisitor();
    Label hasNull = new Label();
    CodeEmitter.Unification unified = code.unifiedEmit(leftExpr, rightExpr, hasNull);
    if (unified.type.isPrimitive()) {
        emitPrimitiveEquals(code, unified.type);
    } else {//  w w w.j  a  v a  2 s  . com
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Object.class), "equals",
                Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Object.class)), false);
        if (negate) {
            emitNegate(mv);
        }
    }
    if (unified.nullPossible) {
        Label done = new Label();
        mv.visitJumpInsn(Opcodes.GOTO, done);
        mv.visitLabel(hasNull);
        emitFalse(code);
        mv.visitLabel(done);
    }
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.EqualsExpression.java

private void emitComplexEquals(CodeEmitter code, int op) {
    MethodVisitor mv = code.getMethodVisitor();
    mv.visitInsn(op);//from  ww w.  j  a v a2  s.c om
    Label done = new Label();
    Label isTrue = new Label();
    mv.visitJumpInsn(Opcodes.IFEQ, isTrue);
    emitFalse(code);
    mv.visitJumpInsn(Opcodes.GOTO, done);
    mv.visitLabel(isTrue);
    emitTrue(code);
    mv.visitLabel(done);
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.EqualsExpression.java

private void emitIntEquals(CodeEmitter code) {
    Label done = new Label();
    MethodVisitor mv = code.getMethodVisitor();
    Label isTrue = new Label();
    mv.visitJumpInsn(Opcodes.IF_ICMPEQ, isTrue);
    emitFalse(code);//from w w w.  j a  va2 s .c  o m
    mv.visitJumpInsn(Opcodes.GOTO, done);
    mv.visitLabel(isTrue);
    emitTrue(code);
    mv.visitLabel(done);
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.EqualsExpression.java

private void emitNegate(MethodVisitor mv) {
    Label truth = new Label();
    Label skip = new Label();
    mv.visitJumpInsn(Opcodes.IFNE, truth);
    mv.visitInsn(Opcodes.ICONST_1);//from w  ww .  j  av a 2s  .c om
    mv.visitJumpInsn(Opcodes.GOTO, skip);
    mv.visitLabel(truth);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitLabel(skip);
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.LocalFrame.java

public LocalFrame() {
    startFrame = new Label();
    endFrame = new Label();
    top = 0;
    parent = null;
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.LocalFrame.java

public LocalFrame(LocalFrame parent) {
    this.parent = parent;
    this.top = parent.top;
    startFrame = new Label();
    endFrame = new Label();
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.MulticompareExpression.java

@Override
public void generate(CodeEmitter code) {
    CodeEmitter scope = code.createScope();
    MethodVisitor mv = scope.getMethodVisitor();
    AssignableValue var = scope.allocate(BaseTypeAdapter.INT32);
    for (BytecodeExpression expr : expressions) {
        Label areEqual = new Label();
        scope.exec(var.write(expr));
        scope.exec(var.read());
        mv.visitJumpInsn(Opcodes.IFEQ, areEqual);
        scope.exec(var.read());
        scope.gotoExitScope();/*from   w ww  . j a  v  a  2 s .c o m*/
        mv.visitLabel(areEqual);
    }
    mv.visitInsn(Opcodes.ICONST_0);
    scope.endScope();
}