Correct -use-separate-module behaviour

This commit is contained in:
gingerBill
2024-07-08 15:13:40 +01:00
parent 8491e2491c
commit 2a219fa830
5 changed files with 16 additions and 6 deletions

View File

@@ -338,6 +338,9 @@ gb_internal Entity *alloc_entity(EntityKind kind, Scope *scope, Token token, Typ
entity->token = token;
entity->type = type;
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;
}

View File

@@ -3439,7 +3439,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
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);
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));

View File

@@ -118,6 +118,7 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
map_init(&gen->anonymous_proc_lits, 1024);
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) {
AstPackage *pkg = entry.value;
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;
map_set(&gen->modules, cast(void *)pkg, m);
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
for (AstFile *file : pkg->files) {
auto m = gb_alloc_item(permanent_allocator(), lbModule);

View File

@@ -3304,11 +3304,16 @@ int main(int arg_count, char const **arg_ptr) {
} else
#endif
{
MAIN_TIME_SECTION("LLVM API Code Gen");
lbGenerator *gen = gb_alloc_item(permanent_allocator(), lbGenerator);
if (!lb_init_generator(gen, checker)) {
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)) {
switch (build_context.build_mode) {
case BuildMode_Executable:

View File

@@ -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);
}
#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 {