Prepare for arbitrary separate modules

This commit is contained in:
gingerBill
2023-01-12 21:45:02 +00:00
parent 3b22c6620c
commit 4a8c37dd52
3 changed files with 28 additions and 7 deletions
+12 -4
View File
@@ -1488,7 +1488,12 @@ gb_internal String lb_filepath_ll_for_module(lbModule *m) {
build_context.build_paths[BuildPath_Output].name
);
if (m->pkg) {
if (m->file) {
char buf[32] = {};
isize n = gb_snprintf(buf, gb_size_of(buf), "-%u", m->file->id);
String suffix = make_string((u8 *)buf, n-1);
path = concatenate_strings(permanent_allocator(), path, suffix);
} else if (m->pkg) {
path = concatenate3_strings(permanent_allocator(), path, STR_LIT("-"), m->pkg->name);
} else if (USE_SEPARATE_MODULES) {
path = concatenate_strings(permanent_allocator(), path, STR_LIT("-builtin"));
@@ -1504,7 +1509,12 @@ gb_internal String lb_filepath_obj_for_module(lbModule *m) {
build_context.build_paths[BuildPath_Output].name
);
if (m->pkg) {
if (m->file) {
char buf[32] = {};
isize n = gb_snprintf(buf, gb_size_of(buf), "-%u", m->file->id);
String suffix = make_string((u8 *)buf, n-1);
path = concatenate_strings(permanent_allocator(), path, suffix);
} else if (m->pkg) {
path = concatenate3_strings(permanent_allocator(), path, STR_LIT("-"), m->pkg->name);
}
@@ -1852,7 +1862,6 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
isize worker_count = thread_count-1;
bool do_threading = !!(LLVMIsMultithreaded() && USE_SEPARATE_MODULES && MULTITHREAD_OBJECT_GENERATION && worker_count > 0);
do_threading = false;
lbModule *default_module = &gen->default_module;
CheckerInfo *info = gen->info;
@@ -2388,7 +2397,6 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
if (lb_is_module_empty(m)) {
continue;
}
String filepath_ll = lb_filepath_ll_for_module(m);
if (LLVMPrintModuleToFile(m->mod, cast(char const *)filepath_ll.text, &llvm_error)) {
gb_printf_err("LLVM Error: %s\n", llvm_error);
+2 -1
View File
@@ -135,7 +135,8 @@ struct lbModule {
LLVMTargetMachineRef target_machine;
CheckerInfo *info;
AstPackage *pkg; // associated
AstPackage *pkg; // possibly associated
AstFile *file; // possibly associated
PtrMap<Type *, LLVMTypeRef> types;
PtrMap<Type *, LLVMTypeRef> func_raw_types;
+14 -2
View File
@@ -19,7 +19,9 @@ gb_internal void lb_init_module(lbModule *m, Checker *c) {
m->info = &c->info;
gbString module_name = gb_string_make(heap_allocator(), "odin_package");
if (m->pkg) {
if (m->file) {
module_name = gb_string_append_fmt(module_name, "-%u", m->file->id+1);
} else if (m->pkg) {
module_name = gb_string_appendc(module_name, "-");
module_name = gb_string_append_length(module_name, m->pkg->name.text, m->pkg->name.len);
} else if (USE_SEPARATE_MODULES) {
@@ -139,12 +141,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
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
}
}