diff options
| author | gingerBill <bill@gingerbill.org> | 2023-01-12 17:13:25 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-01-12 17:13:25 +0000 |
| commit | 3b22c6620cea89394ad7a2b80da5f2529a4fae20 (patch) | |
| tree | 04cc993bb811e0bc5d412dbb14a710bec56bc9d5 /src | |
| parent | 402a165b60dc9de1ef047b44e47c2d38e5cbed6d (diff) | |
Begin to generalize modules away from `AstPackage *` in `-use-separate-modules`
Diffstat (limited to 'src')
| -rw-r--r-- | src/llvm_backend.cpp | 2 | ||||
| -rw-r--r-- | src/llvm_backend.hpp | 2 | ||||
| -rw-r--r-- | src/llvm_backend_debug.cpp | 2 | ||||
| -rw-r--r-- | src/llvm_backend_general.cpp | 29 | ||||
| -rw-r--r-- | src/llvm_backend_proc.cpp | 2 |
5 files changed, 21 insertions, 16 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 4c954b58f..f0d51be73 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -1222,7 +1222,7 @@ gb_internal void lb_create_global_procedures_and_types(lbGenerator *gen, Checker lbModule *m = &gen->default_module; if (USE_SEPARATE_MODULES) { - m = lb_pkg_module(gen, e->pkg); + m = lb_module_of_entity(gen, e); } array_add(&m->global_procedures_and_types_to_create, e); diff --git a/src/llvm_backend.hpp b/src/llvm_backend.hpp index de4deffd4..4288ae16e 100644 --- a/src/llvm_backend.hpp +++ b/src/llvm_backend.hpp @@ -191,7 +191,7 @@ struct lbGenerator { Array<String> output_temp_paths; String output_base; String output_name; - PtrMap<AstPackage *, lbModule *> modules; + PtrMap<void *, lbModule *> modules; // key is `AstPackage *` (`void *` is used for future use) PtrMap<LLVMContextRef, lbModule *> modules_through_ctx; lbModule default_module; diff --git a/src/llvm_backend_debug.cpp b/src/llvm_backend_debug.cpp index 9bf4063d6..83f6da04e 100644 --- a/src/llvm_backend_debug.cpp +++ b/src/llvm_backend_debug.cpp @@ -1177,7 +1177,7 @@ gb_internal void add_debug_info_for_global_constant_from_entity(lbGenerator *gen } lbModule *m = &gen->default_module; if (USE_SEPARATE_MODULES) { - m = lb_pkg_module(gen, e->pkg); + m = lb_module_of_entity(gen, e); } if (is_type_integer(e->type)) { diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index cae3ab1ee..516c46396 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -143,13 +143,13 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) { auto m = gb_alloc_item(permanent_allocator(), lbModule); m->pkg = pkg; m->gen = gen; - map_set(&gen->modules, pkg, m); + map_set(&gen->modules, cast(void *)pkg, m); lb_init_module(m, c); } } gen->default_module.gen = gen; - map_set(&gen->modules, cast(AstPackage *)nullptr, &gen->default_module); + map_set(&gen->modules, cast(void *)nullptr, &gen->default_module); lb_init_module(&gen->default_module, c); @@ -315,17 +315,22 @@ gb_internal bool lb_is_instr_terminating(LLVMValueRef instr) { } - -gb_internal lbModule *lb_pkg_module(lbGenerator *gen, AstPackage *pkg) { - // NOTE(bill): no need for a mutex since it's immutable - auto *found = map_get(&gen->modules, pkg); - if (found) { - return *found; +gb_internal lbModule *lb_module_of_entity(lbGenerator *gen, Entity *e) { + GB_ASSERT(e != nullptr); + if (e->pkg) { + lbModule **found = nullptr; + found = map_get(&gen->modules, cast(void *)e->file); + if (found) { + return *found; + } + found = map_get(&gen->modules, cast(void *)e->pkg); + if (found) { + return *found; + } } return &gen->default_module; } - gb_internal lbAddr lb_addr(lbValue addr) { lbAddr v = {lbAddr_Default, addr}; if (addr.type != nullptr && is_type_relative_pointer(type_deref(addr.type))) { @@ -2546,7 +2551,7 @@ gb_internal lbValue lb_find_ident(lbProcedure *p, lbModule *m, Entity *e, Ast *e return lb_find_procedure_value_from_entity(m, e); } if (USE_SEPARATE_MODULES) { - lbModule *other_module = lb_pkg_module(m->gen, e->pkg); + lbModule *other_module = lb_module_of_entity(m->gen, e); if (other_module != m) { String name = lb_get_entity_name(other_module, e); @@ -2590,7 +2595,7 @@ gb_internal lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e) lbModule *other_module = m; if (USE_SEPARATE_MODULES) { - other_module = lb_pkg_module(m->gen, e->pkg); + other_module = lb_module_of_entity(m->gen, e); } if (other_module == m) { debugf("Missing Procedure (lb_find_procedure_value_from_entity): %.*s\n", LIT(e->token.string)); @@ -2687,7 +2692,7 @@ gb_internal lbValue lb_find_value_from_entity(lbModule *m, Entity *e) { } if (USE_SEPARATE_MODULES) { - lbModule *other_module = lb_pkg_module(m->gen, e->pkg); + lbModule *other_module = lb_module_of_entity(m->gen, e); // TODO(bill): correct this logic bool is_external = other_module != m; diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp index fd654cec9..f156d1ca0 100644 --- a/src/llvm_backend_proc.cpp +++ b/src/llvm_backend_proc.cpp @@ -74,7 +74,7 @@ gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool i String link_name = {}; if (ignore_body) { - lbModule *other_module = lb_pkg_module(m->gen, entity->pkg); + lbModule *other_module = lb_module_of_entity(m->gen, entity); link_name = lb_get_entity_name(other_module, entity); } else { link_name = lb_get_entity_name(m, entity); |