コード例 #1
0
ファイル: WyilFileReader.java プロジェクト: ejrh/Whiley
  private Code readUnaryAssign(int opcode, boolean wideBase, boolean wideRest) throws IOException {
    int target = readBase(wideBase);

    int operand = readBase(wideBase);
    int typeIdx = readRest(wideRest);
    Type type = typePool[typeIdx];
    switch (opcode) {
      case Code.OPCODE_convert:
        {
          int i = readRest(wideRest);
          Type t = typePool[i];
          return Code.Convert(type, target, operand, t);
        }
      case Code.OPCODE_assign:
        return Code.Assign(type, target, operand);
      case Code.OPCODE_dereference:
        {
          if (!(type instanceof Type.Reference)) {
            throw new RuntimeException("expected reference type");
          }
          return Code.Dereference((Type.Reference) type, target, operand);
        }
      case Code.OPCODE_fieldload:
        {
          if (!(type instanceof Type.EffectiveRecord)) {
            throw new RuntimeException("expected record type");
          }
          int i = readRest(wideRest);
          String field = stringPool[i];
          return Code.FieldLoad((Type.EffectiveRecord) type, target, operand, field);
        }
      case Code.OPCODE_invert:
        return Code.Invert(type, target, operand);
      case Code.OPCODE_newobject:
        {
          if (!(type instanceof Type.Reference)) {
            throw new RuntimeException("expected reference type");
          }
          return Code.NewObject((Type.Reference) type, target, operand);
        }
      case Code.OPCODE_lengthof:
        {
          if (!(type instanceof Type.EffectiveCollection)) {
            throw new RuntimeException("expected collection type");
          }
          return Code.LengthOf((Type.EffectiveCollection) type, target, operand);
        }
      case Code.OPCODE_move:
        return Code.Move(type, target, operand);
      case Code.OPCODE_neg:
        return Code.UnArithOp(type, target, operand, Code.UnArithKind.NEG);
      case Code.OPCODE_numerator:
        return Code.UnArithOp(type, target, operand, Code.UnArithKind.NUMERATOR);
      case Code.OPCODE_denominator:
        return Code.UnArithOp(type, target, operand, Code.UnArithKind.DENOMINATOR);
      case Code.OPCODE_not:
        {
          if (!(type instanceof Type.Bool)) {
            throw new RuntimeException("expected bool type");
          }
          return Code.Not(target, operand);
        }
      case Code.OPCODE_tupleload:
        {
          if (!(type instanceof Type.EffectiveTuple)) {
            throw new RuntimeException("expected tuple type");
          }
          int index = readRest(wideRest);
          return Code.TupleLoad((Type.Tuple) type, target, operand, index);
        }
    }
    throw new RuntimeException("unknown opcode encountered (" + opcode + ")");
  }