From b371b61cf5be1e4ae503f6c546159fd3f1b24fef Mon Sep 17 00:00:00 2001 From: Svyatoslav Kuzmich Date: Wed, 4 Nov 2020 16:12:31 +0300 Subject: [PATCH] [Wasm] Indent blocks of produced WAT Makes it more readable --- .../jetbrains/kotlin/wasm/ir/convertors/WasmIrToText.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wasm/wasm.ir/src/org/jetbrains/kotlin/wasm/ir/convertors/WasmIrToText.kt b/wasm/wasm.ir/src/org/jetbrains/kotlin/wasm/ir/convertors/WasmIrToText.kt index f2b4b5ecc3d..e618079e2f3 100644 --- a/wasm/wasm.ir/src/org/jetbrains/kotlin/wasm/ir/convertors/WasmIrToText.kt +++ b/wasm/wasm.ir/src/org/jetbrains/kotlin/wasm/ir/convertors/WasmIrToText.kt @@ -59,8 +59,16 @@ class WasmIrToText : SExpressionBuilder() { } private fun appendInstr(wasmInstr: WasmInstr) { + val op = wasmInstr.operator + if (op == WasmOp.END || op == WasmOp.ELSE) + indent-- + newLine() stringBuilder.append(wasmInstr.operator.mnemonic) + + if (op == WasmOp.BLOCK || op == WasmOp.LOOP || op == WasmOp.IF || op == WasmOp.ELSE) + indent++ + if (wasmInstr.operator in setOf(WasmOp.CALL_INDIRECT, WasmOp.TABLE_INIT)) { wasmInstr.immediates.reversed().forEach { appendImmediate(it)