[Wasm] Don't generate unnecessary unreachable instructions
Helps with WAT readability
This commit is contained in:
@@ -9,6 +9,8 @@ abstract class WasmExpressionBuilder {
|
||||
abstract fun buildInstr(op: WasmOp, vararg immediates: WasmImmediate)
|
||||
abstract var numberOfNestedBlocks: Int
|
||||
|
||||
abstract val lastInstr: WasmOp?
|
||||
|
||||
fun buildConstI32(value: Int) {
|
||||
buildInstr(WasmOp.I32_CONST, WasmImmediate.ConstI32(value))
|
||||
}
|
||||
@@ -30,6 +32,10 @@ abstract class WasmExpressionBuilder {
|
||||
}
|
||||
|
||||
fun buildUnreachable() {
|
||||
// Unreachable is not needed
|
||||
if (lastInstr == WasmOp.UNREACHABLE || lastInstr == WasmOp.RETURN)
|
||||
return
|
||||
|
||||
buildInstr(WasmOp.UNREACHABLE)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,4 +19,7 @@ class WasmIrExpressionBuilder(
|
||||
assert(value >= 0) { "end without matching block" }
|
||||
field = value
|
||||
}
|
||||
|
||||
override val lastInstr: WasmOp?
|
||||
get() = expression.lastOrNull()?.operator
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user