From 8491e2491cd6fe4ea1b5205614f43f1a525cb77f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 8 Jul 2024 14:48:59 +0100 Subject: [PATCH] Experiment with different uses of `-use-separate-modules` --- src/build_settings.cpp | 1 + src/llvm_backend.cpp | 6 +++++- src/llvm_backend_general.cpp | 21 ++++++++++----------- src/main.cpp | 8 +++++++- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/build_settings.cpp b/src/build_settings.cpp index 6f4b51df8..f5a91e6ab 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -426,6 +426,7 @@ struct BuildContext { bool linker_map_file; bool use_separate_modules; + bool module_per_file; bool no_threaded_checker; bool show_debug_messages; diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 375abb0dd..8c82d7117 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -3437,7 +3437,11 @@ gb_internal bool lb_generate_code(lbGenerator *gen) { TIME_SECTION("LLVM Add Foreign Library Paths"); lb_add_foreign_library_paths(gen); - TIME_SECTION("LLVM Object Generation"); + gbString label_object_generation = gb_string_make(heap_allocator(), "LLVM Object Generation"); + if (gen->modules.count > 1) { + label_object_generation = gb_string_append_fmt(label_object_generation, " (%d modules)", gen->modules.count); + } + TIME_SECTION_WITH_LEN(label_object_generation, gb_string_length(label_object_generation)); if (build_context.ignore_llvm_build) { gb_printf_err("LLVM object generation has been ignored!\n"); diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index db89910dd..f65bc9ac7 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -120,23 +120,22 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) { if (USE_SEPARATE_MODULES) { for (auto const &entry : gen->info->packages) { AstPackage *pkg = entry.value; - #if 1 auto m = gb_alloc_item(permanent_allocator(), lbModule); m->pkg = pkg; m->gen = gen; map_set(&gen->modules, cast(void *)pkg, m); lb_init_module(m, c); - #else - // NOTE(bill): Probably per file is not a good idea, so leave this for later - for (AstFile *file : pkg->files) { - auto m = gb_alloc_item(permanent_allocator(), lbModule); - m->file = file; - m->pkg = pkg; - m->gen = gen; - map_set(&gen->modules, cast(void *)file, m); - lb_init_module(m, c); + if (build_context.module_per_file) { + // NOTE(bill): Probably per file is not a good idea, so leave this for later + for (AstFile *file : pkg->files) { + auto m = gb_alloc_item(permanent_allocator(), lbModule); + m->file = file; + m->pkg = pkg; + m->gen = gen; + map_set(&gen->modules, cast(void *)file, m); + lb_init_module(m, c); + } } - #endif } } diff --git a/src/main.cpp b/src/main.cpp index f80da8c68..8ea0ae62c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -390,6 +390,7 @@ enum BuildFlagKind { BuildFlag_InternalIgnoreLazy, BuildFlag_InternalIgnoreLLVMBuild, BuildFlag_InternalIgnorePanic, + BuildFlag_InternalModulePerFile, BuildFlag_Tilde, @@ -591,7 +592,8 @@ gb_internal bool parse_build_flags(Array args) { add_flag(&build_flags, BuildFlag_InternalIgnoreLazy, str_lit("internal-ignore-lazy"), BuildFlagParam_None, Command_all); add_flag(&build_flags, BuildFlag_InternalIgnoreLLVMBuild, str_lit("internal-ignore-llvm-build"),BuildFlagParam_None, Command_all); - add_flag(&build_flags, BuildFlag_InternalIgnorePanic, str_lit("internal-ignore-panic"), BuildFlagParam_None, Command_all); + add_flag(&build_flags, BuildFlag_InternalIgnorePanic, str_lit("internal-ignore-panic"), BuildFlagParam_None, Command_all); + add_flag(&build_flags, BuildFlag_InternalModulePerFile, str_lit("internal-module-per-file"), BuildFlagParam_None, Command_all); #if ALLOW_TILDE add_flag(&build_flags, BuildFlag_Tilde, str_lit("tilde"), BuildFlagParam_None, Command__does_build); @@ -1408,6 +1410,10 @@ gb_internal bool parse_build_flags(Array args) { case BuildFlag_InternalIgnorePanic: build_context.ignore_panic = true; break; + case BuildFlag_InternalModulePerFile: + build_context.module_per_file = true; + break; + case BuildFlag_Tilde: build_context.tilde_backend = true; break;