mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-03 01:07:56 +00:00
Update Tilde for testing reg spill stuff
This commit is contained in:
115
src/tilde.cpp
115
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;
|
||||
}
|
||||
|
||||
@@ -256,6 +256,9 @@ gb_internal TB_Arena *cg_arena(void);
|
||||
gb_internal void cg_add_procedure_to_queue(cgProcedure *p);
|
||||
gb_internal void cg_setup_type_info_data(cgModule *m);
|
||||
|
||||
gb_internal isize cg_global_const_calculate_region_count(ExactValue const &value, Type *type);
|
||||
gb_internal bool cg_global_const_add_region(cgModule *m, ExactValue const &value, Type *type, TB_Global *global, i64 offset);
|
||||
|
||||
gb_internal cgValue cg_value(TB_Global * g, Type *type);
|
||||
gb_internal cgValue cg_value(TB_External *e, Type *type);
|
||||
gb_internal cgValue cg_value(TB_Function *f, Type *type);
|
||||
|
||||
BIN
src/tilde/tb.lib
BIN
src/tilde/tb.lib
Binary file not shown.
@@ -547,7 +547,7 @@ gb_internal cgValue cg_emit_comp(cgProcedure *p, TokenKind op_kind, cgValue left
|
||||
case Token_Gt: res = tb_inst_cmp_igt(p->func, lhs, rhs, is_signed); break;
|
||||
case Token_GtEq: res = tb_inst_cmp_ige(p->func, lhs, rhs, is_signed); break;
|
||||
case Token_Lt: res = tb_inst_cmp_ilt(p->func, lhs, rhs, is_signed); break;
|
||||
case Token_LtEq: res = tb_inst_cmp_ige(p->func, lhs, rhs, is_signed); break;
|
||||
case Token_LtEq: res = tb_inst_cmp_ile(p->func, lhs, rhs, is_signed); break;
|
||||
}
|
||||
|
||||
GB_ASSERT(res != nullptr);
|
||||
@@ -562,7 +562,7 @@ gb_internal cgValue cg_emit_comp(cgProcedure *p, TokenKind op_kind, cgValue left
|
||||
case Token_Gt: res = tb_inst_cmp_fgt(p->func, lhs, rhs); break;
|
||||
case Token_GtEq: res = tb_inst_cmp_fge(p->func, lhs, rhs); break;
|
||||
case Token_Lt: res = tb_inst_cmp_flt(p->func, lhs, rhs); break;
|
||||
case Token_LtEq: res = tb_inst_cmp_fge(p->func, lhs, rhs); break;
|
||||
case Token_LtEq: res = tb_inst_cmp_fle(p->func, lhs, rhs); break;
|
||||
}
|
||||
GB_ASSERT(res != nullptr);
|
||||
return cg_value(res, t_bool);
|
||||
|
||||
@@ -235,7 +235,24 @@ gb_internal void cg_procedure_begin(cgProcedure *p) {
|
||||
if (e != nullptr && e->token.string.len > 0 && e->token.string != "_") {
|
||||
// NOTE(bill): for debugging purposes only
|
||||
String name = e->token.string;
|
||||
tb_node_append_attrib(param_ptr, tb_function_attrib_variable(p->func, name.len, cast(char const *)name.text, debug_type));
|
||||
TB_DebugType *param_debug_type = debug_type;
|
||||
TB_Node * param_ptr_to_use = param_ptr;
|
||||
if (rule == TB_PASSING_INDIRECT) {
|
||||
// HACK TODO(bill): this is just to get the debug information
|
||||
TB_CharUnits ptr_size = cast(TB_CharUnits)build_context.ptr_size;
|
||||
TB_Node *dummy_param = tb_inst_local(p->func, ptr_size, ptr_size);
|
||||
tb_inst_store(p->func, TB_TYPE_PTR, dummy_param, param_ptr, ptr_size, false);
|
||||
param_ptr_to_use = dummy_param;
|
||||
param_debug_type = tb_debug_create_ptr(p->module->mod, param_debug_type);
|
||||
}
|
||||
tb_node_append_attrib(
|
||||
param_ptr_to_use,
|
||||
tb_function_attrib_variable(
|
||||
p->func,
|
||||
name.len, cast(char const *)name.text,
|
||||
param_debug_type
|
||||
)
|
||||
);
|
||||
}
|
||||
cgAddr addr = cg_addr(local);
|
||||
if (e) {
|
||||
@@ -332,13 +349,20 @@ gb_internal WORKER_TASK_PROC(cg_procedure_compile_worker_proc) {
|
||||
|
||||
bool emit_asm = false;
|
||||
|
||||
if (
|
||||
string_starts_with(p->name, str_lit("runtime@_os_write")) ||
|
||||
false
|
||||
) {
|
||||
emit_asm = true;
|
||||
}
|
||||
|
||||
TB_FunctionOutput *output = tb_module_compile_function(p->module->mod, p->func, TB_ISEL_FAST, emit_asm);
|
||||
if (emit_asm) {
|
||||
TB_Assembly *assembly = tb_output_get_asm(output);
|
||||
for (TB_Assembly *node = assembly; node != nullptr; node = node->next) {
|
||||
gb_printf_err("%.*s", cast(int)node->length, node->data);
|
||||
fprintf(stdout, "%.*s", cast(int)node->length, node->data);
|
||||
}
|
||||
gb_printf_err("\n");
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -2,7 +2,84 @@ gb_internal void cg_setup_type_info_data(cgModule *m) {
|
||||
if (build_context.no_rtti) {
|
||||
return;
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
gb_unused(info);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user