Example #1
0
 @Override
 public Object visitPrintStatement(PrintStatement printStatement, Object arg) throws Exception {
   MethodVisitor mv = ((InheritedAttributes) arg).mv;
   Label l0 = new Label();
   mv.visitLabel(l0);
   mv.visitLineNumber(printStatement.firstToken.getLineNumber(), l0);
   mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
   printStatement.expression.visit(this, arg); // adds code to leave value
   // of expression on top of
   // stack.
   // Unless there is a good
   // reason to do otherwise,
   // pass arg down the tree
   String etype = printStatement.expression.getType();
   if (etype.equals("I") || etype.equals("Z") || etype.equals("Ljava/lang/String;")) {
     String desc = "(" + etype + ")V";
     mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", desc, false);
   } else {
     // mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "toString",
     // "()Ljava/lang/String;",false);
     mv.visitMethodInsn(
         INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/Object;)V", false);
   }
   return null;
 }
    @Override
    public void visitLineNumber(int lineNumber, Label start) {
      super.visitLineNumber(lineNumber, start);
      // TODO 1: Register that this line exists

      // TODO 2: Add byte code here which produces a method call to Registry.callLine()

    }
 @Override
 public void visitLineNumber(final int line, final Label start) {
   checkStartCode();
   checkEndCode();
   checkUnsignedShort(line, "Invalid line number");
   checkLabel(start, true, "start label");
   super.visitLineNumber(line, start);
 }
    public static byte[] dump() throws Exception {

      ClassWriter cw = new ClassWriter(0);
      MethodVisitor mv;

      cw.visit(52, ACC_PUBLIC + ACC_SUPER, "DummyBundleClass", null, "java/lang/Object", null);

      cw.visitSource("DummyBundleClass.java", null);

      {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(1, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        mv.visitInsn(RETURN);
        Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLocalVariable("this", "LDummyBundleClass;", null, l0, l1, 0);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
      }
      {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
        mv.visitCode();
        Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(4, l0);
        mv.visitInsn(RETURN);
        Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLocalVariable("args", "[Ljava/lang/String;", null, l0, l1, 0);
        mv.visitMaxs(0, 1);
        mv.visitEnd();
      }
      cw.visitEnd();

      return cw.toByteArray();
    }
  @Override
  public void visitLineNumber(int line, Label start) {
    _currentLine = line;
    _currentJump = 0;

    mv.visitLdcInsn(_owner);
    mv.visitIntInsn(Opcodes.SIPUSH, line);
    mv.visitMethodInsn(
        Opcodes.INVOKESTATIC, _TOUCH_UTIL_CLASS, "touch", "(Ljava/lang/String;I)V", false);

    super.visitLineNumber(line, start);
  }
Example #6
0
  @Test
  public void testLineNumberNegative() {
    Label l1 = new Label();
    sanitizer.visitCode();
    sanitizer.visitLineNumber(15, l1);
    sanitizer.visitInsn(Opcodes.RETURN);
    sanitizer.visitMaxs(0, 0);
    sanitizer.visitEnd();

    expected.visitInsn(Opcodes.RETURN);
    expected.visitMaxs(0, 0);
    expected.visitEnd();

    assertOutput();
  }
  /** {@inheritDoc} */
  @Override
  public void visitLineNumber(int line, Label start) {
    super.visitLineNumber(line, start);
    currentLine = line;

    if (methodName.equals("<clinit>")) return;

    if (!hadInvokeSpecial) return;

    mv.visitMethodInsn(
        Opcodes.INVOKESTATIC,
        PackageInfo.getNameWithSlash(ExecutionTracer.class),
        "checkTimeout",
        "()V",
        false);
  }
 public void visitLineNumber(int i, Label label) {
   System.out.println("visitLineNumber(" + i + ", " + label + ")");
   methodVisitor.visitLineNumber(i, label);
 }
Example #9
0
 public void visitLineNumber(int line, Label start) {
   visitor.visitLineNumber(line, start);
 }
Example #10
0
 @Override
 public void visitLineNumber(int line, Label start) {
   mtd.addDebugInfo(line);
   super.visitLineNumber(line, start);
 }
Example #11
0
  @Override
  public Object visitProgram(Program program, Object arg) throws Exception {
    className = program.JVMName;
    classDescriptor = 'L' + className + ';';
    cw.visit(
        52, // version
        ACC_PUBLIC + ACC_SUPER, // access codes
        className, // fully qualified classname
        null, // signature
        "java/lang/Object", // superclass
        new String[] {"cop5555sp15/Codelet"} // implemented interfaces
        );
    cw.visitSource(null, null); // maybe replace first argument with source
    // file name

    // create init method
    {
      MethodVisitor mv;
      mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
      mv.visitCode();
      Label l0 = new Label();
      mv.visitLabel(l0);
      mv.visitLineNumber(3, l0);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
      mv.visitInsn(RETURN);
      Label l1 = new Label();
      mv.visitLabel(l1);
      mv.visitLocalVariable("this", classDescriptor, null, l0, l1, 0);
      mv.visitMaxs(1, 1);
      mv.visitEnd();
    }

    // generate the execute method
    MethodVisitor mv =
        cw.visitMethod(
            ACC_PUBLIC,
            "execute", // name of top
            // level
            // method
            "()V", // descriptor: this method is parameterless with no
            // return value
            null, // signature.  This is null for us, it has to do with generic types
            null // array of strings containing exceptions
            );
    mv.visitCode();
    Label lbeg = new Label();
    mv.visitLabel(lbeg);
    mv.visitLineNumber(program.firstToken.lineNumber, lbeg);
    program.block.visit(this, new InheritedAttributes(mv));
    mv.visitInsn(RETURN);
    Label lend = new Label();
    mv.visitLabel(lend);
    mv.visitLocalVariable("this", classDescriptor, null, lbeg, lend, 0);
    mv.visitMaxs(0, 0); // this is required just before the end of a method.
    // It causes asm to calculate information about the
    // stack usage of this method.
    mv.visitEnd();

    cw.visitEnd();
    return cw.toByteArray();
  }