[Wasm] Require location for buildBr* and fix all usages
This commit is contained in:
+10
-9
@@ -540,11 +540,11 @@ class BodyGenerator(
|
|||||||
body.buildBlock("isInterface", WasmRefNullType(WasmHeapType.Simple.Data)) { innerLabel ->
|
body.buildBlock("isInterface", WasmRefNullType(WasmHeapType.Simple.Data)) { innerLabel ->
|
||||||
body.buildGetLocal(parameterLocal, location)
|
body.buildGetLocal(parameterLocal, location)
|
||||||
body.buildStructGet(context.referenceGcType(irBuiltIns.anyClass), WasmSymbol(1), 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.buildStructGet(classITable, context.referenceClassITableInterfaceSlot(irInterface.symbol), location)
|
||||||
body.buildInstr(WasmOp.REF_IS_NULL)
|
body.buildInstr(WasmOp.REF_IS_NULL)
|
||||||
body.buildInstr(WasmOp.I32_EQZ)
|
body.buildInstr(WasmOp.I32_EQZ)
|
||||||
body.buildBr(outerLabel)
|
body.buildBr(outerLabel, location)
|
||||||
}
|
}
|
||||||
body.buildDrop(location)
|
body.buildDrop(location)
|
||||||
body.buildConstI32(0, location)
|
body.buildConstI32(0, location)
|
||||||
@@ -661,12 +661,12 @@ class BodyGenerator(
|
|||||||
|
|
||||||
override fun visitBreak(jump: IrBreak) {
|
override fun visitBreak(jump: IrBreak) {
|
||||||
assert(jump.type == irBuiltIns.nothingType)
|
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) {
|
override fun visitContinue(jump: IrContinue) {
|
||||||
assert(jump.type == irBuiltIns.nothingType)
|
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) {
|
private fun visitFunctionReturn(expression: IrReturn) {
|
||||||
@@ -775,7 +775,7 @@ class BodyGenerator(
|
|||||||
val nonLocalReturnSymbol = expression.returnTargetSymbol as? IrReturnableBlockSymbol
|
val nonLocalReturnSymbol = expression.returnTargetSymbol as? IrReturnableBlockSymbol
|
||||||
if (nonLocalReturnSymbol != null) {
|
if (nonLocalReturnSymbol != null) {
|
||||||
generateWithExpectedType(expression.value, nonLocalReturnSymbol.owner.type)
|
generateWithExpectedType(expression.value, nonLocalReturnSymbol.owner.type)
|
||||||
body.buildBr(functionContext.referenceNonLocalReturnLevel(nonLocalReturnSymbol))
|
body.buildBr(functionContext.referenceNonLocalReturnLevel(nonLocalReturnSymbol), expression.getSourceLocation())
|
||||||
} else {
|
} else {
|
||||||
visitFunctionReturn(expression)
|
visitFunctionReturn(expression)
|
||||||
}
|
}
|
||||||
@@ -838,7 +838,7 @@ class BodyGenerator(
|
|||||||
loop.body?.let { generateAsStatement(it) }
|
loop.body?.let { generateAsStatement(it) }
|
||||||
}
|
}
|
||||||
generateExpression(loop.condition)
|
generateExpression(loop.condition)
|
||||||
body.buildBrIf(wasmLoop)
|
body.buildBrIf(wasmLoop, loop.condition.getSourceLocation())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -860,12 +860,13 @@ class BodyGenerator(
|
|||||||
functionContext.defineLoopLevel(loop, LoopLabelType.CONTINUE, wasmLoop)
|
functionContext.defineLoopLevel(loop, LoopLabelType.CONTINUE, wasmLoop)
|
||||||
|
|
||||||
generateExpression(loop.condition)
|
generateExpression(loop.condition)
|
||||||
body.buildInstr(WasmOp.I32_EQZ)
|
val location = loop.condition.getSourceLocation()
|
||||||
body.buildBrIf(wasmBreakBlock)
|
body.buildInstr(WasmOp.I32_EQZ, location)
|
||||||
|
body.buildBrIf(wasmBreakBlock, location)
|
||||||
loop.body?.let {
|
loop.body?.let {
|
||||||
generateAsStatement(it)
|
generateAsStatement(it)
|
||||||
}
|
}
|
||||||
body.buildBr(wasmLoop)
|
body.buildBr(wasmLoop, SourceLocation.NoLocation("Continue in the loop"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -211,7 +211,7 @@ private fun BodyGenerator.createBinaryTable(
|
|||||||
body.buildBlock("when_block", resultType) { currentBlock ->
|
body.buildBlock("when_block", resultType) { currentBlock ->
|
||||||
val thenBody = { result: IrExpression ->
|
val thenBody = { result: IrExpression ->
|
||||||
generateWithExpectedType(result, expectedType)
|
generateWithExpectedType(result, expectedType)
|
||||||
body.buildBr(currentBlock)
|
body.buildBr(currentBlock, SourceLocation.NoLocation("Break from a when"))
|
||||||
}
|
}
|
||||||
createBinaryTable(
|
createBinaryTable(
|
||||||
selectorLocal = selectorLocal,
|
selectorLocal = selectorLocal,
|
||||||
@@ -337,7 +337,7 @@ private fun BodyGenerator.genTableIntSwitch(
|
|||||||
}
|
}
|
||||||
generateWithExpectedType(expression.expression, expectedType)
|
generateWithExpectedType(expression.expression, expectedType)
|
||||||
|
|
||||||
body.buildBr(baseBlockIndex + 1)
|
body.buildBr(baseBlockIndex + 1, location)
|
||||||
body.buildEnd()
|
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
|
val relativeLevel = numberOfNestedBlocks - absoluteBlockLevel
|
||||||
assert(relativeLevel >= 0) { "Negative relative block index" }
|
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
|
val relativeLevel = numberOfNestedBlocks - absoluteBlockLevel
|
||||||
assert(relativeLevel >= 0) { "Negative relative block index" }
|
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) {
|
fun buildBr(absoluteBlockLevel: Int, location: SourceLocation) {
|
||||||
buildBrInstr(WasmOp.BR, absoluteBlockLevel)
|
buildBrInstr(WasmOp.BR, absoluteBlockLevel, location)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildThrow(tagIdx: Int) {
|
fun buildThrow(tagIdx: Int) {
|
||||||
@@ -108,8 +108,8 @@ abstract class WasmExpressionBuilder {
|
|||||||
buildInstr(WasmOp.CATCH, WasmImmediate.TagIdx(tagIdx))
|
buildInstr(WasmOp.CATCH, WasmImmediate.TagIdx(tagIdx))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildBrIf(absoluteBlockLevel: Int) {
|
fun buildBrIf(absoluteBlockLevel: Int, location: SourceLocation) {
|
||||||
buildBrInstr(WasmOp.BR_IF, absoluteBlockLevel)
|
buildBrInstr(WasmOp.BR_IF, absoluteBlockLevel, location)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildCall(symbol: WasmSymbol<WasmFunction>, location: SourceLocation) {
|
fun buildCall(symbol: WasmSymbol<WasmFunction>, location: SourceLocation) {
|
||||||
|
|||||||
Reference in New Issue
Block a user