List of usage examples for org.objectweb.asm Label Label
public Label()
From source file:com.weibo.lodil.mmap.impl.GenerateHugeArrays.java
License:Apache License
public static byte[] dumpImpl(final TypeModel tm) { final ClassWriter cw = new ClassWriter(0); FieldVisitor fv;//w w w . j a v a 2 s. c o m MethodVisitor mv; final String name = tm.bcType(); cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, name + "Impl", "Ljava/lang/Object;L" + name + ";L" + collections + "api/HugeElement<L" + name + ";>;Ljava/io/Externalizable;", "java/lang/Object", new String[] { name, collections + "api/HugeElement", "java/io/Externalizable" }); cw.visitSource(tm.getClass().getSimpleName() + "Impl.java", null); for (final FieldModel fm : tm.fields()) { fv = cw.visitField(ACC_PRIVATE, "m_" + fm.fieldName(), fm.bcLFieldType(), null, null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); final Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(30, l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); mv.visitInsn(RETURN); final Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + name + "Impl;", null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); } for (final FieldModel fm : tm.fields()) { mv = cw.visitMethod(ACC_PUBLIC, "set" + fm.titleFieldName(), "(" + fm.bcLFieldType() + ")V", null, null); mv.visitCode(); final Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(47, l0); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(loadFor(fm.bcType()), 1); mv.visitFieldInsn(PUTFIELD, name + "Impl", "m_" + fm.fieldName(), fm.bcLFieldType()); final Label l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(48, l1); mv.visitInsn(RETURN); final Label l2 = new Label(); mv.visitLabel(l2); mv.visitLocalVariable("this", "L" + name + "Impl;", null, l0, l2, 0); mv.visitLocalVariable("b", fm.bcLFieldType(), null, l0, l2, 1); mv.visitMaxs(1 + fm.bcFieldSize(), 1 + fm.bcFieldSize()); mv.visitEnd(); mv = cw.visitMethod(ACC_PUBLIC, "get" + fm.titleFieldName(), "()" + fm.bcLFieldType(), null, null); mv.visitCode(); final Label l3 = new Label(); mv.visitLabel(l3); mv.visitLineNumber(45, l3); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, name + "Impl", "m_" + fm.fieldName(), fm.bcLFieldType()); mv.visitInsn(returnFor(fm.bcType())); final Label l4 = new Label(); mv.visitLabel(l4); mv.visitLocalVariable("this", "L" + name + "Impl;", null, l3, l4, 0); mv.visitMaxs(1 + fm.bcFieldSize(), 1); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "index", "(J)V", null, null); mv.visitCode(); final Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(175, l0); mv.visitTypeInsn(NEW, "java/lang/UnsupportedOperationException"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>", "()V"); mv.visitInsn(ATHROW); final Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + name + "Impl;", null, l0, l1, 0); mv.visitLocalVariable("n", "J", null, l0, l1, 1); mv.visitMaxs(2, 3); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "index", "()J", null, null); mv.visitCode(); final Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(180, l0); mv.visitInsn(LCONST_0); mv.visitInsn(LRETURN); final Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + name + "Impl;", null, l0, l1, 0); mv.visitMaxs(2, 1); mv.visitEnd(); } appendToStringHashCodeEqualsCopyOf(tm, cw, name + "Impl", false); { mv = cw.visitMethod(ACC_PUBLIC, "hugeElementType", "()L" + collections + "api/HugeElementType;", null, null); mv.visitCode(); final Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(236, l0); mv.visitFieldInsn(GETSTATIC, collections + "api/HugeElementType", "BeanImpl", "L" + collections + "api/HugeElementType;"); mv.visitInsn(ARETURN); final Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + name + "Impl;", null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); } cw.visitEnd(); final byte[] bytes = cw.toByteArray(); // ClassReader cr = new ClassReader(bytes); // cr.accept(new ASMifierClassVisitor(new PrintWriter(System.out)), 0); return bytes; }
From source file:com.wordpress.thesolidsnake.bahasaku.target.jvm.BahasaKuVisitor.java
License:Apache License
public BahasaKuVisitor(File sourceFile, boolean enableTrace) { this.sourceFile = sourceFile; if (!sourceFile.getName().endsWith(".baku")) { throw new RuntimeException( "Nama source file [" + sourceFile.getName() + "] tidak diakhiri dengan .baku"); }//from www .j ava 2 s . co m this.namaSourceFile = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); this.enableTrace = enableTrace; this.namaVariabel = new ArrayList<>(); cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); if (enableTrace) { cv = new TraceClassVisitor(cw, new PrintWriter(System.out)); } else { cv = cw; } // Membuat sebuah class public dengan nama (tanpa package) sesuai dengan namaFile cv.visit(V1_7, ACC_PUBLIC + ACC_SUPER, namaSourceFile, null, "java/lang/Object", null); // Membuat method static void main(String[] args). // Seluruh implementasi kode program BahasaKu akan ada di method ini. mv = cv.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); mv.visitCode(); label0 = new Label(); mv.visitLabel(label0); }
From source file:com.wordpress.thesolidsnake.bahasaku.target.jvm.BahasaKuVisitor.java
License:Apache License
public void generateOutput() { mv.visitInsn(RETURN);// ww w .j a v a2 s . co m Label label = new Label(); mv.visitLabel(label); for (int i = 0; i < namaVariabel.size(); i++) { mv.visitLocalVariable(namaVariabel.get(i), "Ljava/lang/Object;", null, label0, label, i); } mv.visitMaxs(0, 0); mv.visitEnd(); cv.visitEnd(); Path targetFile = Paths.get(sourceFile.getAbsoluteFile().getParent().toString(), namaSourceFile + ".class"); System.out.println("Menghasilkan target file di lokasi: " + targetFile.toString() + "\n"); try { Files.write(targetFile, cw.toByteArray(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); } catch (Exception ex) { System.out.println("Terjadi kesalahan saat membuat file target!"); ex.printStackTrace(); } }
From source file:com.xruby.compiler.codegen.MethodGenerator.java
License:BSD License
public void returnIfBlockReturned() { dup();//from ww w . j a va 2 s .c om invokeVirtual(Types.RUBY_VALUE_TYPE, Method.getMethod("boolean returnedInBlock()")); Label after_return = new Label(); ifZCmp(GeneratorAdapter.EQ, after_return); returnValue();//TODO more error checking, may not in the method context mark(after_return); /*TODO if it is going to return any way, should not not check. Right now the code may look like: if(!rubyvalue5.returnedInBlock()) goto _L2; else goto _L1 _L1: return; _L2: return; */ }
From source file:com.xruby.compiler.codegen.MethodGenerator.java
License:BSD License
public void checkBreakedOrReturned(boolean is_in_block) { int value = newLocal(Types.RUBY_VALUE_TYPE); storeLocal(value);/*from w ww .j a va2 s. co m*/ invokeVirtual(Types.RUBY_BLOCK_TYPE, CgUtil.getMethod("breakedOrReturned", Type.BOOLEAN_TYPE)); Label after_return = new Label(); ifZCmp(GeneratorAdapter.EQ, after_return); if (is_in_block) { loadThis(); push(true); putField(Types.RUBY_BLOCK_TYPE, "__break__", Type.BOOLEAN_TYPE); } loadLocal(value); returnValue();//TODO more error checking, may not in the method context mark(after_return); loadLocal(value); }
From source file:com.xruby.compiler.codegen.RubyCompilerImpl.java
License:BSD License
public void visitMethodDefinitionDefaultParameters(int size) { assert (size > 0); //create a empty array if arg is null (avoid null reference) MethodGenerator mg = cg_.getMethodGenerator(); mg.loadArg(1);/*ww w. j a v a 2 s. c o m*/ Label label = new Label(); mg.ifNonNull(label); mg.ObjectFactory_createArray(size, 0, false); mg.storeArg(1); mg.mark(label); }
From source file:com.xruby.compiler.codegen.RubyCompilerImpl.java
License:BSD License
public Object visitMethodDefinitionDefaultParameterBegin(int index) { Label next_label = new Label(); MethodGenerator mg = cg_.getMethodGenerator(); mg.loadMethodPrameterLength();/*from w w w . ja v a 2 s. c om*/ mg.push(index); mg.ifICmp(GeneratorAdapter.GT, next_label); mg.loadArg(1); return next_label; }
From source file:com.xruby.compiler.codegen.RubyCompilerImpl.java
License:BSD License
public Object visitAfterIfCondition() { MethodGenerator mg = cg_.getMethodGenerator(); mg.RubyValue_isTrue();//www . j a v a 2 s . c om Label label = new Label(); mg.ifZCmp(GeneratorAdapter.EQ, label); return label; }
From source file:com.xruby.compiler.codegen.RubyCompilerImpl.java
License:BSD License
public Object visitAfterIfBody(Object next_label, Object end_label) { if (null == end_label) { end_label = new Label(); }/*from ww w .j av a2s . c o m*/ MethodGenerator mg = cg_.getMethodGenerator(); if (null != next_label) { mg.goTo((Label) end_label); mg.mark((Label) next_label); } else { mg.mark((Label) end_label); } return end_label; }
From source file:com.xruby.compiler.codegen.RubyCompilerImpl.java
License:BSD License
public Object visitAfterWhenCondition(Object case_value, boolean mrhs) { int i = (Integer) case_value; MethodGenerator mg = cg_.getMethodGenerator(); mg.loadLocal(i);/*from w w w . j a va 2 s.c o m*/ if (!mrhs) { mg.RubyAPI_testCaseEqual(); } else { mg.RubyAPI_testCaseEqual2(); } Label label = new Label(); mg.ifZCmp(GeneratorAdapter.EQ, label); return label; }