Example usage for org.objectweb.asm Opcodes ALOAD

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

Introduction

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

Prototype

int ALOAD

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

Click Source Link

Usage

From source file:com.asakusafw.dag.compiler.codegen.OperationAdapterGenerator.java

License:Apache License

/**
 * Generates {@link OperationAdapter} class.
 * @param context the current context/*from   ww  w.  ja  v  a2s . c o  m*/
 * @param operation the target operation
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, OperationSpec operation, ClassDescription target) {
    ClassDescription inner = addInner(context, operation, target);
    ClassWriter writer = newWriter(target, BasicOperationAdapter.class);
    defineAdapterConstructor(writer, BasicOperationAdapter.class, v -> {
        v.visitVarInsn(Opcodes.ALOAD, 0);
        getConst(v, inner);
        v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind",
                Type.getMethodDescriptor(typeOf(BasicOperationAdapter.class), typeOf(Class.class)), false);
        v.visitInsn(Opcodes.POP);
    });
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.codegen.OperationGenerator.java

License:Apache License

private static void addConstructor(ClassWriter writer, ClassDescription target, List<VertexElement> elements,
        Function<VertexElement, String> ids) {
    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(OperationAdapter.Context.class)), null, null);
    method.visitVarInsn(Opcodes.ALOAD, 0);
    method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(Object.class).getInternalName(), "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE), false);

    method.visitVarInsn(Opcodes.ALOAD, 0);
    method.visitVarInsn(Opcodes.ALOAD, 1);
    method.visitFieldInsn(Opcodes.PUTFIELD, target.getInternalName(), FIELD_CONTEXT,
            typeOf(OperationAdapter.Context.class).getDescriptor());

    for (VertexElement element : elements) {
        method.visitVarInsn(Opcodes.ALOAD, 0);
        method.visitMethodInsn(Opcodes.INVOKESPECIAL, target.getInternalName(), ids.apply(element),
                Type.getMethodDescriptor(Type.VOID_TYPE), false);
    }/*from   w w  w . j  a v a2  s. com*/
    method.visitInsn(Opcodes.RETURN);
    method.visitMaxs(0, 0);
    method.visitEnd();
}

From source file:com.asakusafw.dag.compiler.codegen.OperationGenerator.java

License:Apache License

private static void addProcessMethod(ClassWriter writer, ClassDescription target, OperationSpec graph) {
    VertexElement consumer = graph.getInput().getConsumer();
    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, "process",
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class)), null, null);
    method.visitVarInsn(Opcodes.ALOAD, 0);
    method.visitFieldInsn(Opcodes.GETFIELD, target.getInternalName(), graph.getId(consumer),
            typeOf(consumer.getRuntimeType()).getDescriptor());
    method.visitVarInsn(Opcodes.ALOAD, 1);
    invokeResultAdd(method);/*from   w  w w.j  a v  a 2 s. co  m*/
    method.visitInsn(Opcodes.RETURN);
    method.visitMaxs(0, 0);
    method.visitEnd();
}

From source file:com.asakusafw.dag.compiler.codegen.OperationGenerator.java

License:Apache License

private static void addElementMethods(ClassWriter writer, ClassDescription target, List<VertexElement> elements,
        Function<VertexElement, String> ids) {
    for (VertexElement element : elements) {
        String id = ids.apply(element);
        MethodVisitor method = writer.visitMethod(Opcodes.ACC_PRIVATE, id,
                Type.getMethodDescriptor(Type.VOID_TYPE), null, null);
        method.visitVarInsn(Opcodes.ALOAD, 0);
        switch (element.getElementKind()) {
        case VALUE:
            getValue(method, target, (ValueElement) element, ids);
            break;
        case OPERATOR:
        case AGGREGATE:
            getClass(method, target, (ClassNode) element, ids);
            break;
        case OUTPUT:
            getOutput(method, target, (OutputNode) element, ids);
            break;
        case DATA_TABLE:
            getDataTable(method, target, (DataTableNode) element, ids);
            break;
        case CONTEXT:
            getContext(method, target, ids);
            break;
        case EMPTY_DATA_TABLE:
            getEmptyDataTable(method, target, ids);
            break;
        default:/*from   w w  w  . j av a 2 s. co  m*/
            throw new AssertionError(element.getElementKind());
        }
        method.visitFieldInsn(Opcodes.PUTFIELD, target.getInternalName(), id,
                typeOf(element.getRuntimeType()).getDescriptor());
        method.visitInsn(Opcodes.RETURN);
        method.visitMaxs(0, 0);
        method.visitEnd();
    }
}

From source file:com.asakusafw.dag.compiler.codegen.OperationGenerator.java

License:Apache License

private static void getContext(MethodVisitor method, ClassDescription target,
        Function<VertexElement, String> ids) {
    method.visitVarInsn(Opcodes.ALOAD, 0);
    method.visitFieldInsn(Opcodes.GETFIELD, target.getInternalName(), FIELD_CONTEXT,
            typeOf(OperationAdapter.Context.class).getDescriptor());
}

From source file:com.asakusafw.dag.compiler.codegen.OperationGenerator.java

License:Apache License

private static void get(MethodVisitor method, ClassDescription target, VertexElement element,
        Function<VertexElement, String> ids) {
    method.visitVarInsn(Opcodes.ALOAD, 0);
    method.visitFieldInsn(Opcodes.GETFIELD, target.getInternalName(), ids.apply(element),
            typeOf(element.getRuntimeType()).getDescriptor());
}

From source file:com.asakusafw.dag.compiler.codegen.SupplierGenerator.java

License:Apache License

private static ClassData generate0(TypeDescription source, ClassDescription target) {
    ClassWriter writer = newWriter(target, Object.class, Supplier.class);
    defineEmptyConstructor(writer, Object.class);
    defineGetter(writer, typeOf(Object.class), "get", v -> {
        v.visitVarInsn(Opcodes.ALOAD, 0);
        v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "get",
                Type.getMethodDescriptor(typeOf(source)), false);
        v.visitInsn(Opcodes.ARETURN);//from   w  ww .  j a  va 2s. co  m
    });
    defineGetter(writer, typeOf(source), "get", v -> {
        getNew(v, source);
        v.visitInsn(Opcodes.ARETURN);
    });
    writer.visitEnd();
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.codegen.UnionRecordSerDeSupplierGenerator.java

License:Apache License

/**
 * Generates {@link UnionRecordSerDeSupplier} class.
 * @param context the current context/* w  ww.j  a  v  a2s.c o m*/
 * @param upstreams the upstream specifications
 * @param downstream the downstream specification
 * @param target the target class
 * @return the generated class data
 */
public static ClassData generate(ClassGeneratorContext context, List<Upstream> upstreams, Downstream downstream,
        ClassDescription target) {
    Arguments.requireNonNull(context);
    Arguments.requireNonNull(upstreams);
    Arguments.requireNonNull(downstream);
    ClassWriter writer = newWriter(target, UnionRecordSerDeSupplier.class);
    defineEmptyConstructor(writer, UnionRecordSerDeSupplier.class, v -> {
        LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
        self.load(v);
        upstreams.forEach(s -> {
            // this.upstream(tags, elementSerDe)
            getList(v, s.tags);
            getConst(v, s.element);
            v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(UnionRecordSerDeSupplier.class).getInternalName(),
                    "upstream", //$NON-NLS-1$
                    Type.getMethodDescriptor(typeOf(UnionRecordSerDeSupplier.class), typeOf(Collection.class),
                            typeOf(Class.class)),
                    false);
        });
        downstream.tags.forEach(s -> {
            // this.downstream(tag)
            getConst(v, s);
            v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(UnionRecordSerDeSupplier.class).getInternalName(),
                    "downstream", //$NON-NLS-1$
                    Type.getMethodDescriptor(typeOf(UnionRecordSerDeSupplier.class), typeOf(String.class)),
                    false);
        });
        v.visitInsn(Opcodes.POP);
    });
    writer.visitEnd();
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.codegen.ValueSerDeGenerator.java

License:Apache License

private static ClassData generate0(DataModelReference reference, ClassDescription target) {
    ClassWriter writer = newWriter(target, Object.class, ValueSerDe.class);
    FieldRef buffer = defineField(writer, target, "buffer", typeOf(reference));
    defineEmptyConstructor(writer, Object.class, v -> {
        v.visitVarInsn(Opcodes.ALOAD, 0);
        getNew(v, reference.getDeclaration());
        putField(v, buffer);//w ww.  j  av a  2  s  . c  o  m
    });
    putSerialize(reference, writer);
    putDeserialize(reference, buffer, writer);
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.codegen.ValueSerDeGenerator.java

License:Apache License

private static void putSerialize(DataModelReference reference, ClassWriter writer) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "serialize",
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class), typeOf(DataOutput.class)), null,
            new String[] { typeOf(IOException.class).getInternalName(),
                    typeOf(InterruptedException.class).getInternalName(), });
    LocalVarRef object = cast(v, 1, reference.getDeclaration());
    LocalVarRef output = new LocalVarRef(Opcodes.ALOAD, 2);
    for (PropertyReference property : reference.getProperties()) {
        object.load(v);/*w  w  w.ja v a  2 s .  co m*/
        getOption(v, property);
        output.load(v);
        v.visitMethodInsn(Opcodes.INVOKESTATIC, SERDE.getInternalName(), "serialize",
                Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(property.getType()), typeOf(DataOutput.class)),
                false);
    }
    v.visitInsn(Opcodes.RETURN);
    v.visitMaxs(0, 0);
    v.visitEnd();
}