[Wasm] Require location for buildSetLocal and fix all usages

This commit is contained in:
Zalim Bashorov
2022-12-13 17:50:34 +01:00
parent 0b59ef58dc
commit 00d0c38fc3
4 changed files with 15 additions and 11 deletions
@@ -156,7 +156,7 @@ class BodyGenerator(
// Exception object is on top of the stack, store it into the local
aTry.catches.single().catchParameter.symbol.let {
functionContext.defineLocal(it)
body.buildSetLocal(functionContext.referenceLocal(it))
body.buildSetLocal(functionContext.referenceLocal(it), it.owner.getSourceLocation())
}
generateExpression(aTry.catches.single().result)
@@ -253,7 +253,7 @@ class BodyGenerator(
override fun visitSetValue(expression: IrSetValue) {
generateExpression(expression.value)
body.buildSetLocal(functionContext.referenceLocal(expression.symbol))
body.buildSetLocal(functionContext.referenceLocal(expression.symbol), expression.getSourceLocation())
body.commentPreviousInstr { "type: ${expression.symbol.owner.type.render()}" }
body.buildGetUnit()
}
@@ -330,7 +330,7 @@ class BodyGenerator(
}
}
body.buildStructNew(context.referenceGcType(parentClass.symbol))
body.buildSetLocal(thisParameter)
body.buildSetLocal(thisParameter, location)
body.buildEnd()
}
body.commentGroupEnd()
@@ -526,7 +526,7 @@ class BodyGenerator(
if (irInterface.symbol in hierarchyDisjointUnions) {
val classITable = context.referenceClassITableGcType(irInterface.symbol)
val parameterLocal = functionContext.referenceLocal(SyntheticLocalType.IS_INTERFACE_PARAMETER)
body.buildSetLocal(parameterLocal)
body.buildSetLocal(parameterLocal, location)
body.buildBlock("isInterface", WasmI32) { outerLabel ->
body.buildBlock("isInterface", WasmRefNullType(WasmHeapType.Simple.Data)) { innerLabel ->
body.buildGetLocal(parameterLocal, location)
@@ -871,7 +871,7 @@ class BodyGenerator(
val init = declaration.initializer!!
generateExpression(init)
val varName = functionContext.referenceLocal(declaration.symbol)
body.buildSetLocal(varName)
body.buildSetLocal(varName, declaration.getSourceLocation())
}
// Return true if function is recognized as intrinsic.
@@ -921,5 +921,5 @@ class BodyGenerator(
return false
}
private fun IrExpression.getSourceLocation() = getSourceLocation(functionContext.irFunction.fileOrNull?.fileEntry)
private fun IrElement.getSourceLocation() = getSourceLocation(functionContext.irFunction.fileOrNull?.fileEntry)
}
@@ -61,7 +61,10 @@ internal fun BodyGenerator.tryGenerateOptimisedWhen(expression: IrWhen, symbols:
val selectorLocal = functionContext.referenceLocal(SyntheticLocalType.TABLE_SWITCH_SELECTOR)
generateExpression(subject)
body.buildSetLocal(selectorLocal)
// TODO test
val noLocation = SourceLocation.NoLocation("When's binary search infra")
body.buildSetLocal(selectorLocal, noLocation)
val resultType = context.transformBlockResultType(expression.type)
//int overflow or load is too small then make table switch
@@ -77,7 +80,7 @@ internal fun BodyGenerator.tryGenerateOptimisedWhen(expression: IrWhen, symbols:
)
} else {
createBinaryTable(selectorLocal, intBranches)
body.buildSetLocal(selectorLocal)
body.buildSetLocal(selectorLocal, noLocation)
genTableIntSwitch(
selectorLocal = selectorLocal,
resultType = resultType,
@@ -5,11 +5,12 @@
package org.jetbrains.kotlin.backend.wasm.ir2wasm
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrFileEntry
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.wasm.ir.source.location.SourceLocation
fun IrExpression.getSourceLocation(fileEntry: IrFileEntry?): SourceLocation {
fun IrElement.getSourceLocation(fileEntry: IrFileEntry?): SourceLocation {
if (fileEntry == null) return SourceLocation.NoLocation("fileEntry is null")
val path = fileEntry.name
@@ -133,8 +133,8 @@ abstract class WasmExpressionBuilder {
buildInstr(WasmOp.LOCAL_GET, location, WasmImmediate.LocalIdx(local))
}
fun buildSetLocal(local: WasmLocal) {
buildInstr(WasmOp.LOCAL_SET, WasmImmediate.LocalIdx(local))
fun buildSetLocal(local: WasmLocal, location: SourceLocation) {
buildInstr(WasmOp.LOCAL_SET, location, WasmImmediate.LocalIdx(local))
}
fun buildGetGlobal(global: WasmSymbol<WasmGlobal>) {