Exemplo n.º 1
0
static void platform_lp64(compile_t* c, reach_type_t* t)
{
  FIND_METHOD("lp64");
  start_function(c, m, c->ibool, &t->use_type, 1);

  LLVMValueRef result =
    LLVMConstInt(c->ibool, target_is_lp64(c->opt->triple), false);
  LLVMBuildRet(c->builder, result);
  codegen_finishfun(c);

  BOX_FUNCTION();
}
Exemplo n.º 2
0
static bool make_opaque_struct(compile_t* c, reach_type_t* t)
{
  switch(ast_id(t->ast))
  {
    case TK_NOMINAL:
    {
      switch(t->underlying)
      {
        case TK_INTERFACE:
        case TK_TRAIT:
          t->use_type = c->object_ptr;
          return true;

        default: {}
      }

      // Find the primitive type, if there is one.
      AST_GET_CHILDREN(t->ast, pkg, id);
      const char* package = ast_name(pkg);
      const char* name = ast_name(id);

      bool ilp32 = target_is_ilp32(c->opt->triple);
      bool llp64 = target_is_llp64(c->opt->triple);
      bool lp64 = target_is_lp64(c->opt->triple);

      if(package == c->str_builtin)
      {
        if(name == c->str_Bool)
          t->primitive = c->ibool;
        else if(name == c->str_I8)
          t->primitive = c->i8;
        else if(name == c->str_U8)
          t->primitive = c->i8;
        else if(name == c->str_I16)
          t->primitive = c->i16;
        else if(name == c->str_U16)
          t->primitive = c->i16;
        else if(name == c->str_I32)
          t->primitive = c->i32;
        else if(name == c->str_U32)
          t->primitive = c->i32;
        else if(name == c->str_I64)
          t->primitive = c->i64;
        else if(name == c->str_U64)
          t->primitive = c->i64;
        else if(name == c->str_I128)
          t->primitive = c->i128;
        else if(name == c->str_U128)
          t->primitive = c->i128;
        else if(ilp32 && name == c->str_ILong)
          t->primitive = c->i32;
        else if(ilp32 && name == c->str_ULong)
          t->primitive = c->i32;
        else if(ilp32 && name == c->str_ISize)
          t->primitive = c->i32;
        else if(ilp32 && name == c->str_USize)
          t->primitive = c->i32;
        else if(lp64 && name == c->str_ILong)
          t->primitive = c->i64;
        else if(lp64 && name == c->str_ULong)
          t->primitive = c->i64;
        else if(lp64 && name == c->str_ISize)
          t->primitive = c->i64;
        else if(lp64 && name == c->str_USize)
          t->primitive = c->i64;
        else if(llp64 && name == c->str_ILong)
          t->primitive = c->i32;
        else if(llp64 && name == c->str_ULong)
          t->primitive = c->i32;
        else if(llp64 && name == c->str_ISize)
          t->primitive = c->i64;
        else if(llp64 && name == c->str_USize)
          t->primitive = c->i64;
        else if(name == c->str_F32)
          t->primitive = c->f32;
        else if(name == c->str_F64)
          t->primitive = c->f64;
        else if(name == c->str_Pointer)
        {
          t->use_type = c->void_ptr;
          return true;
        }
        else if(name == c->str_Maybe)
        {
          t->use_type = c->void_ptr;
          return true;
        }
      }

      t->structure = LLVMStructCreateNamed(c->context, t->name);
      t->structure_ptr = LLVMPointerType(t->structure, 0);

      if(t->primitive != NULL)
        t->use_type = t->primitive;
      else
        t->use_type = t->structure_ptr;

      return true;
    }

    case TK_TUPLETYPE:
      t->primitive = LLVMStructCreateNamed(c->context, t->name);
      t->use_type = t->primitive;
      t->field_count = (uint32_t)ast_childcount(t->ast);
      return true;

    case TK_UNIONTYPE:
    case TK_ISECTTYPE:
      // Just a raw object pointer.
      t->use_type = c->object_ptr;
      return true;

    default: {}
  }

  assert(0);
  return false;
}
Exemplo n.º 3
0
static void number_conversions(compile_t* c)
{
  num_conv_t ilp32_conv[] =
  {
    {"I8", "i8", c->i8, 8, true, false},
    {"I16", "i16", c->i16, 16, true, false},
    {"I32", "i32", c->i32, 32, true, false},
    {"I64", "i64", c->i64, 64, true, false},

    {"U8", "u8", c->i8, 8, false, false},
    {"U16", "u16", c->i16, 16, false, false},
    {"U32", "u32", c->i32, 32, false, false},
    {"U64", "u64", c->i64, 64, false, false},
    {"I128", "i128", c->i128, 128, true, false},
    {"U128", "u128", c->i128, 128, false, false},

    {"ILong", "ilong", c->i32, 32, true, false},
    {"ULong", "ulong", c->i32, 32, false, false},
    {"ISize", "isize", c->i32, 32, true, false},
    {"USize", "usize", c->i32, 32, false, false},

    {"F32", "f32", c->f32, 32, false, true},
    {"F64", "f64", c->f64, 64, false, true},

    {NULL, NULL, NULL, false, false, false}
  };

  num_conv_t lp64_conv[] =
  {
    {"I8", "i8", c->i8, 8, true, false},
    {"I16", "i16", c->i16, 16, true, false},
    {"I32", "i32", c->i32, 32, true, false},
    {"I64", "i64", c->i64, 64, true, false},

    {"U8", "u8", c->i8, 8, false, false},
    {"U16", "u16", c->i16, 16, false, false},
    {"U32", "u32", c->i32, 32, false, false},
    {"U64", "u64", c->i64, 64, false, false},
    {"I128", "i128", c->i128, 128, true, false},
    {"U128", "u128", c->i128, 128, false, false},

    {"ILong", "ilong", c->i64, 64, true, false},
    {"ULong", "ulong", c->i64, 64, false, false},
    {"ISize", "isize", c->i64, 64, true, false},
    {"USize", "usize", c->i64, 64, false, false},

    {"F32", "f32", c->f32, 32, false, true},
    {"F64", "f64", c->f64, 64, false, true},

    {NULL, NULL, NULL, false, false, false}
  };

  num_conv_t llp64_conv[] =
  {
    {"I8", "i8", c->i8, 8, true, false},
    {"I16", "i16", c->i16, 16, true, false},
    {"I32", "i32", c->i32, 32, true, false},
    {"I64", "i64", c->i64, 64, true, false},

    {"U8", "u8", c->i8, 8, false, false},
    {"U16", "u16", c->i16, 16, false, false},
    {"U32", "u32", c->i32, 32, false, false},
    {"U64", "u64", c->i64, 64, false, false},
    {"I128", "i128", c->i128, 128, true, false},
    {"U128", "u128", c->i128, 128, false, false},

    {"ILong", "ilong", c->i32, 32, true, false},
    {"ULong", "ulong", c->i32, 32, false, false},
    {"ISize", "isize", c->i64, 64, true, false},
    {"USize", "usize", c->i64, 64, false, false},

    {"F32", "f32", c->f32, 32, false, true},
    {"F64", "f64", c->f64, 64, false, true},

    {NULL, NULL, NULL, false, false, false}
  };

  num_conv_t* conv = NULL;

  if(target_is_ilp32(c->opt->triple))
    conv = ilp32_conv;
  else if(target_is_lp64(c->opt->triple))
    conv = lp64_conv;
  else if(target_is_llp64(c->opt->triple))
    conv = llp64_conv;

  assert(conv != NULL);
  bool native128 = target_is_native128(c->opt->triple);

  for(num_conv_t* from = conv; from->type_name != NULL; from++)
  {
    for(num_conv_t* to = conv; to->type_name != NULL; to++)
      number_conversion(c, from, to, native128);
  }
}
Exemplo n.º 4
0
// Report whether the named platform attribute is true
bool os_is_target(const char* attribute, bool release, bool* out_is_target, pass_opt_t* options)
{
  pony_assert(attribute != NULL);
  pony_assert(out_is_target != NULL);
  pony_assert(options != NULL);

  if(!strcmp(attribute, OS_BSD_NAME))
  {
    *out_is_target = target_is_bsd(options->triple);
    return true;
  }

  if(!strcmp(attribute, OS_FREEBSD_NAME))
  {
    *out_is_target = target_is_freebsd(options->triple);
    return true;
  }

  if(!strcmp(attribute, OS_DRAGONFLY_NAME))
  {
    *out_is_target = target_is_dragonfly(options->triple);
    return true;
  }

  if(!strcmp(attribute, OS_LINUX_NAME))
  {
    *out_is_target = target_is_linux(options->triple);
    return true;
  }

  if(!strcmp(attribute, OS_MACOSX_NAME))
  {
    *out_is_target = target_is_macosx(options->triple);
    return true;
  }

  if(!strcmp(attribute, OS_WINDOWS_NAME))
  {
    *out_is_target = target_is_windows(options->triple);
    return true;
  }

  if(!strcmp(attribute, OS_POSIX_NAME))
  {
    *out_is_target = target_is_posix(options->triple);
    return true;
  }

  if(!strcmp(attribute, OS_X86_NAME))
  {
    *out_is_target = target_is_x86(options->triple);
    return true;
  }

  if(!strcmp(attribute, OS_ARM_NAME))
  {
    *out_is_target = target_is_arm(options->triple);
    return true;
  }

  if(!strcmp(attribute, OS_LP64_NAME))
  {
    *out_is_target = target_is_lp64(options->triple);
    return true;
  }

  if(!strcmp(attribute, OS_LLP64_NAME))
  {
    *out_is_target = target_is_llp64(options->triple);
    return true;
  }

  if(!strcmp(attribute, OS_ILP32_NAME))
  {
    *out_is_target = target_is_ilp32(options->triple);
    return true;
  }

  if(!strcmp(attribute, OS_NATIVE128_NAME))
  {
    *out_is_target = target_is_native128(options->triple);
    return true;
  }

  if(!strcmp(attribute, OS_DEBUG_NAME))
  {
    *out_is_target = !release;
    return true;
  }

  return false;
}