Beispiel #1
0
Expr*
Parser::on_float(Token tok)
{
  Type const* t = get_double_type();
  double v = tok.floating_symbol()->value();
  return init<Literal_expr>(tok.location(), t, v);
}
std::vector<DexField*> create_merger_fields(
    const DexType* owner, const std::vector<DexField*>& mergeable_fields) {
  std::vector<DexField*> res;
  size_t cnt = 0;
  for (const auto f : mergeable_fields) {
    auto type = f->get_type();
    std::string name;
    if (type == get_byte_type() || type == get_char_type() ||
        type == get_short_type() || type == get_int_type()) {
      type = get_int_type();
      name = "i";
    } else if (type == get_boolean_type()) {
      type = get_boolean_type();
      name = "z";
    } else if (type == get_long_type()) {
      type = get_long_type();
      name = "j";
    } else if (type == get_float_type()) {
      type = get_float_type();
      name = "f";
    } else if (type == get_double_type()) {
      type = get_double_type();
      name = "d";
    } else {
      static DexType* string_type = DexType::make_type("Ljava/lang/String;");
      if (type == string_type) {
        type = string_type;
        name = "s";
      } else {
        char t = type_shorty(type);
        always_assert(t == 'L' || t == '[');
        type = get_object_type();
        name = "l";
      }
    }

    name = name + std::to_string(cnt);
    auto field = static_cast<DexField*>(
        DexField::make_field(owner, DexString::make_string(name), type));
    field->make_concrete(ACC_PUBLIC);
    res.push_back(field);
    cnt++;
  }

  TRACE(TERA, 8, "  created merger fields %d \n", res.size());
  return res;
}
Beispiel #3
0
void MethodBlock::load_const(Location& loc, double value) {
  always_assert(loc.is_wide());
  DexInstruction* load = new DexInstruction(OPCODE_CONST_WIDE);
  load->set_dest(reg_num(loc));
  load->set_literal(value);
  loc.type = get_double_type();
  push_instruction(load);
}
    ObjectList<Type> Type::get_floating_types()
    {
        Type all_floating_types[] =
        {
            Type(get_float_type()),
            Type(get_double_type()),
            Type(get_long_double_type()),
        };

        return ObjectList<Type>(all_floating_types);
    }
Beispiel #5
0
Type* type_check_positive(Expr const* e1)
{
  if (is_reals_type(e1->type()))
    // FIXME: flip between int and doubles correctly
    return get_double_type();

  error("Expression not of integer or double type found in positive expression: ");
  print(e1);
  print("\n");

  return nullptr;
}
Beispiel #6
0
static void init_spu_types(void)
{
  V16QI_type_node = build_vector_type (intQI_type_node, 16);
  V8HI_type_node = build_vector_type (intHI_type_node, 16);
  V4SI_type_node = build_vector_type (intSI_type_node, 16);
  V2DI_type_node = build_vector_type (intDI_type_node, 16);
  V4SF_type_node = build_vector_type (float_type_node, 16);
  V2DF_type_node = build_vector_type (double_type_node, 16);

  unsigned_V16QI_type_node = build_vector_type (unsigned_intQI_type_node, 16);
  unsigned_V8HI_type_node = build_vector_type (unsigned_intHI_type_node, 16);
  unsigned_V4SI_type_node = build_vector_type (unsigned_intSI_type_node, 16);
  unsigned_V2DI_type_node = build_vector_type (unsigned_intDI_type_node, 16);

  spu_builtin_types[SPU_BTI_QUADWORD] = V16QI_type_node;

  spu_builtin_types[SPU_BTI_7] = get_signed_int_type();
  spu_builtin_types[SPU_BTI_S7] = get_signed_int_type();
  spu_builtin_types[SPU_BTI_U7] = get_signed_int_type();
  spu_builtin_types[SPU_BTI_S10] = get_signed_int_type();
  spu_builtin_types[SPU_BTI_S10_4] = get_signed_int_type();
  spu_builtin_types[SPU_BTI_U14] = get_signed_int_type();
  spu_builtin_types[SPU_BTI_16] = get_signed_int_type();
  spu_builtin_types[SPU_BTI_S16] = get_signed_int_type();
  spu_builtin_types[SPU_BTI_S16_2] = get_signed_int_type();
  spu_builtin_types[SPU_BTI_U16] = get_signed_int_type();
  spu_builtin_types[SPU_BTI_U16_2] = get_signed_int_type();
  spu_builtin_types[SPU_BTI_U18] = get_signed_int_type();

  spu_builtin_types[SPU_BTI_INTQI] = get_signed_char_type();
  spu_builtin_types[SPU_BTI_INTHI] = get_signed_short_int_type();
  spu_builtin_types[SPU_BTI_INTSI] = get_signed_int_type();
  spu_builtin_types[SPU_BTI_INTDI] = get_signed_long_long_int_type();
  spu_builtin_types[SPU_BTI_UINTQI] = get_unsigned_char_type();
  spu_builtin_types[SPU_BTI_UINTHI] = get_unsigned_short_int_type();
  spu_builtin_types[SPU_BTI_UINTSI] = get_unsigned_int_type();
  spu_builtin_types[SPU_BTI_UINTDI] = get_unsigned_long_long_int_type();

  spu_builtin_types[SPU_BTI_FLOAT] = get_float_type();
  spu_builtin_types[SPU_BTI_DOUBLE] = get_double_type();

  spu_builtin_types[SPU_BTI_VOID] = get_void_type();

  spu_builtin_types[SPU_BTI_PTR] = 
      get_cv_qualified_type(get_pointer_type(get_void_type()),
              CV_CONST | CV_VOLATILE);
}
Beispiel #7
0
	int get_scaled_double(const paramdsc* v, double& rc)
	{
		ISC_INT64 iv;
		int rct = get_int_type(v, iv);
		if (rct < 0)
			rct = get_double_type(v, rc);
		else
		{
			rc = static_cast<double>(iv);
			int scale = v->dsc_scale;
			for (; scale < 0; ++scale)
				rc /= 10;
			for (; scale > 0; --scale)
				rc *= 10;
		}
		return rct;
	}
Beispiel #8
0
Type* type_check_arithmetic(Expr const* e1, Expr const* e2)
{
  if (is_reals_type(e1->type())) {
    if (is_reals_type(e2->type()))
      return get_double_type();
    else {
      error("Expression not of integer or double type found in arithmetic expression: ");
      print(e2);
      print("\n");
    }
  }
  else {
      error("Expression not of integer or double type found in arithmetic expression: ");
      print(e1);
      print("\n");
  }

  return nullptr;
}
Beispiel #9
0
// Parse a primary type.
//
//    primary-type -> 'bool'
//                  | 'int'
//                  | 'char'
//                  | id-type
//                  | function-type
//
//    function-type -> '(' type-list ')' '->' type
//
//    type-list -> type | type-list ',' type
Type const*
Parser::primary_type()
{
  // id-type
  if (Token tok = match_if(identifier_tok))
    return on_id_type(tok);

  // bool
  else if (match_if(bool_kw))
    return get_boolean_type();

  // char
  else if (match_if(char_kw))
    return get_character_type();

  // int
  else if (match_if(int_kw))
    return get_integer_type();

  // uint
  else if (match_if(uint_kw))
    return get_integer_type(false);

  // short
  else if (match_if(short_kw))
    return get_integer_type(16);

  // ushort
  else if (match_if(ushort_kw))
    return get_integer_type(false, 16);

  // long
  else if (match_if(long_kw))
    return get_integer_type(64);

  // ulong
  else if (match_if(ulong_kw))
    return get_integer_type(false, 64);

  // int16
  else if (match_if(int16_kw))
    return get_integer_type(16);

  // uint16
  else if (match_if(uint16_kw))
    return get_integer_type(false, 16);

  // int32
  else if (match_if(int32_kw))
    return get_integer_type();

  // uint32
  else if (match_if(uint32_kw))
    return get_integer_type(false);

  // int64
  else if (match_if(int64_kw))
    return get_integer_type(64);

  // uint64
  else if (match_if(uint64_kw))
    return get_integer_type(false, 64);

  // float
  else if (match_if(float_kw))
      return get_float_type();

  // double
  else if (match_if(double_kw))
      return get_double_type();

  // function-type
  else if (match_if(lparen_tok)) {
    Type_seq ts;
    while (true) {
      ts.push_back(type());
      if (match_if(comma_tok))
        continue;
      else
        break;
    }
    match(rparen_tok);
    match(arrow_tok);
    Type const* t = type();
    return on_function_type(ts, t);
  }

  // error
  //
  // TODO: Make this a little less vague.
  else
    error("invalid type");
}