From c5cd97dd8968f5f6ad4f130a68008beacda78b64 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 2 Nov 2021 12:54:23 +0000 Subject: Improve `wasm-import` semantics to allow procedures from different import paths --- src/llvm_backend_utility.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/llvm_backend_utility.cpp') diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index 709106bc4..1359d93c2 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -1770,3 +1770,36 @@ LLVMValueRef llvm_get_inline_asm(LLVMTypeRef func_type, String const &str, Strin #endif ); } + + +void lb_set_wasm_import_attributes(LLVMValueRef value, Entity *entity, String import_name) { + if (!is_arch_wasm()) { + return; + } + String module_name = str_lit("env"); + if (entity->Procedure.foreign_library != nullptr) { + Entity *foreign_library = entity->Procedure.foreign_library; + GB_ASSERT(foreign_library->kind == Entity_LibraryName); + GB_ASSERT(foreign_library->LibraryName.paths.count == 1); + + module_name = foreign_library->LibraryName.paths[0]; + + if (string_starts_with(import_name, module_name)) { + import_name = substring(import_name, module_name.len+WASM_MODULE_NAME_SEPARATOR.len, import_name.len); + } + + } + LLVMAddTargetDependentFunctionAttr(value, "wasm-import-module", alloc_cstring(permanent_allocator(), module_name)); + LLVMAddTargetDependentFunctionAttr(value, "wasm-import-name", alloc_cstring(permanent_allocator(), import_name)); +} + + +void lb_set_wasm_export_attributes(LLVMValueRef value, String export_name) { + if (!is_arch_wasm()) { + return; + } + LLVMSetLinkage(value, LLVMDLLExportLinkage); + LLVMSetDLLStorageClass(value, LLVMDLLExportStorageClass); + LLVMSetVisibility(value, LLVMDefaultVisibility); + LLVMAddTargetDependentFunctionAttr(value, "wasm-export-name", alloc_cstring(permanent_allocator(), export_name)); +} -- cgit v1.2.3