List of usage examples for org.objectweb.asm Label Label
public Label()
From source file:com.j2biz.pencil.asm.tree.LabelWrapper.java
License:Open Source License
public LabelWrapper() { this.label = new Label(); }
From source file:com.j2biz.pencil.asm.tree.LabelWrapper.java
License:Open Source License
public static LabelWrapper create() { return new LabelWrapper(new Label()); }
From source file:com.j2biz.pencil.asm.tree.LogMessageNode.java
License:Open Source License
/** * @param name/* w ww.j a va 2 s .c om*/ * @param template */ public LogMessageNode(final String name, final String template) { this.name = name; this.template = template; // TODO: isXXXEnabled() Methods are used by commons logging. // if you want to adapt this code for log4j, rewrite this code or // reimplement an own node. // --------------------------------------------------------------------------- isName = "is" + Character.toUpperCase(name.charAt(0)) + name.substring(1) + "Enabled"; // --------------------------------------------------------------------------- this.templateParser = Template.parse(this.template); this.complex = checkParser(this.templateParser); this.scopeStart = new Label(); this.scopeEnd = new Label(); }
From source file:com.j2biz.pencil.asm.tree.MethodInfoNode.java
License:Open Source License
public void addLogInitAtStaticBlock(ASMClassInfoNode classInfo) { addLabel(new Label()); addLdc(classInfo.getClassName());//from w w w . j a va 2 s . co m final MethodInsnNode methodInsn = new MethodInsnNode(Constants.INVOKESTATIC, "org/apache/commons/logging/LogFactory", "getLog", "(Ljava/lang/String;)Lorg/apache/commons/logging/Log;"); addInstruction(methodInsn); final FieldInsnNode fieldInsn = new FieldInsnNode(Constants.PUTSTATIC, LogTransformer.LOGGER_FIELD_NAME, classInfo.getClassName(), "Lorg/apache/commons/logging/Log;"); addInstruction(fieldInsn); }
From source file:com.j2biz.pencil.asm.tree.MethodInfoNode.java
License:Open Source License
public void insertLogInitInClearStaticBlock(ASMClassInfoNode classInfo) { final FieldInsnNode fieldInsn = new FieldInsnNode(Constants.PUTSTATIC, LogTransformer.LOGGER_FIELD_NAME, classInfo.getClassName(), "Lorg/apache/commons/logging/Log;"); addInstructionAtBeginning(fieldInsn); final MethodInsnNode methodInsn = new MethodInsnNode(Constants.INVOKESTATIC, "org/apache/commons/logging/LogFactory", "getLog", "(Ljava/lang/String;)Lorg/apache/commons/logging/Log;"); addInstructionAtBeginning(methodInsn); addLdcAtBeginning(classInfo.getClassName()); addLabelAtBeginning(new Label()); }
From source file:com.judoscript.jamaica.ASMJavaClassCreator.java
License:Open Source License
public Label getLabel(String label) throws JavaClassCreatorException { if (label == null) throw new JavaClassCreatorException("Label cannot be null."); Label l = labels.get(label);/*from w w w.j a v a 2 s . c om*/ if (l == null) { l = new Label(); labels.put(label, l); } return l; }
From source file:com.khubla.jvmbasic.jvmbasicc.compiler.analysis.lines.LinesDatabase.java
License:Open Source License
/** * add a label//from w w w . j a v a 2 s . co m */ private LineDeclaration addLine(LineContext lineContext, int codeLine, int basicLine) { if (null == getLine(basicLine)) { final LineDeclaration lineDeclaration = new LineDeclaration(lineContext, codeLine, basicLine, new Label()); lines.put(basicLine, lineDeclaration); return lineDeclaration; } else { return null; } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.ifstmtRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {//from www. j a v a 2 s . c om if (generationContext.getParseTree().getChildCount() == 4) { /* * dispatch into the test */ final GenerationContext testGenerationContext = new GenerationContext(generationContext, generationContext.getParseTree().getChild(1)); Dispatcher.dispatchChildren(testGenerationContext); /* * check the result */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/khubla/jvmbasic/jvmbasicrt/Value", "getBoolean", "()Ljava/lang/Boolean;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z"); /* * check result */ final Label l1 = new Label(); generationContext.getMethodVisitor().visitJumpInsn(Opcodes.IFEQ, l1); /* * process the contained tree */ final GenerationContext statementGenerationContext = new GenerationContext(generationContext, generationContext.getParseTree().getChild(3)); Dispatcher.dispatch(statementGenerationContext); /* * label to skip to */ generationContext.getMethodVisitor().visitLabel(l1); generationContext.getMethodVisitor().visitFrame(Opcodes.F_SAME, 0, null, 0, null); return true; } else if (generationContext.getParseTree().getChildCount() == 3) { /* * dispatch into the test */ final GenerationContext testGenerationContext = new GenerationContext(generationContext, generationContext.getParseTree().getChild(1)); Dispatcher.dispatchChildren(testGenerationContext); /* * check the result */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/khubla/jvmbasic/jvmbasicrt/Value", "getBoolean", "()Ljava/lang/Boolean;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z"); /* * check result */ final Label l1 = new Label(); generationContext.getMethodVisitor().visitJumpInsn(Opcodes.IFEQ, l1); /* * process the contained tree */ final GenerationContext statementGenerationContext = new GenerationContext(generationContext, generationContext.getParseTree().getChild(2)); Dispatcher.dispatch(statementGenerationContext); /* * label to skip to */ generationContext.getMethodVisitor().visitLabel(l1); generationContext.getMethodVisitor().visitFrame(Opcodes.F_SAME, 0, null, 0, null); return true; } else { throw new Exception( "Invalid number of tokens in subtree '" + generationContext.getParseTree().getChildCount() + "' expected 3 on line number: " + generationContext.getLineNumber()); } } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.JVMBasicCompiler.java
License:Open Source License
/** * generate init./*www . jav a 2 s . c o m*/ * <p> * This inits the class members and assigns class members, such as the ExecutionContext. * </p> * <p> * <code> * public ExecutionContext executionContext = new ExecutionContext(); * </code> * </p> */ protected void generateInit(String className, ClassWriter classWriter) throws Exception { try { final MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); methodVisitor.visitCode(); /* * call init() */ final Label l0 = new Label(); methodVisitor.visitLabel(l0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); /* * create a new execution context and assign it */ final Label l1 = new Label(); methodVisitor.visitLabel(l1); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitTypeInsn(Opcodes.NEW, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "<init>", "()V"); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, className, RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); /* * return */ final Label l2 = new Label(); methodVisitor.visitLabel(l2); methodVisitor.visitLineNumber(8, l2); methodVisitor.visitInsn(Opcodes.RETURN); /* * declare variables */ final Label l3 = new Label(); methodVisitor.visitLabel(l3); methodVisitor.visitLocalVariable("this", "L" + className + ";", null, l0, l3, 0); methodVisitor.visitMaxs(3, 1); methodVisitor.visitEnd(); } catch (final Exception e) { throw new Exception("Exception in generateInit", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.JVMBasicCompiler.java
License:Open Source License
/** * generate void main(String[])/*from w ww .j a v a2 s . co m*/ * <p> * <code> * public static void main(String[] args) { * ExampleProgram exampleProgram = new ExampleProgram(); * try { * exampleProgram.inputStream = System.in; * exampleProgram.outputStream = System.out; * exampleProgram.program(); * } catch (Exception e) { * e.printStackTrace(); * } * } * </code> * </p> */ protected void generateMain(String classname, ClassWriter classWriter) throws Exception { try { /* * make method */ final MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); methodVisitor.visitCode(); final Label l0 = new Label(); final Label l1 = new Label(); final Label l2 = new Label(); methodVisitor.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception"); final Label l3 = new Label(); methodVisitor.visitLabel(l3); /* * declare a local instance of the class in the void() main, store as variable 1. */ methodVisitor.visitTypeInsn(Opcodes.NEW, classname); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, classname, "<init>", "()V"); methodVisitor.visitVarInsn(Opcodes.ASTORE, 1); /* * assign the input stream */ methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "in", "Ljava/io/InputStream;"); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, classname, "inputStream", "Ljava/io/InputStream;"); /* * assign the output stream */ methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, classname, "outputStream", "Ljava/io/PrintStream;"); /* * load the class instance from variable 1 and call "program" */ methodVisitor.visitLabel(l0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classname, "program", "()V"); methodVisitor.visitLabel(l1); final Label l4 = new Label(); methodVisitor.visitJumpInsn(Opcodes.GOTO, l4); methodVisitor.visitLabel(l2); methodVisitor.visitFrame(Opcodes.F_FULL, 2, new Object[] { "[Ljava/lang/String;", classname }, 1, new Object[] { "java/lang/Exception" }); methodVisitor.visitVarInsn(Opcodes.ASTORE, 2); final Label l5 = new Label(); methodVisitor.visitLabel(l5); methodVisitor.visitLineNumber(21, l5); methodVisitor.visitVarInsn(Opcodes.ALOAD, 2); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V"); /* * return */ methodVisitor.visitLabel(l4); methodVisitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null); methodVisitor.visitInsn(Opcodes.RETURN); /* * declare the parameters */ final Label l6 = new Label(); methodVisitor.visitLabel(l6); methodVisitor.visitLocalVariable("args", "[Ljava/lang/String;", null, l3, l6, 0); methodVisitor.visitLocalVariable("exampleProgram", "L" + classname + ";", null, l0, l6, 1); methodVisitor.visitLocalVariable("e", "Ljava/lang/Exception;", null, l5, l4, 2); /* * done */ methodVisitor.visitMaxs(2, 3); methodVisitor.visitEnd(); } catch (final Exception e) { throw new Exception("Exception in generateMain", e); } }