Begin fixing type info stuff

This commit is contained in:
gingerBill
2024-04-30 11:01:10 +01:00
parent d04039ba43
commit ac9919b8e2
3 changed files with 32 additions and 13 deletions

View File

@@ -679,6 +679,13 @@ gb_internal String cg_filepath_obj_for_module(cgModule *m, bool use_assembly) {
build_context.build_paths[BuildPath_Output].name
);
#if defined(GB_SYSTEM_WINDOWS)
for (isize i = 0; i < path.len; i++) {
if (path.text[i] == '/') {
path.text[i] = '\\';
}
}
#endif
// if (m->file) {
// char buf[32] = {};
// isize n = gb_snprintf(buf, gb_size_of(buf), "-%u", m->file->id);
@@ -861,12 +868,13 @@ gb_internal bool cg_generate_code(Checker *c, LinkerData *linker_data) {
TB_Arena *export_arena = tb_arena_create(0);
defer (tb_arena_destroy(export_arena));
TB_ExportBuffer export_buffer = tb_module_object_export(m->mod, export_arena, debug_format);
String filepath_obj = cg_filepath_obj_for_module(m, false);
array_add(&linker_data->output_object_paths, filepath_obj);
TB_ExportBuffer export_buffer = tb_module_object_export(m->mod, export_arena, debug_format);
GB_ASSERT(tb_export_buffer_to_file(export_buffer, cast(char const *)filepath_obj.text));
array_add(&linker_data->output_object_paths, filepath_obj);
return true;
}

View File

@@ -381,8 +381,8 @@ gb_internal WORKER_TASK_PROC(cg_procedure_compile_worker_proc) {
cgProcedure *p = cast(cgProcedure *)data;
gb_unused(p);
tb_print(p->func, cg_arena());
fprintf(stdout, "\n");
// tb_print(p->func, cg_arena());
// fprintf(stdout, "\n");
// bool preserve_types = true;
// tb_opt(p->func, cg_worklist(), preserve_types);

View File

@@ -287,13 +287,10 @@ gb_internal void cg_setup_type_info_data(cgModule *m) {
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);
i64 max_objects = cast(i64)max_type_info_count * cg_global_const_calculate_region_count_from_basic_type(t_type_info);
Type *t = alloc_type_array(t_type_info_ptr, 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_objects);
tb_global_set_storage(m->mod, tb_module_get_rdata(m->mod), g, type_size_of(t), 16, cast(i64)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);
@@ -319,6 +316,9 @@ gb_internal void cg_setup_type_info_data(cgModule *m) {
case Type_Struct:
count += t->Struct.fields.count;
break;
case Type_BitField:
count += t->BitField.fields.count;
break;
case Type_Tuple:
count += t->Tuple.variables.count;
break;
@@ -405,7 +405,6 @@ gb_internal void cg_setup_type_info_data(cgModule *m) {
entries_handled[0] = true;
i64 type_info_size = type_size_of(t_type_info);
i64 size_offset = type_offset_of(t_type_info, 0);
i64 align_offset = type_offset_of(t_type_info, 1);
i64 flags_offset = type_offset_of(t_type_info, 2);
@@ -441,9 +440,18 @@ gb_internal void cg_setup_type_info_data(cgModule *m) {
}
entries_handled[entry_index] = true;
TB_Global *global = type_table_array;
i64 offset = entry_index * type_info_size;
char ti_entry_name[64] = {};
gb_snprintf(ti_entry_name, 63, "__$ti-%td", entry_index+1);
TB_Global *global = tb_global_create(m->mod, -1, ti_entry_name, nullptr, TB_LINKAGE_PRIVATE);
tb_global_set_storage(m->mod, tb_module_get_rdata(m->mod), global,
type_size_of(t_type_info), 16,
cg_global_const_calculate_region_count_from_basic_type(t_type_info));
tb_global_add_symbol_reloc(m->mod, type_table_array, entry_index * build_context.ptr_size, cast(TB_Symbol *)global);
i64 offset = 0;
i64 size = type_size_of(t);
i64 align = type_align_of(t);
@@ -466,6 +474,9 @@ gb_internal void cg_setup_type_info_data(cgModule *m) {
Type *tag_type = nullptr;
switch (t->kind) {
default:
GB_PANIC("MISSING TYPE: %s", type_to_string(t));
break;
case Type_Named: {
// Type_Info_Named :: struct {
// name: string,