Browse Source

Experiment with different uses of `-use-separate-modules`

gingerBill 1 year ago
parent
commit
8491e2491c
4 changed files with 23 additions and 13 deletions
  1. 1 0
      src/build_settings.cpp
  2. 5 1
      src/llvm_backend.cpp
  3. 10 11
      src/llvm_backend_general.cpp
  4. 7 1
      src/main.cpp

+ 1 - 0
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;

+ 5 - 1
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");

+ 10 - 11
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
 		}
 	}
 

+ 7 - 1
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<String> 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<String> 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;