diff options
| author | gingerBill <bill@gingerbill.org> | 2021-11-02 12:54:23 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-11-02 12:54:23 +0000 |
| commit | c5cd97dd8968f5f6ad4f130a68008beacda78b64 (patch) | |
| tree | c62e0b5c96d6abf116b47dceee64901b7b40d2d2 /src/llvm_backend_utility.cpp | |
| parent | a4b68b93f2db127fde34c935e0764deaeb06a518 (diff) | |
Improve `wasm-import` semantics to allow procedures from different import paths
Diffstat (limited to 'src/llvm_backend_utility.cpp')
| -rw-r--r-- | src/llvm_backend_utility.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
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)); +} |