[Wasm] Support external functions

This commit is contained in:
Svyatoslav Kuzmich
2021-09-06 18:18:15 +03:00
parent 7e399202a2
commit c0d48e3417
2 changed files with 7 additions and 6 deletions
@@ -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)
@@ -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