1 23 24 package org.objectweb.fractal.julia.asm; 25 26 import org.objectweb.fractal.julia.loader.Initializable; 27 import org.objectweb.fractal.julia.loader.Tree; 28 29 import org.objectweb.asm.CodeVisitor; 30 31 import java.lang.reflect.Method ; 32 33 49 50 public class TraceCodeGenerator extends AbstractCodeGenerator 51 implements Initializable 52 { 53 54 57 58 private int type = IN; 59 60 64 70 71 public void initialize (final Tree args) { 72 String type = args.getSubTree(0).toString(); 73 if (type.equals("in")) { 74 this.type = IN; 75 } else if (type.equals("out")) { 76 this.type = OUT; 77 } else if (type.equals("inout")) { 78 this.type = IN_OUT; 79 } 80 } 81 82 86 public int init (final InterceptorClassGenerator icg) { 87 return type; 88 } 89 90 94 protected void generateInterceptionCodeBlock ( 95 final Method m, 96 final boolean pre, 97 final CodeVisitor cv, 98 final int formals) 99 { 100 cv.visitFieldInsn( 102 GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;"); 103 if (pre) { 104 cv.visitLdcInsn("Entering " + m); 106 } else { 107 cv.visitLdcInsn("Leaving " + m); 109 } 110 cv.visitMethodInsn( 112 INVOKEVIRTUAL, 113 "java/io/PrintStream", 114 "println", 115 "(Ljava/lang/String;)V"); 116 } 117 } 118 | Popular Tags |