[WASM] Add text section to implement debug info
This commit is contained in:
committed by
teamcityserver
parent
8286927e8c
commit
b8d11f7938
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.wasm.ir.*
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
class WasmIrToBinary(outputStream: OutputStream, val module: WasmModule) {
|
||||
class WasmIrToBinary(outputStream: OutputStream, val module: WasmModule, val moduleName: String, val emitNameSection: Boolean) {
|
||||
var b: ByteWriter = ByteWriter.OutputStream(outputStream)
|
||||
|
||||
fun appendWasmModule() {
|
||||
@@ -109,6 +109,38 @@ class WasmIrToBinary(outputStream: OutputStream, val module: WasmModule) {
|
||||
appendVectorSize(data.size)
|
||||
data.forEach { appendData(it) }
|
||||
}
|
||||
|
||||
//text section (should be placed after data)
|
||||
if (emitNameSection) {
|
||||
appendTextSection(definedFunctions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun appendTextSection(definedFunctions: List<WasmFunction.Defined>) {
|
||||
appendSection(0u) {
|
||||
b.writeString("name")
|
||||
appendSection(0u) {
|
||||
b.writeString(moduleName)
|
||||
}
|
||||
appendSection(1u) {
|
||||
appendVectorSize(definedFunctions.size)
|
||||
definedFunctions.forEach {
|
||||
appendModuleFieldReference(it)
|
||||
b.writeString(it.name)
|
||||
}
|
||||
}
|
||||
appendSection(2u) {
|
||||
appendVectorSize(definedFunctions.size)
|
||||
definedFunctions.forEach {
|
||||
appendModuleFieldReference(it)
|
||||
appendVectorSize(it.locals.size)
|
||||
it.locals.forEach { local ->
|
||||
b.writeVarUInt32(local.id)
|
||||
b.writeString(local.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ fun testWasmFile(wasmFile: File, dirName: String) {
|
||||
|
||||
fun WasmModule.toBinaryFormat(): ByteArray {
|
||||
val os = ByteArrayOutputStream()
|
||||
WasmIrToBinary(os, this).appendWasmModule()
|
||||
WasmIrToBinary(os, this, "<WASM_TESTS>", emitNameSection = false).appendWasmModule()
|
||||
return os.toByteArray()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user