Skip to content

Commit 83c94cc

Browse files
skuzmichSpace
authored andcommitted
[Wasm] Name section for globals and structs
1 parent a5aee29 commit 83c94cc

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

wasm/wasm.ir/src/org/jetbrains/kotlin/wasm/ir/convertors/WasmIrToBinary.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,41 @@ class WasmIrToBinary(outputStream: OutputStream, val module: WasmModule, val mod
141141
}
142142
}
143143
}
144+
145+
// Extended Name Section
146+
// https://github.com/WebAssembly/extended-name-section/blob/main/document/core/appendix/custom.rst
147+
148+
appendSection(4u) {
149+
appendVectorSize(module.gcTypes.size)
150+
module.gcTypes.forEach {
151+
appendModuleFieldReference(it)
152+
b.writeString(it.name)
153+
}
154+
}
155+
156+
appendSection(7u) {
157+
appendVectorSize(module.globals.size)
158+
module.globals.forEach { global ->
159+
appendModuleFieldReference(global)
160+
b.writeString(global.name)
161+
}
162+
}
163+
164+
// Experimental fields name section
165+
// https://github.com/WebAssembly/gc/issues/193
166+
appendSection(10u) {
167+
appendVectorSize(module.gcTypes.size)
168+
module.gcTypes.forEach {
169+
if (it is WasmStructDeclaration) {
170+
appendModuleFieldReference(it)
171+
appendVectorSize(it.fields.size)
172+
it.fields.forEachIndexed { index, field ->
173+
b.writeVarUInt32(index)
174+
b.writeString(field.name)
175+
}
176+
}
177+
}
178+
}
144179
}
145180
}
146181

0 commit comments

Comments
 (0)