From c0d48e341763ef07b65487b55960df8d9f13fb4f Mon Sep 17 00:00:00 2001 From: Svyatoslav Kuzmich Date: Mon, 6 Sep 2021 18:18:15 +0300 Subject: [PATCH] [Wasm] Support external functions --- .../kotlin/backend/wasm/ir2wasm/BodyGenerator.kt | 2 +- .../backend/wasm/ir2wasm/DeclarationGenerator.kt | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/BodyGenerator.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/BodyGenerator.kt index 3324195ecbe..e23e1e8e4cd 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/BodyGenerator.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/BodyGenerator.kt @@ -296,7 +296,7 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV // Return types of imported functions cannot have concrete struct/array references. // Non-primitive return types are represented as eqref which need to be casted back to expected type on call site. - if (function.getWasmImportAnnotation() != null || function.getJsFunAnnotation() != null) { + if (function.getWasmImportAnnotation() != null || function.getJsFunAnnotation() != null || function.isExternal) { val resT = context.transformResultType(function.returnType) if (resT is WasmRefNullType) { generateTypeRTT(function.returnType) diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/DeclarationGenerator.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/DeclarationGenerator.kt index 6358ae5d16b..b3b4834ce38 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/DeclarationGenerator.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/DeclarationGenerator.kt @@ -49,7 +49,12 @@ class DeclarationGenerator(val context: WasmModuleCodegenContext) : IrElementVis if (declaration is IrConstructor && backendContext.inlineClassesUtils.isClassInlineLike(declaration.parentAsClass)) return - val jsCode = declaration.getJsFunAnnotation() + val isIntrinsic = declaration.hasWasmNoOpCastAnnotation() || declaration.getWasmOpAnnotation() != null + if (isIntrinsic) { + return + } + + val jsCode = declaration.getJsFunAnnotation() ?: if (declaration.isExternal) declaration.name.asString() else null val importedName = if (jsCode != null) { val jsCodeName = jsCodeName(declaration) context.addJsFun(jsCodeName, jsCode) @@ -58,10 +63,6 @@ class DeclarationGenerator(val context: WasmModuleCodegenContext) : IrElementVis declaration.getWasmImportAnnotation() } - val isIntrinsic = declaration.hasWasmNoOpCastAnnotation() || declaration.getWasmOpAnnotation() != null - if (isIntrinsic) { - return - } if (declaration.isFakeOverride) return