[Wasm] Support external functions
This commit is contained in:
+1
-1
@@ -296,7 +296,7 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
|
|||||||
|
|
||||||
// Return types of imported functions cannot have concrete struct/array references.
|
// 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.
|
// 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)
|
val resT = context.transformResultType(function.returnType)
|
||||||
if (resT is WasmRefNullType) {
|
if (resT is WasmRefNullType) {
|
||||||
generateTypeRTT(function.returnType)
|
generateTypeRTT(function.returnType)
|
||||||
|
|||||||
+6
-5
@@ -49,7 +49,12 @@ class DeclarationGenerator(val context: WasmModuleCodegenContext) : IrElementVis
|
|||||||
if (declaration is IrConstructor && backendContext.inlineClassesUtils.isClassInlineLike(declaration.parentAsClass))
|
if (declaration is IrConstructor && backendContext.inlineClassesUtils.isClassInlineLike(declaration.parentAsClass))
|
||||||
return
|
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 importedName = if (jsCode != null) {
|
||||||
val jsCodeName = jsCodeName(declaration)
|
val jsCodeName = jsCodeName(declaration)
|
||||||
context.addJsFun(jsCodeName, jsCode)
|
context.addJsFun(jsCodeName, jsCode)
|
||||||
@@ -58,10 +63,6 @@ class DeclarationGenerator(val context: WasmModuleCodegenContext) : IrElementVis
|
|||||||
declaration.getWasmImportAnnotation()
|
declaration.getWasmImportAnnotation()
|
||||||
}
|
}
|
||||||
|
|
||||||
val isIntrinsic = declaration.hasWasmNoOpCastAnnotation() || declaration.getWasmOpAnnotation() != null
|
|
||||||
if (isIntrinsic) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (declaration.isFakeOverride)
|
if (declaration.isFakeOverride)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user