From 83c94cc9447c49441f620a5910e9fc66f4eedfc8 Mon Sep 17 00:00:00 2001 From: Svyatoslav Kuzmich Date: Tue, 9 Nov 2021 18:54:35 +0300 Subject: [PATCH] [Wasm] Name section for globals and structs --- .../wasm/ir/convertors/WasmIrToBinary.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/wasm/wasm.ir/src/org/jetbrains/kotlin/wasm/ir/convertors/WasmIrToBinary.kt b/wasm/wasm.ir/src/org/jetbrains/kotlin/wasm/ir/convertors/WasmIrToBinary.kt index c161d060a601e..057f19857f284 100644 --- a/wasm/wasm.ir/src/org/jetbrains/kotlin/wasm/ir/convertors/WasmIrToBinary.kt +++ b/wasm/wasm.ir/src/org/jetbrains/kotlin/wasm/ir/convertors/WasmIrToBinary.kt @@ -141,6 +141,41 @@ class WasmIrToBinary(outputStream: OutputStream, val module: WasmModule, val mod } } } + + // Extended Name Section + // https://github.com/WebAssembly/extended-name-section/blob/main/document/core/appendix/custom.rst + + appendSection(4u) { + appendVectorSize(module.gcTypes.size) + module.gcTypes.forEach { + appendModuleFieldReference(it) + b.writeString(it.name) + } + } + + appendSection(7u) { + appendVectorSize(module.globals.size) + module.globals.forEach { global -> + appendModuleFieldReference(global) + b.writeString(global.name) + } + } + + // Experimental fields name section + // https://github.com/WebAssembly/gc/issues/193 + appendSection(10u) { + appendVectorSize(module.gcTypes.size) + module.gcTypes.forEach { + if (it is WasmStructDeclaration) { + appendModuleFieldReference(it) + appendVectorSize(it.fields.size) + it.fields.forEachIndexed { index, field -> + b.writeVarUInt32(index) + b.writeString(field.name) + } + } + } + } } }