Hook up Tilde to the linker code

This commit is contained in:
gingerBill
2023-07-24 12:01:23 +01:00
parent bd81c6f5b4
commit b09cdc0f25
5 changed files with 55 additions and 44 deletions

View File

@@ -11,6 +11,39 @@ struct LinkerData {
gb_internal i32 system_exec_command_line_app(char const *name, char const *fmt, ...);
gb_internal void linker_data_init(LinkerData *ld, CheckerInfo *info, String const &init_fullpath) {
gbAllocator ha = heap_allocator();
array_init(&ld->output_object_paths, ha);
array_init(&ld->output_temp_paths, ha);
array_init(&ld->foreign_libraries, ha, 0, 1024);
ptr_set_init(&ld->foreign_libraries_set, 1024);
if (build_context.out_filepath.len == 0) {
ld->output_name = remove_directory_from_path(init_fullpath);
ld->output_name = remove_extension_from_path(ld->output_name);
ld->output_name = string_trim_whitespace(ld->output_name);
if (ld->output_name.len == 0) {
ld->output_name = info->init_scope->pkg->name;
}
ld->output_base = ld->output_name;
} else {
ld->output_name = build_context.out_filepath;
ld->output_name = string_trim_whitespace(ld->output_name);
if (ld->output_name.len == 0) {
ld->output_name = info->init_scope->pkg->name;
}
isize pos = string_extension_position(ld->output_name);
if (pos < 0) {
ld->output_base = ld->output_name;
} else {
ld->output_base = substring(ld->output_name, 0, pos);
}
}
ld->output_base = path_to_full_path(ha, ld->output_base);
}
gb_internal i32 linker_stage(LinkerData *gen) {
i32 result = 0;
Timings *timings = &global_timings;

View File

@@ -103,37 +103,7 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
}
String init_fullpath = c->parser->init_fullpath;
if (build_context.out_filepath.len == 0) {
gen->output_name = remove_directory_from_path(init_fullpath);
gen->output_name = remove_extension_from_path(gen->output_name);
gen->output_name = string_trim_whitespace(gen->output_name);
if (gen->output_name.len == 0) {
gen->output_name = c->info.init_scope->pkg->name;
}
gen->output_base = gen->output_name;
} else {
gen->output_name = build_context.out_filepath;
gen->output_name = string_trim_whitespace(gen->output_name);
if (gen->output_name.len == 0) {
gen->output_name = c->info.init_scope->pkg->name;
}
isize pos = string_extension_position(gen->output_name);
if (pos < 0) {
gen->output_base = gen->output_name;
} else {
gen->output_base = substring(gen->output_name, 0, pos);
}
}
gbAllocator ha = heap_allocator();
array_init(&gen->output_object_paths, ha);
array_init(&gen->output_temp_paths, ha);
gen->output_base = path_to_full_path(ha, gen->output_base);
gbString output_file_path = gb_string_make_length(ha, gen->output_base.text, gen->output_base.len);
output_file_path = gb_string_appendc(output_file_path, ".obj");
defer (gb_string_free(output_file_path));
linker_data_init(gen, &c->info, init_fullpath);
gen->info = &c->info;
@@ -141,10 +111,6 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
map_init(&gen->modules_through_ctx, gen->info->packages.count*2);
map_init(&gen->anonymous_proc_lits, 1024);
array_init(&gen->foreign_libraries, heap_allocator(), 0, 1024);
ptr_set_init(&gen->foreign_libraries_set, 1024);
if (USE_SEPARATE_MODULES) {
for (auto const &entry : gen->info->packages) {
AstPackage *pkg = entry.value;

View File

@@ -2489,16 +2489,24 @@ int main(int arg_count, char const **arg_ptr) {
#if defined(GB_SYSTEM_WINDOWS)
if (build_context.tilde_backend) {
LinkerData linker_data = {};
MAIN_TIME_SECTION("Tilde Code Gen");
if (!cg_generate_code(checker)) {
if (!cg_generate_code(checker, &linker_data)) {
return 1;
}
if (build_context.show_timings) {
show_timings(checker, &global_timings);
switch (build_context.build_mode) {
case BuildMode_Executable:
case BuildMode_DynamicLibrary:
i32 result = linker_stage(&linker_data);
if (result) {
if (build_context.show_timings) {
show_timings(checker, &global_timings);
}
return result;
}
break;
}
return 0;
} else
#endif
{

View File

@@ -717,11 +717,12 @@ gb_internal String cg_get_entity_name(cgModule *m, Entity *e) {
#include "tilde_stmt.cpp"
gb_internal bool cg_generate_code(Checker *c) {
gb_internal bool cg_generate_code(Checker *c, LinkerData *linker_data) {
TIME_SECTION("Tilde Module Initializtion");
CheckerInfo *info = &c->info;
gb_unused(info);
linker_data_init(linker_data, info, c->parser->init_fullpath);
global_tb_arenas = slice_make<TB_Arena *>(permanent_allocator(), global_thread_pool.threads.count);
for_array(i, global_tb_arenas) {
@@ -803,8 +804,10 @@ gb_internal bool cg_generate_code(Checker *c) {
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));
char const *filepath_obj = "W:/Odin/tilde_main.obj";
array_add(&linker_data->output_object_paths, make_string_c(filepath_obj));
GB_ASSERT(tb_export_buffer_to_file(export_buffer, filepath_obj));
return true;
}

View File

@@ -208,6 +208,7 @@ struct cgModule {
TB_Module * mod;
Checker * checker;
CheckerInfo *info;
LinkerData * linker_data;
RwMutex values_mutex;
PtrMap<Entity *, cgValue> values;