コード例 #1
0
ファイル: Decoder.java プロジェクト: vazexqi/WALA
  private static Instruction[] makeSimpleInstructions() {
    Instruction[] table = new Instruction[256];

    table[OP_aconst_null] = ConstantInstruction.make(TYPE_null, null);
    for (int i = OP_iconst_m1; i <= OP_iconst_5; i++) {
      table[i] = ConstantInstruction.make(TYPE_int, new Integer(i - OP_iconst_m1 - 1));
    }
    for (int i = OP_lconst_0; i <= OP_lconst_1; i++) {
      table[i] = ConstantInstruction.make(TYPE_long, new Long(i - OP_lconst_0));
    }
    for (int i = OP_fconst_0; i <= OP_fconst_2; i++) {
      table[i] = ConstantInstruction.make(TYPE_float, new Float(i - OP_fconst_0));
    }
    for (int i = OP_dconst_0; i <= OP_dconst_1; i++) {
      table[i] = ConstantInstruction.make(TYPE_double, new Double(i - OP_dconst_0));
    }

    for (int i = OP_iload_0; i <= OP_aload_3; i++) {
      table[i] = LoadInstruction.make(indexedTypes[(i - OP_iload_0) / 4], (i - OP_iload_0) % 4);
    }
    for (int i = OP_iaload; i <= OP_saload; i++) {
      table[i] = ArrayLoadInstruction.make(indexedTypes[i - OP_iaload]);
    }
    for (int i = OP_istore_0; i <= OP_astore_3; i++) {
      table[i] = StoreInstruction.make(indexedTypes[(i - OP_istore_0) / 4], (i - OP_istore_0) % 4);
    }
    for (int i = OP_iastore; i <= OP_sastore; i++) {
      table[i] = ArrayStoreInstruction.make(indexedTypes[i - OP_iastore]);
    }

    table[OP_pop] = PopInstruction.make(1);
    table[OP_dup] = DupInstruction.make(1, 0);
    table[OP_dup_x1] = DupInstruction.make(1, 1);
    table[OP_swap] = SwapInstruction.make();

    for (int i = OP_iadd; i <= OP_drem; i++) {
      table[i] =
          BinaryOpInstruction.make(
              indexedTypes[(i - OP_iadd) % 4],
              BinaryOpInstruction.Operator.values()[(i - OP_iadd) / 4]);
    }
    for (int i = OP_ineg; i <= OP_dneg; i++) {
      table[i] =
          UnaryOpInstruction.make(indexedTypes[i - OP_ineg], IUnaryOpInstruction.Operator.NEG);
    }
    for (int i = OP_ishl; i <= OP_lushr; i++) {
      table[i] =
          ShiftInstruction.make(
              indexedTypes[(i - OP_ishl) % 2],
              ShiftInstruction.Operator.values()[(i - OP_ishl) / 2]);
    }
    for (int i = OP_iand; i <= OP_lxor; i++) {
      table[i] =
          BinaryOpInstruction.make(
              indexedTypes[(i - OP_iand) % 2],
              BinaryOpInstruction.Operator.values()[
                  BinaryOpInstruction.Operator.AND.ordinal() + (i - OP_iand) / 2]);
    }

    for (int i = OP_i2l; i <= OP_d2f; i++) {
      table[i] =
          ConversionInstruction.make(
              indexedTypes[(i - OP_i2l) / 3],
              indexedTypes[skip((i - OP_i2l) % 3, (i - OP_i2l) / 3)]);
    }
    for (int i = OP_i2b; i <= OP_i2s; i++) {
      table[i] = ConversionInstruction.make(TYPE_int, indexedTypes[5 + (i - OP_i2b)]);
    }

    table[OP_lcmp] = ComparisonInstruction.make(TYPE_long, ComparisonInstruction.Operator.CMP);
    for (int i = OP_fcmpl; i <= OP_dcmpg; i++) {
      table[i] =
          ComparisonInstruction.make(
              indexedTypes[2 + (i - OP_fcmpl) / 2],
              ComparisonInstruction.Operator.values()[
                  ComparisonInstruction.Operator.CMPL.ordinal() + (i - OP_fcmpl) % 2]);
    }

    for (int i = OP_ireturn; i <= OP_areturn; i++) {
      table[i] = ReturnInstruction.make(indexedTypes[i - OP_ireturn]);
    }
    table[OP_return] = ReturnInstruction.make(TYPE_void);

    table[OP_athrow] = ThrowInstruction.make(false);

    table[OP_monitorenter] = MonitorInstruction.make(true);
    table[OP_monitorexit] = MonitorInstruction.make(false);

    table[OP_arraylength] = ArrayLengthInstruction.make();

    return table;
  }
コード例 #2
0
ファイル: StatementGenerator.java プロジェクト: sba1/teavm
 @Override
 public void visit(ArrayLengthInstruction insn) {
   assign(
       Expr.unary(UnaryOperation.LENGTH, Expr.var(insn.getArray().getIndex())),
       insn.getReceiver());
 }