[Wasm] Require location for buildBr* and fix all usages

This commit is contained in:
Zalim Bashorov
2022-12-13 20:16:35 +01:00
parent 95c84d5d3f
commit 1244cd1259
3 changed files with 20 additions and 19 deletions
@@ -540,11 +540,11 @@ class BodyGenerator(
body.buildBlock("isInterface", WasmRefNullType(WasmHeapType.Simple.Data)) { innerLabel ->
body.buildGetLocal(parameterLocal, location)
body.buildStructGet(context.referenceGcType(irBuiltIns.anyClass), WasmSymbol(1), location)
body.buildBrInstr(WasmOp.BR_ON_CAST_FAIL_DEPRECATED, innerLabel, classITable)
body.buildBrInstr(WasmOp.BR_ON_CAST_FAIL_DEPRECATED, innerLabel, classITable, location)
body.buildStructGet(classITable, context.referenceClassITableInterfaceSlot(irInterface.symbol), location)
body.buildInstr(WasmOp.REF_IS_NULL)
body.buildInstr(WasmOp.I32_EQZ)
body.buildBr(outerLabel)
body.buildBr(outerLabel, location)
}
body.buildDrop(location)
body.buildConstI32(0, location)
@@ -661,12 +661,12 @@ class BodyGenerator(
override fun visitBreak(jump: IrBreak) {
assert(jump.type == irBuiltIns.nothingType)
body.buildBr(functionContext.referenceLoopLevel(jump.loop, LoopLabelType.BREAK))
body.buildBr(functionContext.referenceLoopLevel(jump.loop, LoopLabelType.BREAK), jump.getSourceLocation())
}
override fun visitContinue(jump: IrContinue) {
assert(jump.type == irBuiltIns.nothingType)
body.buildBr(functionContext.referenceLoopLevel(jump.loop, LoopLabelType.CONTINUE))
body.buildBr(functionContext.referenceLoopLevel(jump.loop, LoopLabelType.CONTINUE), jump.getSourceLocation())
}
private fun visitFunctionReturn(expression: IrReturn) {
@@ -775,7 +775,7 @@ class BodyGenerator(
val nonLocalReturnSymbol = expression.returnTargetSymbol as? IrReturnableBlockSymbol
if (nonLocalReturnSymbol != null) {
generateWithExpectedType(expression.value, nonLocalReturnSymbol.owner.type)
body.buildBr(functionContext.referenceNonLocalReturnLevel(nonLocalReturnSymbol))
body.buildBr(functionContext.referenceNonLocalReturnLevel(nonLocalReturnSymbol), expression.getSourceLocation())
} else {
visitFunctionReturn(expression)
}
@@ -838,7 +838,7 @@ class BodyGenerator(
loop.body?.let { generateAsStatement(it) }
}
generateExpression(loop.condition)
body.buildBrIf(wasmLoop)
body.buildBrIf(wasmLoop, loop.condition.getSourceLocation())
}
}
@@ -860,12 +860,13 @@ class BodyGenerator(
functionContext.defineLoopLevel(loop, LoopLabelType.CONTINUE, wasmLoop)
generateExpression(loop.condition)
body.buildInstr(WasmOp.I32_EQZ)
body.buildBrIf(wasmBreakBlock)
val location = loop.condition.getSourceLocation()
body.buildInstr(WasmOp.I32_EQZ, location)
body.buildBrIf(wasmBreakBlock, location)
loop.body?.let {
generateAsStatement(it)
}
body.buildBr(wasmLoop)
body.buildBr(wasmLoop, SourceLocation.NoLocation("Continue in the loop"))
}
}
@@ -211,7 +211,7 @@ private fun BodyGenerator.createBinaryTable(
body.buildBlock("when_block", resultType) { currentBlock ->
val thenBody = { result: IrExpression ->
generateWithExpectedType(result, expectedType)
body.buildBr(currentBlock)
body.buildBr(currentBlock, SourceLocation.NoLocation("Break from a when"))
}
createBinaryTable(
selectorLocal = selectorLocal,
@@ -337,7 +337,7 @@ private fun BodyGenerator.genTableIntSwitch(
}
generateWithExpectedType(expression.expression, expectedType)
body.buildBr(baseBlockIndex + 1)
body.buildBr(baseBlockIndex + 1, location)
body.buildEnd()
}
@@ -78,20 +78,20 @@ abstract class WasmExpressionBuilder {
}
fun buildBrInstr(brOp: WasmOp, absoluteBlockLevel: Int) {
fun buildBrInstr(brOp: WasmOp, absoluteBlockLevel: Int, location: SourceLocation) {
val relativeLevel = numberOfNestedBlocks - absoluteBlockLevel
assert(relativeLevel >= 0) { "Negative relative block index" }
buildInstr(brOp, WasmImmediate.LabelIdx(relativeLevel))
buildInstr(brOp, location, WasmImmediate.LabelIdx(relativeLevel))
}
fun buildBrInstr(brOp: WasmOp, absoluteBlockLevel: Int, symbol: WasmSymbolReadOnly<WasmTypeDeclaration>) {
fun buildBrInstr(brOp: WasmOp, absoluteBlockLevel: Int, symbol: WasmSymbolReadOnly<WasmTypeDeclaration>, location: SourceLocation) {
val relativeLevel = numberOfNestedBlocks - absoluteBlockLevel
assert(relativeLevel >= 0) { "Negative relative block index" }
buildInstr(brOp, WasmImmediate.LabelIdx(relativeLevel), WasmImmediate.TypeIdx(symbol))
buildInstr(brOp, location, WasmImmediate.LabelIdx(relativeLevel), WasmImmediate.TypeIdx(symbol))
}
fun buildBr(absoluteBlockLevel: Int) {
buildBrInstr(WasmOp.BR, absoluteBlockLevel)
fun buildBr(absoluteBlockLevel: Int, location: SourceLocation) {
buildBrInstr(WasmOp.BR, absoluteBlockLevel, location)
}
fun buildThrow(tagIdx: Int) {
@@ -108,8 +108,8 @@ abstract class WasmExpressionBuilder {
buildInstr(WasmOp.CATCH, WasmImmediate.TagIdx(tagIdx))
}
fun buildBrIf(absoluteBlockLevel: Int) {
buildBrInstr(WasmOp.BR_IF, absoluteBlockLevel)
fun buildBrIf(absoluteBlockLevel: Int, location: SourceLocation) {
buildBrInstr(WasmOp.BR_IF, absoluteBlockLevel, location)
}
fun buildCall(symbol: WasmSymbol<WasmFunction>, location: SourceLocation) {