Begin to generalize modules away from AstPackage * in -use-separate-modules

This commit is contained in:
gingerBill
2023-01-12 17:13:25 +00:00
parent 402a165b60
commit 3b22c6620c
5 changed files with 21 additions and 16 deletions
+1 -1
View File
@@ -1222,7 +1222,7 @@ gb_internal void lb_create_global_procedures_and_types(lbGenerator *gen, Checker
lbModule *m = &gen->default_module; lbModule *m = &gen->default_module;
if (USE_SEPARATE_MODULES) { 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); array_add(&m->global_procedures_and_types_to_create, e);
+1 -1
View File
@@ -191,7 +191,7 @@ struct lbGenerator {
Array<String> output_temp_paths; Array<String> output_temp_paths;
String output_base; String output_base;
String output_name; 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; PtrMap<LLVMContextRef, lbModule *> modules_through_ctx;
lbModule default_module; lbModule default_module;
+1 -1
View File
@@ -1177,7 +1177,7 @@ gb_internal void add_debug_info_for_global_constant_from_entity(lbGenerator *gen
} }
lbModule *m = &gen->default_module; lbModule *m = &gen->default_module;
if (USE_SEPARATE_MODULES) { if (USE_SEPARATE_MODULES) {
m = lb_pkg_module(gen, e->pkg); m = lb_module_of_entity(gen, e);
} }
if (is_type_integer(e->type)) { if (is_type_integer(e->type)) {
+17 -12
View File
@@ -143,13 +143,13 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
auto m = gb_alloc_item(permanent_allocator(), lbModule); auto m = gb_alloc_item(permanent_allocator(), lbModule);
m->pkg = pkg; m->pkg = pkg;
m->gen = gen; m->gen = gen;
map_set(&gen->modules, pkg, m); map_set(&gen->modules, cast(void *)pkg, m);
lb_init_module(m, c); lb_init_module(m, c);
} }
} }
gen->default_module.gen = gen; 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); lb_init_module(&gen->default_module, c);
@@ -315,17 +315,22 @@ gb_internal bool lb_is_instr_terminating(LLVMValueRef instr) {
} }
gb_internal lbModule *lb_module_of_entity(lbGenerator *gen, Entity *e) {
gb_internal lbModule *lb_pkg_module(lbGenerator *gen, AstPackage *pkg) { GB_ASSERT(e != nullptr);
// NOTE(bill): no need for a mutex since it's immutable if (e->pkg) {
auto *found = map_get(&gen->modules, pkg); lbModule **found = nullptr;
if (found) { found = map_get(&gen->modules, cast(void *)e->file);
return *found; if (found) {
return *found;
}
found = map_get(&gen->modules, cast(void *)e->pkg);
if (found) {
return *found;
}
} }
return &gen->default_module; return &gen->default_module;
} }
gb_internal lbAddr lb_addr(lbValue addr) { gb_internal lbAddr lb_addr(lbValue addr) {
lbAddr v = {lbAddr_Default, addr}; lbAddr v = {lbAddr_Default, addr};
if (addr.type != nullptr && is_type_relative_pointer(type_deref(addr.type))) { 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); return lb_find_procedure_value_from_entity(m, e);
} }
if (USE_SEPARATE_MODULES) { 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) { if (other_module != m) {
String name = lb_get_entity_name(other_module, e); 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; lbModule *other_module = m;
if (USE_SEPARATE_MODULES) { 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) { if (other_module == m) {
debugf("Missing Procedure (lb_find_procedure_value_from_entity): %.*s\n", LIT(e->token.string)); 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) { 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 // TODO(bill): correct this logic
bool is_external = other_module != m; bool is_external = other_module != m;
+1 -1
View File
@@ -74,7 +74,7 @@ gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool i
String link_name = {}; String link_name = {};
if (ignore_body) { 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); link_name = lb_get_entity_name(other_module, entity);
} else { } else {
link_name = lb_get_entity_name(m, entity); link_name = lb_get_entity_name(m, entity);