[WASM] Remove WasmImport annotation
This commit is contained in:
@@ -110,33 +110,10 @@ fun WasmCompiledModuleFragment.generateJs(): String {
|
||||
var wasmInstance = null;
|
||||
|
||||
const externrefBoxes = new WeakMap();
|
||||
|
||||
const runtime = {
|
||||
identity(x) {
|
||||
return x;
|
||||
},
|
||||
|
||||
println(valueAddr) {
|
||||
console.log(">>> " + importStringFromWasm(valueAddr));
|
||||
},
|
||||
|
||||
printError(valueAddr) {
|
||||
console.error(">>> " + importStringFromWasm(valueAddr));
|
||||
},
|
||||
};
|
||||
|
||||
function importStringFromWasm(addr) {
|
||||
const mem16 = new Uint16Array(wasmInstance.exports.memory.buffer);
|
||||
const mem32 = new Int32Array(wasmInstance.exports.memory.buffer);
|
||||
const len = mem32[addr / 4];
|
||||
const str_start_addr = (addr + 4) / 2;
|
||||
const slice = mem16.slice(str_start_addr, str_start_addr + len);
|
||||
return String.fromCharCode.apply(null, slice);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val jsCode =
|
||||
"\nconst js_code = {${jsFuns.joinToString(",\n") { "\"" + it.importName + "\" : " + it.jsCode }}};"
|
||||
val jsFuns = jsFuns.joinToString(",\n") { "\"" + it.importName + "\" : " + it.jsCode }
|
||||
val jsCode = "\nconst js_code = {$jsFuns};"
|
||||
|
||||
return runtime + jsCode
|
||||
}
|
||||
|
||||
+2
-5
@@ -65,15 +65,12 @@ class DeclarationGenerator(val context: WasmModuleCodegenContext, private val al
|
||||
}
|
||||
|
||||
val jsCode = declaration.getJsFunAnnotation() ?: if (declaration.isExternal) declaration.name.asString() else null
|
||||
val importedName = if (jsCode != null) {
|
||||
val importedName = jsCode?.let {
|
||||
val jsCodeName = jsCodeName(declaration)
|
||||
context.addJsFun(jsCodeName, jsCode)
|
||||
context.addJsFun(jsCodeName, it)
|
||||
WasmImportPair("js_code", jsCodeName(declaration))
|
||||
} else {
|
||||
declaration.getWasmImportAnnotation()
|
||||
}
|
||||
|
||||
|
||||
if (declaration.isFakeOverride)
|
||||
return
|
||||
|
||||
|
||||
@@ -29,15 +29,6 @@ fun IrAnnotationContainer.hasWasmNoOpCastAnnotation(): Boolean =
|
||||
fun IrAnnotationContainer.hasWasmAutoboxedAnnotation(): Boolean =
|
||||
hasAnnotation(FqName("kotlin.wasm.internal.WasmAutoboxed"))
|
||||
|
||||
fun IrAnnotationContainer.getWasmImportAnnotation(): WasmImportPair? =
|
||||
getAnnotation(FqName("kotlin.wasm.internal.WasmImport"))?.let {
|
||||
WasmImportPair(
|
||||
(it.getValueArgument(0) as IrConst<*>).value as String,
|
||||
(it.getValueArgument(1) as IrConst<*>).value as String
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
class WasmArrayInfo(val klass: IrClass, val isNullable: Boolean) {
|
||||
val type = klass.defaultType.let { if (isNullable) it.makeNullable() else it }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user