diff options
Diffstat (limited to 'src/tilde.cpp')
| -rw-r--r-- | src/tilde.cpp | 115 |
1 files changed, 16 insertions, 99 deletions
diff --git a/src/tilde.cpp b/src/tilde.cpp index 7d7b028c1..e765a5c72 100644 --- a/src/tilde.cpp +++ b/src/tilde.cpp @@ -411,28 +411,27 @@ gb_internal bool cg_global_variables_create(cgModule *m) { // LLVMSetSection(g.value, alloc_cstring(permanent_allocator(), e->Variable.link_section)); } - size_t max_objects = 0; - tb_global_set_storage(m->mod, section, global, type_size_of(e->type), type_align_of(e->type), max_objects); cgGlobalVariable var = {}; var.var = g; var.decl = decl; if (decl->init_expr != nullptr) { - // TypeAndValue tav = type_and_value_of_expr(decl->init_expr); - // if (!is_type_any(e->type) && !is_type_union(e->type)) { - // if (tav.mode != Addressing_Invalid) { - // if (tav.value.kind != ExactValue_Invalid) { - // ExactValue v = tav.value; - // lbValue init = lb_const_value(m, tav.type, v); - // LLVMSetInitializer(g.value, init.value); - // var.is_initialized = true; - // } - // } - // } - // if (!var.is_initialized && is_type_untyped_nil(tav.type)) { - // var.is_initialized = true; - // } + TypeAndValue tav = type_and_value_of_expr(decl->init_expr); + + isize max_regions = cg_global_const_calculate_region_count(tav.value, e->type); + tb_global_set_storage(m->mod, section, global, type_size_of(e->type), type_align_of(e->type), max_regions); + + if (tav.mode != Addressing_Invalid && + tav.value.kind != ExactValue_Invalid) { + cg_global_const_add_region(m, tav.value, e->type, global, 0); + var.is_initialized = true; + } + if (!var.is_initialized && is_type_untyped_nil(tav.type)) { + var.is_initialized = true; + } + } else { + tb_global_set_storage(m->mod, section, global, type_size_of(e->type), type_align_of(e->type), 0); } array_add(&global_variables, var); @@ -443,89 +442,7 @@ gb_internal bool cg_global_variables_create(cgModule *m) { - if (build_context.no_rtti) { - return already_has_entry_point; - } - - CheckerInfo *info = m->info; - { // Add type info data - isize max_type_info_count = info->minimum_dependency_type_info_set.count+1; - // gb_printf_err("max_type_info_count: %td\n", max_type_info_count); - Type *t = alloc_type_array(t_type_info, max_type_info_count); - - TB_Global *g = tb_global_create(m->mod, -1, CG_TYPE_INFO_DATA_NAME, nullptr, TB_LINKAGE_PRIVATE); - tb_global_set_storage(m->mod, tb_module_get_rdata(m->mod), g, type_size_of(t), 16, max_type_info_count); - - cgValue value = cg_value(g, alloc_type_pointer(t)); - cg_global_type_info_data_entity = alloc_entity_variable(nullptr, make_token_ident(CG_TYPE_INFO_DATA_NAME), t, EntityState_Resolved); - cg_add_entity(m, cg_global_type_info_data_entity, value); - } - - { // Type info member buffer - // NOTE(bill): Removes need for heap allocation by making it global memory - isize count = 0; - - for (Type *t : m->info->type_info_types) { - isize index = cg_type_info_index(m->info, t, false); - if (index < 0) { - continue; - } - - switch (t->kind) { - case Type_Union: - count += t->Union.variants.count; - break; - case Type_Struct: - count += t->Struct.fields.count; - break; - case Type_Tuple: - count += t->Tuple.variables.count; - break; - } - } - - if (count > 0) { - { - char const *name = CG_TYPE_INFO_TYPES_NAME; - Type *t = alloc_type_array(t_type_info_ptr, count); - TB_Global *g = tb_global_create(m->mod, -1, name, nullptr, TB_LINKAGE_PRIVATE); - tb_global_set_storage(m->mod, tb_module_get_rdata(m->mod), g, type_size_of(t), 16, count*2); - cg_global_type_info_member_types = cg_addr(cg_value(g, alloc_type_pointer(t))); - } - { - char const *name = CG_TYPE_INFO_NAMES_NAME; - Type *t = alloc_type_array(t_string, count); - TB_Global *g = tb_global_create(m->mod, -1, name, nullptr, TB_LINKAGE_PRIVATE); - tb_global_set_storage(m->mod, tb_module_get_rdata(m->mod), g, type_size_of(t), 16, count*2); - cg_global_type_info_member_names = cg_addr(cg_value(g, alloc_type_pointer(t))); - } - { - char const *name = CG_TYPE_INFO_OFFSETS_NAME; - Type *t = alloc_type_array(t_uintptr, count); - TB_Global *g = tb_global_create(m->mod, -1, name, nullptr, TB_LINKAGE_PRIVATE); - tb_global_set_storage(m->mod, tb_module_get_rdata(m->mod), g, type_size_of(t), 16, count); - cg_global_type_info_member_offsets = cg_addr(cg_value(g, alloc_type_pointer(t))); - } - - { - char const *name = CG_TYPE_INFO_USINGS_NAME; - Type *t = alloc_type_array(t_bool, count); - TB_Global *g = tb_global_create(m->mod, -1, name, nullptr, TB_LINKAGE_PRIVATE); - tb_global_set_storage(m->mod, tb_module_get_rdata(m->mod), g, type_size_of(t), 16, count); - cg_global_type_info_member_usings = cg_addr(cg_value(g, alloc_type_pointer(t))); - } - - { - char const *name = CG_TYPE_INFO_TAGS_NAME; - Type *t = alloc_type_array(t_string, count); - TB_Global *g = tb_global_create(m->mod, -1, name, nullptr, TB_LINKAGE_PRIVATE); - tb_global_set_storage(m->mod, tb_module_get_rdata(m->mod), g, type_size_of(t), 16, count*2); - cg_global_type_info_member_tags = cg_addr(cg_value(g, alloc_type_pointer(t))); - } - } - - cg_setup_type_info_data(m); - } + cg_setup_type_info_data(m); return already_has_entry_point; } |