Update Tilde to get procedure passing rules

This commit is contained in:
gingerBill
2023-07-22 07:56:13 +01:00
parent ec0a9a5f8a
commit e5f9458905
6 changed files with 217 additions and 115 deletions

View File

@@ -1,5 +1,12 @@
#include "tilde.hpp"
gb_global Slice<TB_Arena *> global_tb_arenas;
gb_internal TB_Arena *cg_arena(void) {
return global_tb_arenas[current_thread_index()];
}
// returns TB_TYPE_VOID if not trivially possible
gb_internal TB_DataType cg_data_type(Type *t) {
GB_ASSERT(t != nullptr);
@@ -672,6 +679,11 @@ gb_internal bool cg_generate_code(Checker *c) {
CheckerInfo *info = &c->info;
gb_unused(info);
global_tb_arenas = slice_make<TB_Arena *>(permanent_allocator(), global_thread_pool.threads.count);
for_array(i, global_tb_arenas) {
global_tb_arenas[i] = tb_default_arena();
}
cgModule *m = cg_module_create(c);
defer (cg_module_destroy(m));
@@ -750,89 +762,6 @@ gb_internal bool cg_generate_code(Checker *c) {
char const *path = "W:/Odin/tilde_main.obj";
GB_ASSERT(tb_export_buffer_to_file(export_buffer, path));
////////////////////////////////////////////////////////////////////////////////////
// TB_Arena *arena = tb_default_arena();
// TB_Global *str = nullptr;
// {
// TB_Global *str_data = nullptr;
// {
// str_data = tb_global_create(m->mod, "csb$1", nullptr, TB_LINKAGE_PRIVATE);
// tb_global_set_storage(m->mod, tb_module_get_rdata(m->mod), str_data, 8, 1, 1);
// void *region = tb_global_add_region(m->mod, str_data, 0, 8);
// memcpy(region, "Hellope\x00", 8);
// }
// str = tb_global_create(m->mod, "global$str", nullptr, TB_LINKAGE_PRIVATE);
// tb_global_set_storage(m->mod, tb_module_get_rdata(m->mod), str, 16, 8, 2);
// tb_global_add_symbol_reloc(m->mod, str, 0, cast(TB_Symbol *)str_data);
// void *len = tb_global_add_region(m->mod, str, 8, 8);
// *cast(i64 *)len = 7;
// }
// {
// TB_PrototypeParam printf_ret = {TB_TYPE_I32};
// TB_PrototypeParam printf_params = {TB_TYPE_PTR};
// TB_FunctionPrototype *printf_proto = tb_prototype_create(m->mod, TB_STDCALL, 1, &printf_params, 1, &printf_ret, true);
// TB_External *printf_proc = tb_extern_create(m->mod, "printf", TB_EXTERNAL_SO_LOCAL);
// TB_PrototypeParam main_ret = {TB_TYPE_I32};
// TB_FunctionPrototype *main_proto = tb_prototype_create(m->mod, TB_STDCALL, 0, nullptr, 1, &main_ret, false);
// TB_Function * p = tb_function_create(m->mod, "main", TB_LINKAGE_PUBLIC, TB_COMDAT_NONE);
// tb_function_set_prototype(p, main_proto, arena);
// auto str_ptr = tb_inst_get_symbol_address(p, cast(TB_Symbol *)str);
// auto str_data_ptr_ptr = tb_inst_member_access(p, str_ptr, 0);
// auto str_data_ptr = tb_inst_load(p, TB_TYPE_PTR, str_data_ptr_ptr, 1, false);
// auto str_len_ptr = tb_inst_member_access(p, str_ptr, 8);
// auto str_len = tb_inst_load(p, TB_TYPE_I64, str_len_ptr, 8, false);
// TB_Node *params[4] = {};
// params[0] = tb_inst_cstring(p, "%.*s %s!\n");
// params[1] = tb_inst_trunc(p, str_len, TB_TYPE_I32);
// params[2] = str_data_ptr;
// params[3] = tb_inst_cstring(p, "World");
// TB_MultiOutput output = tb_inst_call(p, printf_proto, tb_inst_get_symbol_address(p, cast(TB_Symbol *)printf_proc), gb_count_of(params), params);
// gb_unused(output);
// TB_Node *printf_return_value = output.single;
// TB_Node *zero = tb_inst_uint(p, TB_TYPE_I32, 0);
// TB_Node *one = tb_inst_uint(p, TB_TYPE_I32, 1);
// TB_Node *prev_case = tb_inst_get_control(p);
// TB_Node *true_case = tb_inst_region(p);
// TB_Node *false_case = tb_inst_region(p);
// TB_Node *cond = tb_inst_cmp_igt(p, printf_return_value, zero, true);
// tb_inst_if(p, cond, true_case, false_case);
// tb_inst_set_control(p, true_case);
// tb_inst_ret(p, 1, &zero);
// tb_inst_set_control(p, false_case);
// tb_inst_ret(p, 1, &one);
// tb_inst_set_control(p, prev_case);
// tb_module_compile_function(m->mod, p, TB_ISEL_FAST);
// tb_function_print(p, tb_default_print_callback, stdout);
// TB_DebugFormat debug_format = TB_DEBUGFMT_NONE;
// TB_ExportBuffer export_buffer = tb_module_object_export(m->mod, debug_format);
// defer (tb_export_buffer_free(export_buffer));
// char const *path = "W:/Odin/tilde_main.obj";
// GB_ASSERT(tb_export_buffer_to_file(export_buffer, path));
// }
return true;
}