List of usage examples for org.objectweb.asm MethodVisitor visitMethodInsn
public void visitMethodInsn(final int opcode, final String owner, final String name, final String descriptor, final boolean isInterface)
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds a value list on to the top of the stack. * @param method the current method visitor * @param values the array elements//from w w w .j av a 2s . c om */ public static void getList(MethodVisitor method, Collection<?> values) { getInt(method, values.size()); method.visitTypeInsn(Opcodes.ANEWARRAY, typeOf(Object.class).getInternalName()); int index = 0; for (Object value : values) { method.visitInsn(Opcodes.DUP); getInt(method, index++); getConst(method, value); method.visitInsn(Opcodes.AASTORE); } method.visitMethodInsn(Opcodes.INVOKESTATIC, typeOf(Arrays.class).getInternalName(), "asList", Type.getMethodDescriptor(typeOf(List.class), typeOf(Object[].class)), false); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds an new instance of the target type on to the top of the stack. * @param method the current method visitor * @param type the target type//w w w . j a v a2 s .c o m */ public static void getNew(MethodVisitor method, TypeDescription type) { Type t = typeOf(type); method.visitTypeInsn(Opcodes.NEW, t.getInternalName()); method.visitInsn(Opcodes.DUP); method.visitMethodInsn(Opcodes.INVOKESPECIAL, t.getInternalName(), CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE), false); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds a {@code get*Option()} method invocation. * @param method the target method//from w ww . j a v a 2 s. co m * @param property the target property */ public static void getOption(MethodVisitor method, PropertyReference property) { MethodDescription decl = property.getDeclaration(); assert decl.getParameterTypes().isEmpty(); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, decl.getDeclaringClass().getInternalName(), decl.getName(), Type.getMethodDescriptor(typeOf(property.getType())), false); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Invokes {@code ValueOption#isNull()}. * @param method the target method/*w w w . j a v a2s . com*/ * @param dataType the data type */ public static void getNullity(MethodVisitor method, TypeDescription dataType) { method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(dataType).getInternalName(), "isNull", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), false); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Invokes {@code ValueOption#copyFrom(ValueOption)}. * @param method the target method/* w w w. j a v a 2 s .c om*/ * @param dataType the data type */ public static void copyOption(MethodVisitor method, TypeDescription dataType) { method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(dataType).getInternalName(), "copyFrom", Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(dataType)), false); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Sets {@code null} to a {@code ValueOption}. * @param method the target method// w ww. j a va2 s .c o m */ public static void setNullOption(MethodVisitor method) { method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, VALUE_OPTION_TYPE.getInternalName(), "setNull", Type.getMethodDescriptor(typeOf(VALUE_OPTION_TYPE)), false); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Invokes {@code DataModel#reset()}.//from w ww. j a va 2 s. c o m * @param method the target method * @param dataType the data type */ public static void resetDataModel(MethodVisitor method, TypeDescription dataType) { method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(dataType).getInternalName(), "reset", Type.getMethodDescriptor(Type.VOID_TYPE), false); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Invokes {@code DataModel#copyFrom(DataModel)}. * @param method the target method//from w ww. j a va 2 s. c om * @param dataType the data type */ public static void copyDataModel(MethodVisitor method, TypeDescription dataType) { method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(dataType).getInternalName(), "copyFrom", Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(dataType)), false); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds {@link Result#add(Object)} method invocation. * @param method the current method visitor *//*from www .jav a2 s .c o m*/ public static void invokeResultAdd(MethodVisitor method) { method.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(RESULT_TYPE).getInternalName(), "add", Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class)), true); }
From source file:com.asakusafw.dag.compiler.codegen.DataComparatorGenerator.java
License:Apache License
private static void defineCompare(ClassWriter writer, DataModelReference reference, List<Group.Ordering> orderings) { MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "compare", DESC_COMPARE, null, new String[] { typeOf(IOException.class).getInternalName(), }); LocalVarRef a = new LocalVarRef(Opcodes.ALOAD, 1); LocalVarRef b = new LocalVarRef(Opcodes.ALOAD, 2); for (Group.Ordering ordering : orderings) { PropertyReference property = Invariants .requireNonNull(reference.findProperty(ordering.getPropertyName())); // int diff = ValueOptionSerDe.compareT({a, b}, {b, a}); switch (ordering.getDirection()) { case ASCENDANT: a.load(v);/* w w w . ja v a2 s. c o m*/ b.load(v); break; case DESCENDANT: b.load(v); a.load(v); break; default: throw new AssertionError(ordering); } v.visitMethodInsn(Opcodes.INVOKESTATIC, typeOf(ValueOptionSerDe.class).getInternalName(), Invariants.requireNonNull(METHOD_NAMES.get(property.getType())), DESC_COMPARE, false); LocalVarRef cmp = putLocalVar(v, Type.INT, 3); Label eq = new Label(); // if (diff != 0) { cmp.load(v); v.visitJumpInsn(Opcodes.IFEQ, eq); // return diff; cmp.load(v); v.visitInsn(Opcodes.IRETURN); // } @ eq v.visitLabel(eq); } getConst(v, 0); v.visitInsn(Opcodes.IRETURN); v.visitMaxs(0, 0); v.visitEnd(); }