Package org.objectweb.asm.tree

Examples of org.objectweb.asm.tree.VarInsnNode


    testInstructionBetweenFrames(new IntInsnNode(Opcodes.BIPUSH, 123));
  }

  @Test
  public void testVarInsn() {
    testInstructionBetweenFrames(new VarInsnNode(Opcodes.ILOAD, 0));
  }
View Full Code Here


      if (m == null) {
        break l;
      }

      m.instructions.clear();
      m.instructions.add(new VarInsnNode(ALOAD, 1));
      m.instructions.add(new VarInsnNode(ILOAD, 2));
      m.instructions.add(new VarInsnNode(ILOAD, 3));
      m.instructions.add(new VarInsnNode(ILOAD, 4));
      m.instructions.add(new VarInsnNode(ALOAD, 5));
      m.instructions.add(new MethodInsnNode(INVOKESTATIC, "cofh/asm/HooksCore", "paneConnectsTo", sig, false));
      m.instructions.add(new InsnNode(IRETURN));

      m.localVariables = null;
View Full Code Here

        if (names[0].equals(mName) && "(Z)V".equals(m.desc)) {
          updated = true;
          for (int i = 0, e = m.instructions.size(); i < e; ++i) {
            AbstractInsnNode n = m.instructions.get(i);
            if (n.getOpcode() == RETURN) {
              m.instructions.insertBefore(n, new VarInsnNode(ALOAD, 0));
              m.instructions.insertBefore(n, new InsnNode(ICONST_0));
              m.instructions.insertBefore(n, new FieldInsnNode(PUTFIELD, name, names[1], "Z"));
              break;
            }
          }
View Full Code Here

            if (jmp == null || jmp2 == null) {
              break l;
            }

            // presently on stack: player.getHeldItem()
            m.instructions.insertBefore(mn, new VarInsnNode(ALOAD, 0));
            m.instructions.insertBefore(mn, new FieldInsnNode(GETFIELD, name, names[1], 'L' + itemstack + ';'));
            final String clazz = "cofh/asm/HooksCore";
            final String method = "areItemsEqualHook";
            final String sign = "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z";
            m.instructions.insertBefore(mn, new MethodInsnNode(INVOKESTATIC, clazz, method, sign, false));
View Full Code Here

      if (m == null) {
        break l;
      }

      m.instructions.clear();
      m.instructions.add(new VarInsnNode(ALOAD, 0));
      m.instructions.add(new FieldInsnNode(GETFIELD, name, names[1], "Ljava/util/List;"));
      m.instructions.add(new VarInsnNode(ALOAD, 1));
      m.instructions.add(new VarInsnNode(ILOAD, 2));
      m.instructions.add(new VarInsnNode(ILOAD, 3));
      m.instructions.add(new VarInsnNode(ILOAD, 4));
      m.instructions.add(new InsnNode(ICONST_0));
      m.instructions.add(new MethodInsnNode(INVOKESTATIC, "cofh/lib/util/helpers/InventoryHelper", "mergeItemStack",
          "(Ljava/util/List;Lnet/minecraft/item/ItemStack;IIZZ)Z", false));
      m.instructions.add(new InsnNode(IRETURN));
View Full Code Here

        AbstractInsnNode n = m.instructions.getFirst();
        while (n.getOpcode() != INVOKESPECIAL ||
            !((MethodInsnNode)n).name.equals("<init>")) n = n.getNext();
        m.instructions.insert(n, n = a);
        m.instructions.insert(n, n = new LineNumberNode(-15000, a));
        m.instructions.insert(n, n = new VarInsnNode(ALOAD, 0));
        m.instructions.insert(n, n = new TypeInsnNode(NEW, "cofh/lib/util/LinkedHashList"));
        m.instructions.insert(n, n = new InsnNode(DUP));
        m.instructions.insert(n, n = new MethodInsnNode(INVOKESPECIAL, "cofh/lib/util/LinkedHashList", "<init>", "()V", false));
        m.instructions.insert(n, n = new FieldInsnNode(PUTFIELD, "net/minecraft/world/World", "cofh_recentTiles", "Lcofh/lib/util/LinkedHashList;"));
      } else if ("addTileEntity".equals(m.name) && "(Lnet/minecraft/tileentity/TileEntity;)V".equals(remapper.mapMethodDesc(m.desc))) {
        addTileEntity = m;
      } else if (names[4].equals(remapper.mapMethodName(name, m.name, m.desc)) && "(Ljava/util/Collection;)V".equals(m.desc)) {
        addTileEntities = m;
      } else if (names[5].equals(remapper.mapMethodName(name, m.name, m.desc)) && "(IIILnet/minecraft/tileentity/TileEntity;)V".equals(remapper.mapMethodDesc(m.desc))) {
        setTileEntity = m;
      } else if (names[6].equals(remapper.mapMethodName(name, m.name, m.desc)) && "()V".equals(remapper.mapMethodDesc(m.desc))) {
        updateEntities = m;
      }
    }
    cn.fields.add(new FieldNode(ACC_PRIVATE, "cofh_recentTiles", "Lcofh/lib/util/LinkedHashList;", null, null));
    if (addTileEntity != null) {

      LabelNode a = new LabelNode(new Label());
      AbstractInsnNode n;
      addTileEntity.instructions.insert(n = a);
      addTileEntity.instructions.insert(n, n = new LineNumberNode(-15001, a));
      addTileEntity.instructions.insert(n, n = new VarInsnNode(ALOAD, 0));
      addTileEntity.instructions.insert(n, n = new FieldInsnNode(GETFIELD, "net/minecraft/world/World", "cofh_recentTiles", "Lcofh/lib/util/LinkedHashList;"));
      addTileEntity.instructions.insert(n, n = new VarInsnNode(ALOAD, 1));
      addTileEntity.instructions.insert(n, n = new MethodInsnNode(INVOKEVIRTUAL, "cofh/lib/util/LinkedHashList", "push", "(Ljava/lang/Object;)Z", false));
      addTileEntity.instructions.insert(n, n = new InsnNode(POP));
    }
    if (setTileEntity != null) {

      LabelNode a = new LabelNode(new Label());
      AbstractInsnNode n = setTileEntity.instructions.getLast();
      while (n.getOpcode() != RETURN) n = n.getPrevious();
      n = n.getPrevious();
      setTileEntity.instructions.insert(n = a);
      setTileEntity.instructions.insert(n, n = new LineNumberNode(-15002, a));
      setTileEntity.instructions.insert(n, n = new VarInsnNode(ALOAD, 0));
      setTileEntity.instructions.insert(n, n = new FieldInsnNode(GETFIELD, "net/minecraft/world/World", "cofh_recentTiles", "Lcofh/lib/util/LinkedHashList;"));
      setTileEntity.instructions.insert(n, n = new VarInsnNode(ALOAD, 4));
      setTileEntity.instructions.insert(n, n = new MethodInsnNode(INVOKEVIRTUAL, "cofh/lib/util/LinkedHashList", "push", "(Ljava/lang/Object;)Z", false));
      setTileEntity.instructions.insert(n, n = new InsnNode(POP));
    }
    if (addTileEntities != null) {
      LabelNode a = new LabelNode(new Label());
      AbstractInsnNode n = addTileEntities.instructions.getFirst();
      for (;;) {
        while (n.getOpcode() != CHECKCAST) n = n.getNext();
        if (remapper.mapType(((TypeInsnNode)n).desc).equals("net/minecraft/tileentity/TileEntity"))
          break;
      }
      addTileEntities.instructions.insert(n, n = a);
      addTileEntities.instructions.insert(n, n = new LineNumberNode(-15003, a));
      addTileEntities.instructions.insert(n, n = new InsnNode(DUP));
      addTileEntities.instructions.insert(n, n = new VarInsnNode(ALOAD, 0));
      addTileEntities.instructions.insert(n, n = new FieldInsnNode(GETFIELD, "net/minecraft/world/World", "cofh_recentTiles", "Lcofh/lib/util/LinkedHashList;"));
      addTileEntities.instructions.insert(n, n = new InsnNode(SWAP));
      addTileEntities.instructions.insert(n, n = new MethodInsnNode(INVOKEVIRTUAL, "cofh/lib/util/LinkedHashList", "push", "(Ljava/lang/Object;)Z", false));
      addTileEntities.instructions.insert(n, n = new InsnNode(POP));
    }
    if (updateEntities != null) {
      AbstractInsnNode n = updateEntities.instructions.getFirst();
      while (n.getOpcode() != INVOKEVIRTUAL ||
          !"onChunkUnload".equals(((MethodInsnNode)n).name) ||
          !"()V".equals(((MethodInsnNode)n).desc)) n = n.getNext();
      while (n.getOpcode() != PUTFIELD) n = n.getNext();
      n = n.getPrevious().getPrevious();
      LabelNode lStart = new LabelNode(new Label());
      LabelNode lCond = new LabelNode(new Label());
      LabelNode lGuard = new LabelNode(new Label());
      LabelNode a = new LabelNode(new Label());
      updateEntities.instructions.insert(n, n = a);
      updateEntities.instructions.insert(n, n = new LineNumberNode(-15004, a));
      updateEntities.instructions.insert(n, n = new JumpInsnNode(GOTO, lCond));
      updateEntities.instructions.insert(n, n = lStart);
      updateEntities.instructions.insert(n, n = new FrameNode(F_SAME, 0, null, 0, null));
      updateEntities.instructions.insert(n, n = new VarInsnNode(ALOAD, 0));
      updateEntities.instructions.insert(n, n = new FieldInsnNode(GETFIELD, "net/minecraft/world/World", "cofh_recentTiles", "Lcofh/lib/util/LinkedHashList;"));
      updateEntities.instructions.insert(n, n = new MethodInsnNode(INVOKEVIRTUAL, "cofh/lib/util/LinkedHashList", "shift", "()Ljava/lang/Object;", false));
      updateEntities.instructions.insert(n, n = new TypeInsnNode(CHECKCAST, "net/minecraft/tileentity/TileEntity"));
      updateEntities.instructions.insert(n, n = new InsnNode(DUP));
      updateEntities.instructions.insert(n, n = new JumpInsnNode(IFNULL, lGuard));
      updateEntities.instructions.insert(n, n = new MethodInsnNode(INVOKEVIRTUAL, "net/minecraft/tileentity/TileEntity", "cofh_validate", "()V", false));
      updateEntities.instructions.insert(n, n = new InsnNode(ACONST_NULL));
      updateEntities.instructions.insert(n, n = lGuard);
      updateEntities.instructions.insert(n, n = new InsnNode(POP));
      updateEntities.instructions.insert(n, n = lCond);
      updateEntities.instructions.insert(n, n = new FrameNode(F_SAME, 0, null, 0, null));
      updateEntities.instructions.insert(n, n = new VarInsnNode(ALOAD, 0));
      updateEntities.instructions.insert(n, n = new FieldInsnNode(GETFIELD, "net/minecraft/world/World", "cofh_recentTiles", "Lcofh/lib/util/LinkedHashList;"));
      updateEntities.instructions.insert(n, n = new MethodInsnNode(INVOKEVIRTUAL, "cofh/lib/util/LinkedHashList", "size", "()I", false));
      updateEntities.instructions.insert(n, n = new JumpInsnNode(IFNE, lStart));
    }
View Full Code Here

        while(!(current instanceof InsnNode && ((InsnNode)current).getOpcode() == Opcodes.RETURN)) {
          current = current.getPrevious();
        }
        current = current.getPrevious();
        InsnList toAdd = new InsnList();
        toAdd.add(new VarInsnNode(Opcodes.ALOAD, 0));
        toAdd.add(new VarInsnNode(Opcodes.ALOAD, 1));
        toAdd.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "logisticspipes/proxy/buildcraft/BCPipeWireHooks", "updateSignalStateForColor", "(Lbuildcraft/transport/Pipe;Lbuildcraft/api/transport/PipeWire;)V"));
        toAdd.add(getLabelNode(new Label()));
        m.instructions.insert(current, toAdd);
      }
      if(m.name.equals("readNearbyPipesSignal")) {
        MethodNode mv = new MethodNode(Opcodes.ASM4, m.access, m.name, m.desc, m.signature, m.exceptions.toArray(new String[0])) {
          boolean handled = false;
          @Override
          public void visitInsn(int opcode) {
            if(!handled) {
              handled = true;
              super.visitVarInsn(Opcodes.ALOAD, 0);
              super.visitVarInsn(Opcodes.ALOAD, 1);
              super.visitMethodInsn(Opcodes.INVOKESTATIC, "logisticspipes/proxy/buildcraft/BCPipeWireHooks", "readNearbyPipesSignal_Pre", "(Lbuildcraft/transport/Pipe;Lbuildcraft/api/transport/PipeWire;)Z");
            } else {
              super.visitInsn(opcode);
            }
          }
        };

        m.accept(mv);
       
        InsnList list = mv.instructions;
        AbstractInsnNode current = list.getLast();
        while(!(current instanceof InsnNode && ((InsnNode)current).getOpcode() == Opcodes.RETURN)) {
          current = current.getPrevious();
        }
        current = current.getPrevious();
        InsnList toAdd = new InsnList();
        toAdd.add(new VarInsnNode(Opcodes.ALOAD, 0));
        toAdd.add(new VarInsnNode(Opcodes.ALOAD, 1));
        toAdd.add(new VarInsnNode(Opcodes.ILOAD, 2));
        toAdd.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "logisticspipes/proxy/buildcraft/BCPipeWireHooks", "readNearbyPipesSignal_Post", "(Lbuildcraft/transport/Pipe;Lbuildcraft/api/transport/PipeWire;Z)V"));
        toAdd.add(getLabelNode(new Label()));
        mv.instructions.insert(current, toAdd);
       
        node.methods.set(node.methods.indexOf(m), mv);
View Full Code Here

          for (MethodNode mn : classNode.methods)
          {
            if ( mn.name.equals( "func_146977_a" ) || (mn.name.equals( "a" ) && mn.desc.equals( "(Lzk;)V" )) )
            {
              MethodNode newNode = new MethodNode( Opcodes.ACC_PUBLIC, "func_146977_a_original", mn.desc, mn.signature, new String[0] );
              newNode.instructions.add( new VarInsnNode( Opcodes.ALOAD, 0 ) );
              newNode.instructions.add( new VarInsnNode( Opcodes.ALOAD, 1 ) );
              newNode.instructions.add( new MethodInsnNode( Opcodes.INVOKESPECIAL, classNode.name, mn.name, mn.desc, false ) );
              newNode.instructions.add( new InsnNode( Opcodes.RETURN ) );
              log( newNode.name + newNode.desc + " - New Method" );
              classNode.methods.add( newNode );
              break;
View Full Code Here

      // save stack
      for (int j= args.length - 1; j >= 0; j--)
      {
        Type type= args[j];

        doNew.add(new VarInsnNode(type.getOpcode(ISTORE), varOffset));
        varOffset+= type.getSize();
      }
      if (varOffset > maxLocals)
      {
        maxLocals= varOffset;
      }

      doNew.add(node1); // NEW

      if (requireDup)
        doNew.add(new InsnNode(DUP));

      // restore stack
      for (int j= 0; j < args.length; j++)
      {
        Type type= args[j];
        varOffset-= type.getSize();

        doNew.add(new VarInsnNode(type.getOpcode(ILOAD), varOffset));

        // clean up store to avoid memory leak?
        if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY)
        {
          updateMaxStack= updateMaxStack < 1 ? 1 : updateMaxStack; // an extra slot for ACONST_NULL

          doNew.add(new InsnNode(ACONST_NULL));

          doNew.add(new VarInsnNode(type.getOpcode(ISTORE), varOffset));
        }
      }
      instructions.insertBefore(nm, doNew);
      nm= doNew.getLast();
    }
View Full Code Here

        return this;
    }

    public MethodDefinition loadObject(int slot)
    {
        instructionList.add(new VarInsnNode(ALOAD, slot));
        return this;
    }
View Full Code Here

TOP

Related Classes of org.objectweb.asm.tree.VarInsnNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.