WASM: NFC. Rename string import/export functions

This commit is contained in:
Igor Laevsky
2021-07-23 20:46:35 +03:00
committed by TeamCityServer
parent ebde1e5491
commit 2538caa84f
6 changed files with 7 additions and 7 deletions
@@ -142,7 +142,7 @@ class WasmSymbols(
val wasmThrow = getInternalFunction("wasmThrow")
val exportStringRet = getInternalFunction("exportStringRet")
val exportString = getInternalFunction("exportString")
val unsafeGetScratchRawMemory = getInternalFunction("unsafeGetScratchRawMemory")
private val functionNInterfaces = (0..22).map { arity ->
@@ -133,11 +133,11 @@ fun WasmCompiledModuleFragment.generateJs(): String {
},
println(valueAddr) {
console.log(">>> " + importStringToJs(valueAddr));
console.log(">>> " + importStringFromWasm(valueAddr));
}
};
function importStringToJs(addr) {
function importStringFromWasm(addr) {
const mem16 = new Uint16Array(wasmInstance.exports.memory.buffer);
const mem32 = new Int32Array(wasmInstance.exports.memory.buffer);
const len = mem32[addr / 4];
@@ -371,7 +371,7 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
if (context.irFunction.isExported(context.backendContext) &&
expression.value.type == irBuiltIns.stringType) {
body.buildCall(context.referenceFunction(wasmSymbols.exportStringRet))
body.buildCall(context.referenceFunction(wasmSymbols.exportString))
}
body.buildInstr(WasmOp.RETURN)
@@ -151,7 +151,7 @@ abstract class BasicWasmBoxTest(
const wasmModule = new WebAssembly.Module(wasmBinary);
wasmInstance = new WebAssembly.Instance(wasmModule, { runtime, js_code });
const actualResult = importStringToJs(wasmInstance.exports.$testFunction());
const actualResult = importStringFromWasm(wasmInstance.exports.$testFunction());
if (actualResult !== "OK")
throw `Wrong box result '${'$'}{actualResult}'; Expected "OK"`;
""".trimIndent()
@@ -8,7 +8,7 @@ package kotlin.wasm.internal
// This is called when exported function returns a string. It writes [i32 length, [i16 chars ...]] into a temporary raw memory area and
// returns pointer to the start of it.
// Note: currently there is a single temporary raw memory area so it's not possible to export more than one string at a time.
internal fun exportStringRet(src: String): Int {
internal fun exportString(src: String): Int {
val retAddr = unsafeGetScratchRawMemory(INT_SIZE_BYTES + src.length * CHAR_SIZE_BYTES)
wasm_i32_store(retAddr, src.length)
unsafeCharArrayToRawMemory(src.toCharArray(), retAddr + INT_SIZE_BYTES)
+1 -1
View File
@@ -14,7 +14,7 @@ public actual fun println() {
/** Prints the given [message] and the line separator to the standard output stream. */
public actual fun println(message: Any?) {
printlnImpl(exportStringRet(message.toString()))
printlnImpl(exportString(message.toString()))
}
/** Prints the given [message] to the standard output stream. */