Support multiple paths for wasm in foreign import

This commit is contained in:
gingerBill
2025-01-01 15:12:54 +00:00
parent 7ffec820ac
commit c8ad2a4245
3 changed files with 77 additions and 46 deletions
+34
View File
@@ -1356,6 +1356,7 @@ gb_internal void init_checker_info(CheckerInfo *i) {
mpsc_init(&i->required_global_variable_queue, a); // 1<<10);
mpsc_init(&i->required_foreign_imports_through_force_queue, a); // 1<<10);
mpsc_init(&i->foreign_imports_to_check_fullpaths, a); // 1<<10);
mpsc_init(&i->foreign_decls_to_check, a); // 1<<10);
mpsc_init(&i->intrinsics_entry_point_usage, a); // 1<<10); // just waste some memory here, even if it probably never used
string_map_init(&i->load_directory_cache);
@@ -1382,6 +1383,7 @@ gb_internal void destroy_checker_info(CheckerInfo *i) {
mpsc_destroy(&i->required_global_variable_queue);
mpsc_destroy(&i->required_foreign_imports_through_force_queue);
mpsc_destroy(&i->foreign_imports_to_check_fullpaths);
mpsc_destroy(&i->foreign_decls_to_check);
map_destroy(&i->objc_msgSend_types);
string_map_destroy(&i->load_file_cache);
@@ -5094,6 +5096,38 @@ gb_internal void check_foreign_import_fullpaths(Checker *c) {
e->LibraryName.paths = fl->fullpaths;
}
for (Entity *e = nullptr; mpsc_dequeue(&c->info.foreign_decls_to_check, &e); /**/) {
GB_ASSERT(e != nullptr);
if (e->kind != Entity_Procedure) {
continue;
}
if (!is_arch_wasm()) {
continue;
}
Entity *foreign_library = e->Procedure.foreign_library;
GB_ASSERT(foreign_library != nullptr);
String name = e->Procedure.link_name;
String module_name = str_lit("env");
GB_ASSERT (foreign_library->kind == Entity_LibraryName);
if (foreign_library->LibraryName.paths.count != 1) {
error(foreign_library->token, "'foreign import' for '%.*s' architecture may only have one path, got %td",
LIT(target_arch_names[build_context.metrics.arch]), foreign_library->LibraryName.paths.count);
}
if (foreign_library->LibraryName.paths.count >= 1) {
module_name = foreign_library->LibraryName.paths[0];
}
if (!string_ends_with(module_name, str_lit(".o"))) {
name = concatenate3_strings(permanent_allocator(), module_name, WASM_MODULE_NAME_SEPARATOR, name);
}
e->Procedure.link_name = name;
check_foreign_procedure(&ctx, e, e->decl_info);
}
}
gb_internal void check_add_foreign_import_decl(CheckerContext *ctx, Ast *decl) {