List of usage examples for org.objectweb.asm Opcodes RETURN
int RETURN
To view the source code for org.objectweb.asm Opcodes RETURN.
Click Source Link
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds an empty constructor.//from ww w .j ava2s. c o m * @param writer the target class * @param superClass the super class * @param body the constructor body */ public static void defineEmptyConstructor(ClassWriter writer, Class<?> superClass, Consumer<MethodVisitor> body) { MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE), null, null); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(superClass).getInternalName(), CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE), false); body.accept(method); method.visitInsn(Opcodes.RETURN); method.visitMaxs(0, 0); method.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds an adapter constructor./*from ww w. j a va 2 s .c o m*/ * @param writer the target class * @param superClass the super class * @param body the constructor body */ public static void defineAdapterConstructor(ClassWriter writer, Class<?> superClass, Consumer<MethodVisitor> body) { MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(VertexProcessorContext.class)), null, null); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitVarInsn(Opcodes.ALOAD, 1); method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(superClass).getInternalName(), CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(VertexProcessorContext.class)), false); body.accept(method); method.visitInsn(Opcodes.RETURN); method.visitMaxs(0, 0); method.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds {@link Result#add(Object)} method. * @param writer the current writer//from ww w. j a v a 2 s . c om * @param callback the callback */ public static void defineResultAdd(ClassVisitor writer, Consumer<MethodVisitor> callback) { MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, "add", Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class)), null, null); callback.accept(method); method.visitInsn(Opcodes.RETURN); method.visitMaxs(0, 0); method.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
private static List<Tuple<VertexElement, FieldRef>> defineDependenciesConstructor0(ClassDescription aClass, ClassVisitor writer, Iterable<? extends VertexElement> dependencies, Consumer<MethodVisitor> superConstructor, Consumer<MethodVisitor> callback) { List<Tuple<VertexElement, FieldRef>> results = new ArrayList<>(); int index = 0; int varIndex = 1; List<Type> parameterTypes = new ArrayList<>(); List<Consumer<MethodVisitor>> ctor = new ArrayList<>(); for (VertexElement element : dependencies) { int current = index++; int currentVar = varIndex; String name = getDependencyId(current); Type type = typeOf(element.getRuntimeType()); parameterTypes.add(type);// w w w. j a v a 2s. c om FieldRef ref = defineField(writer, aClass, name, type); ctor.add(v -> { v.visitVarInsn(Opcodes.ALOAD, 0); v.visitVarInsn(loadOpcodeOf(element.getRuntimeType()), currentVar); putField(v, ref); }); varIndex += categoryOf(element.getRuntimeType()); results.add(new Tuple<>(element, ref)); } MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, parameterTypes.stream().toArray(Type[]::new)), null, null); superConstructor.accept(method); ctor.forEach(c -> c.accept(method)); callback.accept(method); method.visitInsn(Opcodes.RETURN); method.visitMaxs(0, 0); method.visitEnd(); return results; }
From source file:com.asakusafw.dag.compiler.codegen.EdgeDataTableAdapterGenerator.java
License:Apache License
private static void defineBuildKey(ClassGeneratorContext context, ClassWriter writer, TypeDescription dataType, Group group) {/*from w ww.j a v a2s . com*/ DataModelReference type = context.getDataModelLoader().load(dataType); List<PropertyReference> props = group.getGrouping().stream() .map(p -> Invariants.requireNonNull(type.findProperty(p))).collect(Collectors.toList()); MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "buildKey", Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(KeyBuffer.class), typeOf(Object.class)), null, null); LocalVarRef key = new LocalVarRef(Opcodes.ALOAD, 1); LocalVarRef object = cast(v, 2, dataType); for (PropertyReference p : props) { key.load(v); object.load(v); getOption(v, p); v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(KeyBuffer.class).getInternalName(), "append", Type.getMethodDescriptor(typeOf(KeyBuffer.class), typeOf(Object.class)), true); v.visitInsn(Opcodes.POP); } v.visitInsn(Opcodes.RETURN); v.visitMaxs(0, 0); v.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.KeyValueSerDeGenerator.java
License:Apache License
private static void putSerialize(String methodName, DataModelReference reference, List<PropertyReference> properties, ClassWriter writer) { MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, methodName, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class), typeOf(DataOutput.class)), null, new String[] { typeOf(IOException.class).getInternalName(), typeOf(InterruptedException.class).getInternalName(), }); if (properties.isEmpty()) { LocalVarRef output = new LocalVarRef(Opcodes.ALOAD, 2); output.load(v);//from w w w. j av a 2 s . com getConst(v, 0); v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(DataOutput.class).getInternalName(), "writeByte", Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE), true); } else { LocalVarRef object = cast(v, 1, reference.getDeclaration()); LocalVarRef output = new LocalVarRef(Opcodes.ALOAD, 2); for (PropertyReference property : properties) { object.load(v); 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(); }
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 ww w.j a va2s. c o 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 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. jav a2 s . c om 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. ja v a2 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.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);//from www .j ava 2s .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(); }