Browse Source

Correct `-use-separate-module` behaviour

gingerBill 1 year ago
parent
commit
2a219fa830
5 changed files with 16 additions and 6 deletions
  1. 3 0
      src/entity.cpp
  2. 1 1
      src/llvm_backend.cpp
  3. 2 1
      src/llvm_backend_general.cpp
  4. 6 1
      src/main.cpp
  5. 4 3
      src/timings.cpp

+ 3 - 0
src/entity.cpp

@@ -338,6 +338,9 @@ gb_internal Entity *alloc_entity(EntityKind kind, Scope *scope, Token token, Typ
 	entity->token  = token;
 	entity->token  = token;
 	entity->type   = type;
 	entity->type   = type;
 	entity->id     = 1 + global_entity_id.fetch_add(1);
 	entity->id     = 1 + global_entity_id.fetch_add(1);
+	if (token.pos.file_id) {
+		entity->file = thread_safe_get_ast_file_from_id(token.pos.file_id);
+	}
 	return entity;
 	return entity;
 }
 }
 
 

+ 1 - 1
src/llvm_backend.cpp

@@ -3439,7 +3439,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
 
 
 	gbString label_object_generation = gb_string_make(heap_allocator(), "LLVM Object Generation");
 	gbString label_object_generation = gb_string_make(heap_allocator(), "LLVM Object Generation");
 	if (gen->modules.count > 1) {
 	if (gen->modules.count > 1) {
-		label_object_generation = gb_string_append_fmt(label_object_generation, " (%d modules)", gen->modules.count);
+		label_object_generation = gb_string_append_fmt(label_object_generation, " (%td modules)", gen->modules.count);
 	}
 	}
 	TIME_SECTION_WITH_LEN(label_object_generation, gb_string_length(label_object_generation));
 	TIME_SECTION_WITH_LEN(label_object_generation, gb_string_length(label_object_generation));
 	
 	

+ 2 - 1
src/llvm_backend_general.cpp

@@ -118,6 +118,7 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
 	map_init(&gen->anonymous_proc_lits, 1024);
 	map_init(&gen->anonymous_proc_lits, 1024);
 
 
 	if (USE_SEPARATE_MODULES) {
 	if (USE_SEPARATE_MODULES) {
+		bool module_per_file = build_context.module_per_file && build_context.optimization_level <= 0;
 		for (auto const &entry : gen->info->packages) {
 		for (auto const &entry : gen->info->packages) {
 			AstPackage *pkg = entry.value;
 			AstPackage *pkg = entry.value;
 			auto m = gb_alloc_item(permanent_allocator(), lbModule);
 			auto m = gb_alloc_item(permanent_allocator(), lbModule);
@@ -125,7 +126,7 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
 			m->gen = gen;
 			m->gen = gen;
 			map_set(&gen->modules, cast(void *)pkg, m);
 			map_set(&gen->modules, cast(void *)pkg, m);
 			lb_init_module(m, c);
 			lb_init_module(m, c);
-			if (build_context.module_per_file) {
+			if (module_per_file) {
 				// NOTE(bill): Probably per file is not a good idea, so leave this for later
 				// NOTE(bill): Probably per file is not a good idea, so leave this for later
 				for (AstFile *file : pkg->files) {
 				for (AstFile *file : pkg->files) {
 					auto m = gb_alloc_item(permanent_allocator(), lbModule);
 					auto m = gb_alloc_item(permanent_allocator(), lbModule);

+ 6 - 1
src/main.cpp

@@ -3304,11 +3304,16 @@ int main(int arg_count, char const **arg_ptr) {
 	} else
 	} else
 #endif
 #endif
 	{
 	{
-		MAIN_TIME_SECTION("LLVM API Code Gen");
 		lbGenerator *gen = gb_alloc_item(permanent_allocator(), lbGenerator);
 		lbGenerator *gen = gb_alloc_item(permanent_allocator(), lbGenerator);
 		if (!lb_init_generator(gen, checker)) {
 		if (!lb_init_generator(gen, checker)) {
 			return 1;
 			return 1;
 		}
 		}
+
+		gbString label_code_gen = gb_string_make(heap_allocator(), "LLVM API Code Gen");
+		if (gen->modules.count > 1) {
+			label_code_gen = gb_string_append_fmt(label_code_gen, " ( %4td modules )", gen->modules.count);
+		}
+		MAIN_TIME_SECTION_WITH_LEN(label_code_gen, gb_string_length(label_code_gen));
 		if (lb_generate_code(gen)) {
 		if (lb_generate_code(gen)) {
 			switch (build_context.build_mode) {
 			switch (build_context.build_mode) {
 			case BuildMode_Executable:
 			case BuildMode_Executable:

+ 4 - 3
src/timings.cpp

@@ -146,9 +146,10 @@ gb_internal f64 time_stamp_as_us(TimeStamp const &ts, u64 freq) {
 	return 1000000.0*time_stamp_as_s(ts, freq);
 	return 1000000.0*time_stamp_as_s(ts, freq);
 }
 }
 
 
-#define MAIN_TIME_SECTION(str)          do { debugf("[Section] %s\n", str);                                      timings_start_section(&global_timings, str_lit(str));                } while (0)
-#define TIME_SECTION(str)               do { debugf("[Section] %s\n", str); if (build_context.show_more_timings) timings_start_section(&global_timings, str_lit(str));                } while (0)
-#define TIME_SECTION_WITH_LEN(str, len) do { debugf("[Section] %s\n", str); if (build_context.show_more_timings) timings_start_section(&global_timings, make_string((u8 *)str, len)); } while (0)
+#define MAIN_TIME_SECTION(str)               do { debugf("[Section] %s\n", str);                                      timings_start_section(&global_timings, str_lit(str));                } while (0)
+#define MAIN_TIME_SECTION_WITH_LEN(str, len) do { debugf("[Section] %s\n", str);                                      timings_start_section(&global_timings, make_string((u8 *)str, len)); } while (0)
+#define TIME_SECTION(str)                    do { debugf("[Section] %s\n", str); if (build_context.show_more_timings) timings_start_section(&global_timings, str_lit(str));                } while (0)
+#define TIME_SECTION_WITH_LEN(str, len)      do { debugf("[Section] %s\n", str); if (build_context.show_more_timings) timings_start_section(&global_timings, make_string((u8 *)str, len)); } while (0)
 
 
 
 
 enum TimingUnit {
 enum TimingUnit {