Examples of Insn


Examples of com.android.dx.rop.code.Insn

            if (label < 0) {
                return null;
            }

            Insn insn
                    = method.getBlocks().labelToBlock(label).getInsns().get(0);

            if (insn.getOpcode().getOpcode() != RegOps.MOVE_RESULT_PSEUDO) {
                return null;
            } else {
                return insn.getResult();
            }
        }
View Full Code Here

Examples of erjang.beam.repr.Insn

public class Rewriter {
    public void rewriteFunctionBody(List<Insn> body, FunctionInfo sig) {
  ListIterator<Insn> it = body.listIterator();
  while (it.hasNext()) {
      final Insn insn = it.next();
      switch (insn.opcode()) {
      case call_fun: {
    int save_pos = savePos(it);
    boolean trigger = (it.hasNext() &&
           it.next().opcode() == BeamOpcode.deallocate &&
           it.hasNext() &&
View Full Code Here

Examples of erjang.beam.repr.Insn

    private void restorePos(ListIterator<Insn> it, int save_pos) {
  // Only works for restoring backwards.
  int i=0;
  while (it.previousIndex() >= save_pos) {
      int pi = it.previousIndex();
      Insn insn = it.previous(); i++;
  }
  if (it.nextIndex() <= save_pos) it.next(); // Turn iterator.
    }
View Full Code Here

Examples of erjang.beam.repr.Insn

        Arg tuple_reg = null;

        vis.visitBegin(exh);

        for (int insn_idx = 0; insn_idx < insns.size(); insn_idx++) {
          Insn insn_ = insns.get(insn_idx);
          BeamOpcode opcode = insn_.opcode();
          TypeMap type_map = this.map[insn_idx];

          switch (opcode) {
          case func_info: {
            Insn.AAI insn = (Insn.AAI)insn_;
            // log.finer("go: " + insn);
            vis.visitInsn(opcode, insn.getExtFun());
            break;
          }

          case fnegate:
            Insn.LSD insn = (Insn.LSD)insn_;
            EAtom name = opcode.symbol;
            int failLabel = decode_labelref(insn.label, type_map.exh);
            Arg[] in = new Arg[] {src_arg(insn_idx, insn.src)};
            Type[] inTypes = new Type[] {in[0].type};
            Arg out = dest_arg(insn_idx, insn.dest);

            BuiltInFunction bif = BIFUtil.getMethod("erlang", name.getName(), inTypes,
                failLabel != 0, true);

            vis.visitInsn(opcode, failLabel, in, out, bif);
            break;
          }
         
          case fconv:
          case fmove:
          case move: {
            Insn.SD insn = (Insn.SD)insn_;
            Arg src  = src_arg(insn_idx, insn.src);
            Arg dest = dest_arg(insn_idx, insn.dest);

            if (insns.size() > insn_idx+1) {
            Insn next_insn = insns.get(insn_idx+1);
            if (next_insn.opcode() == BeamOpcode.K_return) {
              vis.visitInsn(BeamOpcode.K_return, src);
              insn_idx += 1;
              break;
            }
            }
           
            if (dest.kind != Kind.F) {
              if (src.kind == Kind.F) {
                dest = new Arg(dest, EDOUBLE_TYPE);
              } else {
                dest = new Arg(dest, src.type);
              }
            } else {
              // arg2.kind == F
            }

            vis.visitInsn(opcode, src, dest);
            break;
          }

          case put_string: {
            Insn.ByD insn = (Insn.ByD)insn_;
            Arg src  = src_arg(insn_idx, insn.bin);
            Arg dest = dest_arg(insn_idx, insn.dest);
//             Arg arg1 = decode_arg(insn_idx, insn.elm(3));
//             Arg arg2 = decode_out_arg(insn_idx, insn.elm(4));
            dest = new Arg(dest, ESEQ_TYPE);
            vis.visitInsn(BeamOpcode.move, src, dest);
            break;
          }

          case fadd:
          case fsub:
          case fmul:
          case fdiv:
          {
            Insn.LSSD insn = (Insn.LSSD)insn_;
            EAtom name = opcode.symbol;
            int failLabel = decode_labelref(insn.label, type_map.exh);
            Arg[] in = new Arg[] {src_arg(insn_idx, insn.src1),
                        src_arg(insn_idx, insn.src2)};
            Type[] inTypes = new Type[] {in[0].type,
                           in[1].type};
            Arg out = dest_arg(insn_idx, insn.dest);

            BuiltInFunction bif = BIFUtil.getMethod("erlang", name.getName(), inTypes,
                failLabel != 0, true);

            vis.visitInsn(opcode, failLabel, in, out, bif);
            break;
          }

          case bif0:
          case bif1:
          case bif2:
          {
            Insn.Bif insn = (Insn.Bif)insn_;
            EAtom name = insn.ext_fun.fun;
            int failLabel = decode_labelref(insn.label, type_map.exh);
            SourceOperand[] srcs = insn.args;
            Arg[] in = src_args(insn_idx, srcs);
            Arg out  = dest_arg(insn_idx, insn.dest);

            BuiltInFunction bif = BIFUtil.getMethod("erlang", name.getName(),
                parmTypes(type_map, srcs),
                failLabel != 0, true);

            vis.visitInsn(opcode, failLabel, in, out, bif);
            break;
          }

           case gc_bif1:
           case gc_bif2:
           case gc_bif3:
          {
            Insn.GcBif insn = (Insn.GcBif)insn_;
            EAtom name = insn.ext_fun.fun;
            int failLabel = decode_labelref(insn.label, type_map.exh);
            SourceOperand[] srcs = insn.args;
            Arg[] in = src_args(insn_idx, srcs);
            Arg out  = dest_arg(insn_idx, insn.dest);

            // special case for X+1, 1+X, X-1.
            Int lop = null, rop = null;
            if (srcs.length==2
                && (((name==am_plus || name == am_minus) && (rop=srcs[1].testInt()) != null && rop.equals(1))
                 || (name==am_plus && (lop=srcs[0].testInt()) != null && lop.equals(1))))
            {
              if (name == am_plus) {
                Arg src = (lop == null) ? in[0] : in[1];
               
                vis.visitIncrement(src, out);
                break;
              } else if (name == am_minus) {
                Arg src = in[0];
                vis.visitDecrement(src, out);
                break;               
              }
            }
           
            BuiltInFunction bif = BIFUtil.getMethod("erlang", name.getName(),
                parmTypes(type_map, srcs),
                failLabel != 0, true);

            vis.visitInsn(opcode, failLabel, in, out, bif);
            break;
          }

          case is_tuple: {
           
            if (insn_idx+1 < insns.size()) {
            Insn next_insn = insns.get(insn_idx+1);
            if (next_insn.opcode() == BeamOpcode.test_arity) {
             
              int this_fail = decode_labelref(((Insn.L)insn_).label, this.map[insn_idx].exh);
              int next_fail = decode_labelref(((Insn.L)next_insn).label, this.map[insn_idx+1].exh);

              if (this_fail == next_fail) {
View Full Code Here

Examples of erjang.beam.repr.Insn

      }

      public void analyze0() {
        TypeMap current = initial;
        BeamOpcode last_opcode = BeamOpcode.NONE;
        Insn last_insn = null;

        map = new TypeMap[insns.size()];

        next_insn: for (int insn_idx = 0; insn_idx < insns.size(); insn_idx++) {

          update_max_regs(current);

          if (is_term(last_opcode)) {
            throw new Error("how did we get here then...? "
                + this.block_label + ":" + insn_idx);
          }

          map[insn_idx] = current;
          Insn insn_ = insns.get(insn_idx);
          BeamOpcode code = insn_.opcode();
          last_opcode = code; last_insn = insn_;
          /*
           * System.out.println(name + "(" + bb_label + "):" + i +
           * " :: " + current + "" + insn);
           */

          if (current.exh != null && may_terminate_exceptionally(code))
            addExceptionEdge(current);

          switch (code) {
          case fmove:
          case move: {
            Insn.SD insn = (Insn.SD) insn_;
            SourceOperand src = insn.src;
            DestinationOperand dst = insn.dest;

            Type srcType = getType(current, src);

            // Determine type after possible conversion:
            Type dstType = srcType;
            if (dst.testFReg() != null) {
              dstType = Type.DOUBLE_TYPE; // FRegs are always unboxed
            } else if (sizeof(current, src) > sizeof(current, dst)) { // Conversion needed
              if (srcType.equals(Type.DOUBLE_TYPE)) {
                dstType = EDOUBLE_TYPE; // Box
              } else {
                throw new Error("why?" + insn.toSymbolic()
                    + "; srcType="+getType(current,src));
              }
            }

            current = setType(current, dst, dstType);
            continue next_insn;
          }
          case put_string: {
            Insn.ByD insn = (Insn.ByD) insn_;
            DestinationOperand dst = insn.dest;
            current = setType(current, dst, ESEQ_TYPE);
            continue next_insn;
          }

          case jump: {
            Insn.L insn = (Insn.L) insn_;
            current = branch(current, insn.label, insn_idx);
            continue next_insn;

          }

          case send: {
            current.touchx(0, 2);
            current = current.setx(0, current.getx(1), FV.this);
            continue next_insn;
          }

          case fnegate: {
            Insn.LSD insn = (Insn.LSD)insn_;
            EAtom name = insn.opcode().symbol;
            SourceOperand[] parms = new SourceOperand[] {
              insn.src
            };
            Type type = getBifResult("erlang", name.getName(),
                         parmTypes(current, parms), false);
            current = setType(current, insn.dest, type);

            continue next_insn;
          }
          case fadd:
          case fsub:
          case fmul:
          case fdiv:
          {
            Insn.LSSD insn = (Insn.LSSD) insn_;
            EAtom name = insn.opcode().symbol;
            SourceOperand[] parms = new SourceOperand[] {
              insn.src1, insn.src2
            };
            Type type = getBifResult("erlang", name.getName(),
                         parmTypes(current, parms), false);
            current = setType(current, insn.dest, type);

            continue next_insn;
          }

           case gc_bif1:
           case gc_bif2:
           case gc_bif3:
          {
            // {gc_bif,BifName,F,Live,[A1,A2?],Reg};

            Insn.GcBif insn = (Insn.GcBif) insn_;
            boolean is_guard = (insn.label.nr != 0);

            current = branch(current, insn.label, insn_idx);

            EAtom name = insn.ext_fun.fun;
            SourceOperand[] parms = insn.argList();

            Type type = getBifResult("erlang", name.getName(),
                         parmTypes(current, parms), is_guard);

            current = setType(current, insn.dest, type);

            continue next_insn;
          }

          case bif0:
          case bif1:
          case bif2:
          {
            Insn.Bif insn = (Insn.Bif) insn_;
            current = branch(current, insn.label, insn_idx);

            EAtom name = insn.ext_fun.fun;
            SourceOperand[] parms = insn.argList();

            Type type = getBifResult("erlang", name.getName(),
                         parmTypes(current, parms), false);

            current = setType(current, insn.dest, type);

            continue next_insn;
          }


          case is_tuple: {
           
            if (insn_idx+1 < insns.size()) {
            Insn next_insn = insns.get(insn_idx+1);
            if (next_insn.opcode() == BeamOpcode.test_arity) {
             
              if (this.map[insn_idx+1] == null) {
                this.map[insn_idx+1] = this.map[insn_idx];
              }
             
View Full Code Here

Examples of erjang.beam.repr.Insn

                    ", hop:"+highestOpcode+
                    ", L:"+labelCnt+
                    ", f:"+funCnt);

    code = new ArrayList<Insn>();
    Insn insn;
    do {
      insn = readInstruction();
      code.add(insn);
    } while (insn.opcode() != BeamOpcode.int_code_end);
    }
View Full Code Here

Examples of erjang.beam.repr.Insn

      case if_end:
      case int_code_end:
      case fclearerror:
      case bs_init_writable:
      case on_load:
        return new Insn(opcode); // TODO: use static set of objects

        //---------- 1-ary ----------
            case line: {
        int i1 = readCodeInteger();
                int lineNo = -1;
View Full Code Here

Examples of org.apache.jdo.impl.enhancer.classfile.Insn

        }
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // generate empty method in case of datastore identity
        final String keyClassName = analyzer.getKeyClassName();
        if (keyClassName == null){
            // end of method body
            insn = insn.append(Insn.create(opc_return));

            final CodeAttribute codeAttr
                = new CodeAttribute(getCodeAttributeUtf8(),
                                    0, // maxStack
                                    2, // maxLocals
                                    begin,
                                    new ExceptionTable(),
                                    new AttributeVector());
            augmenter.addMethod(methodName, methodSig, accessFlags,
                                codeAttr, exceptAttr);
            return;
        }
        affirm(keyClassName != null);

        // check oid argument
        final ConstClass keyConstClass = pool.addClass(keyClassName);
        affirm(keyConstClass != null);
        insn = appendCheckVarInstanceOf(insn, 1, keyConstClass,
                                        JAVA_IllegalArgumentException_Path,
                                        "arg1");

        // downcast argument
        insn = insn.append(Insn.create(opc_aload_1));
        insn = insn.append(Insn.create(opc_checkcast, keyConstClass));
        insn = insn.append(Insn.create(opc_astore_2));

        // check argument or delegate to superclass
        final boolean isPCRoot = analyzer.isAugmentableAsRoot();
        if (!isPCRoot) {
            // call super.jdoCopyKeyFieldsToObjectId(oid)

            //^olsen: javac uses the truelly declaring class
            //final ConstClass superConstClass = classFile.superName();
            //affirm(superConstClass != null);
            //final String superClassName = superConstClass.asString();
            //affirm(superClassName != null);

            final String superClassName
                = analyzer.getPCSuperKeyOwnerClassName();
            affirm(superClassName != null);
            insn = insn.append(Insn.create(opc_aload_0));
            insn = insn.append(Insn.create(opc_aload_2));
            insn = insn.append(
                Insn.create(opc_invokespecial,
                            pool.addMethodRef(
                                superClassName,
                                methodName,
                                methodSig)));
        }
       
        // get types of and field references of the key fields
        final int keyFieldCount = analyzer.getKeyFieldCount();
        final ConstFieldRef[] keyFieldRefs = getKeyFieldRefs();
        final ConstFieldRef[] keyClassKeyFieldRefs = getKeyClassKeyFieldRefs();
        affirm(keyFieldRefs.length == keyFieldCount);
        affirm(keyClassKeyFieldRefs.length == keyFieldCount);

        // generate the assignment statements
        int maxFieldSize = 0;
        for (int i = 0; i < keyFieldCount; i++) {
            // assign key field
            final ConstFieldRef thisClassKeyRef = keyFieldRefs[i];
            final ConstFieldRef keyClassKeyRef = keyClassKeyFieldRefs[i];
            affirm(thisClassKeyRef != null);
            affirm(keyClassKeyRef != null);
            if (isToOid) {
                insn = insn.append(Insn.create(opc_aload_2));
                insn = insn.append(Insn.create(opc_aload_0));
                insn = insn.append(Insn.create(opc_getfield, thisClassKeyRef));
                insn = insn.append(Insn.create(opc_putfield, keyClassKeyRef));
            } else {
                insn = insn.append(Insn.create(opc_aload_0));
                insn = insn.append(Insn.create(opc_aload_2));
                insn = insn.append(Insn.create(opc_getfield, keyClassKeyRef));
                insn = insn.append(Insn.create(opc_putfield, thisClassKeyRef));
            }

            // compute stack demand
            final String sig
                = thisClassKeyRef.nameAndType().signature().asString();
            affirm(sig != null && sig.length() > 0);
            maxFieldSize = max(maxFieldSize, Descriptor.countFieldWords(sig));
        }

        // end of method body
        insn = insn.append(Insn.create(opc_return));

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                max(maxFieldSize + 1, 3), // maxStack
                                3, // maxLocals
View Full Code Here

Examples of org.apache.jdo.impl.enhancer.classfile.Insn

        }
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // generate empty method in case of datastore identity
        final String keyClassName = analyzer.getKeyClassName();
        if (keyClassName == null){
            // end of method body
            insn = insn.append(Insn.create(opc_return));

            final CodeAttribute codeAttr
                = new CodeAttribute(getCodeAttributeUtf8(),
                                    0, // maxStack
                                    3, // maxLocals
                                    begin,
                                    new ExceptionTable(),
                                    new AttributeVector());
            augmenter.addMethod(methodName, methodSig, accessFlags,
                                codeAttr, exceptAttr);
            return;
        }
        affirm(keyClassName != null);

        // check fm argument
        insn = appendCheckVarNonNull(insn, 1,
                                     JAVA_IllegalArgumentException_Path,
                                     "arg1");
       
        // check oid argument
        final ConstClass keyConstClass = pool.addClass(keyClassName);
        affirm(keyConstClass != null);
        insn = appendCheckVarInstanceOf(insn, 2, keyConstClass,
                                        JAVA_IllegalArgumentException_Path,
                                        "arg2");

        // downcast argument
        insn = insn.append(Insn.create(opc_aload_2));
        insn = insn.append(Insn.create(opc_checkcast, keyConstClass));
        insn = insn.append(Insn.create(opc_astore_3));

        // call super.jdoCopyKeyFieldsToObjectId(oid)
        final boolean isPCRoot = analyzer.isAugmentableAsRoot();
        if (!isPCRoot) {
            // call super.jdoCopyKeyFieldsToObjectId(oid)

            //^olsen: javac uses the truelly declaring class
            //final ConstClass superConstClass = classFile.superName();
            //affirm(superConstClass != null);
            //final String superClassName = superConstClass.asString();
            //affirm(superClassName != null);

            final String superClassName
                = analyzer.getPCSuperKeyOwnerClassName();
            insn = insn.append(Insn.create(opc_aload_0));
            insn = insn.append(Insn.create(opc_aload_1));
            insn = insn.append(Insn.create(opc_aload_3));
            insn = insn.append(
                Insn.create(opc_invokespecial,
                            pool.addMethodRef(
                                superClassName,
                                methodName,
                                methodSig)));
        }
       
        // get types of and field references of the key fields
        final int keyFieldCount = analyzer.getKeyFieldCount();
        final ConstFieldRef[] keyFieldRefs = getKeyFieldRefs();
        final ConstFieldRef[] keyClassKeyFieldRefs = getKeyClassKeyFieldRefs();
        affirm(keyFieldRefs.length == keyFieldCount);
        affirm(keyClassKeyFieldRefs.length == keyFieldCount);

        // generate the case-targets for the method calls
        final SizeHolder sizeHolder = new SizeHolder();
        if (isToOid) {
            insn = appendStatementsForCopyKeyFieldsToOid(insn, sizeHolder);
        } else {
            insn = appendStatementsForCopyKeyFieldsFromOid(insn, sizeHolder);
        }

        // end of method body
        insn = insn.append(Insn.create(opc_return));

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                max(sizeHolder.size
                                    + (isToOid ? 3 : 2), 3), // maxStack
View Full Code Here

Examples of org.apache.jdo.impl.enhancer.classfile.Insn

        affirm(methodSig != null);     
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        final ConstFieldRef fieldRef = getAnnotatedFieldRefs()[fieldIndex];
        affirm(fieldRef != null);
        final String sig = fieldRef.nameAndType().signature().asString();
        affirm(sig != null && sig.length() > 0);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.