[K/Wasm] Unmute most of the stepping tests for Wasm in K1
This commit is contained in:
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.backend.wasm
|
||||
import org.jetbrains.kotlin.backend.common.linkage.issues.checkNoUnboundSymbols
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaserState
|
||||
import org.jetbrains.kotlin.backend.common.phaser.invokeToplevel
|
||||
import org.jetbrains.kotlin.backend.wasm.ir2wasm.JsModuleAndQualifierReference
|
||||
import org.jetbrains.kotlin.backend.wasm.ir2wasm.WasmCompiledModuleFragment
|
||||
import org.jetbrains.kotlin.backend.wasm.ir2wasm.WasmModuleFragmentGenerator
|
||||
@@ -122,7 +121,7 @@ fun compileWasm(
|
||||
|
||||
val os = ByteArrayOutputStream()
|
||||
|
||||
val sourceMapFileName = "$baseFileName.map".takeIf { generateSourceMaps }
|
||||
val sourceMapFileName = "$baseFileName.wasm.map".takeIf { generateSourceMaps }
|
||||
val sourceLocationMappings =
|
||||
if (generateSourceMaps) mutableListOf<SourceLocationMapping>() else null
|
||||
|
||||
@@ -175,19 +174,19 @@ private fun generateSourceMap(
|
||||
val pathResolver =
|
||||
SourceFilePathResolver.create(sourceMapsInfo.sourceRoots, sourceMapsInfo.sourceMapPrefix, sourceMapsInfo.outputDir)
|
||||
|
||||
var prev: SourceLocation? = null
|
||||
var prev: SourceLocation.Location? = null
|
||||
|
||||
for (mapping in sourceLocationMappings) {
|
||||
val location = mapping.sourceLocation as? SourceLocation.Location ?: continue
|
||||
|
||||
if (location == prev) continue
|
||||
|
||||
prev = location
|
||||
|
||||
location.apply {
|
||||
// TODO resulting path goes too deep since temporary directory we compiled first is deeper than final destination.
|
||||
val relativePath = pathResolver.getPathRelativeToSourceRoots(File(file)).substring(3)
|
||||
sourceMapBuilder.addMapping(relativePath, null, { null }, line, column, null, mapping.offset)
|
||||
when (val location = mapping.sourceLocation.takeIf { it != prev } ?: continue) {
|
||||
is SourceLocation.NoLocation -> sourceMapBuilder.addEmptyMapping(mapping.offset)
|
||||
is SourceLocation.Location -> {
|
||||
location.apply {
|
||||
// TODO resulting path goes too deep since temporary directory we compiled first is deeper than final destination.
|
||||
val relativePath = pathResolver.getPathRelativeToSourceRoots(File(file)).replace(Regex("^\\.\\./"), "")
|
||||
sourceMapBuilder.addMapping(relativePath, null, { null }, line, column, null, mapping.offset)
|
||||
prev = this
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,6 +371,6 @@ fun writeCompilationResult(
|
||||
File(dir, "$fileNameBase.mjs").writeText(result.jsWrapper)
|
||||
|
||||
if (result.sourceMap != null) {
|
||||
File(dir, "$fileNameBase.map").writeText(result.sourceMap)
|
||||
File(dir, "$fileNameBase.wasm.map").writeText(result.sourceMap)
|
||||
}
|
||||
}
|
||||
|
||||
+12
-3
@@ -68,7 +68,7 @@ class BodyGenerator(
|
||||
}
|
||||
|
||||
private fun generateStatement(statement: IrStatement) {
|
||||
when(statement) {
|
||||
when (statement) {
|
||||
is IrExpression -> generateAsStatement(statement)
|
||||
is IrVariable -> statement.acceptVoid(this)
|
||||
else -> error("Unsupported node type: ${statement::class.simpleName}")
|
||||
@@ -518,7 +518,7 @@ class BodyGenerator(
|
||||
// Assumes call arguments are already on the stack
|
||||
private fun tryToGenerateIntrinsicCall(
|
||||
call: IrFunctionAccessExpression,
|
||||
function: IrFunction
|
||||
function: IrFunction,
|
||||
): Boolean {
|
||||
if (tryToGenerateWasmOpIntrinsicCall(call, function)) {
|
||||
return true
|
||||
@@ -655,6 +655,14 @@ class BodyGenerator(
|
||||
|
||||
override fun visitBlockBody(body: IrBlockBody) {
|
||||
body.statements.forEach(::generateStatement)
|
||||
this.body.buildNop(body.getSourceEndLocation())
|
||||
}
|
||||
|
||||
override fun visitInlinedFunctionBlock(inlinedBlock: IrInlinedFunctionBlock) {
|
||||
body.buildNop(inlinedBlock.inlineCall.getSourceLocation())
|
||||
functionContext.stepIntoInlinedFunction(inlinedBlock.inlineCall.symbol.owner)
|
||||
super.visitInlinedFunctionBlock(inlinedBlock)
|
||||
functionContext.stepOutLastInlinedFunction()
|
||||
}
|
||||
|
||||
override fun visitContainerExpression(expression: IrContainerExpression) {
|
||||
@@ -985,5 +993,6 @@ class BodyGenerator(
|
||||
return false
|
||||
}
|
||||
|
||||
private fun IrElement.getSourceLocation() = getSourceLocation(functionContext.irFunction.fileOrNull?.fileEntry)
|
||||
private fun IrElement.getSourceLocation() = getSourceLocation(functionContext.currentFunction.fileOrNull?.fileEntry)
|
||||
private fun IrElement.getSourceEndLocation() = getSourceLocation(functionContext.currentFunction.fileOrNull?.fileEntry, type = LocationType.END)
|
||||
}
|
||||
|
||||
+14
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.wasm.ir2wasm
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.ir.Ir
|
||||
import org.jetbrains.kotlin.backend.wasm.WasmBackendContext
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
@@ -13,6 +14,7 @@ import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
||||
import org.jetbrains.kotlin.wasm.ir.*
|
||||
import java.util.LinkedList
|
||||
|
||||
enum class LoopLabelType { BREAK, CONTINUE }
|
||||
enum class SyntheticLocalType { IS_INTERFACE_PARAMETER, TABLE_SWITCH_SELECTOR }
|
||||
@@ -33,6 +35,7 @@ class WasmFunctionCodegenContext(
|
||||
private val wasmSyntheticLocals = LinkedHashMap<SyntheticLocalType, WasmLocal>()
|
||||
private val loopLevels = LinkedHashMap<Pair<IrLoop, LoopLabelType>, Int>()
|
||||
private val nonLocalReturnLevels = LinkedHashMap<IrReturnableBlockSymbol, Int>()
|
||||
private val inlinedFunctionStack = LinkedList<IrFunction>()
|
||||
|
||||
fun defineLocal(irValueDeclaration: IrValueSymbol) {
|
||||
assert(irValueDeclaration !in wasmLocals) { "Redefinition of local" }
|
||||
@@ -92,4 +95,15 @@ class WasmFunctionCodegenContext(
|
||||
fun referenceLoopLevel(irLoop: IrLoop, labelType: LoopLabelType): Int {
|
||||
return loopLevels.getValue(Pair(irLoop, labelType))
|
||||
}
|
||||
|
||||
val currentFunction: IrFunction
|
||||
get() = inlinedFunctionStack.lastOrNull() ?: irFunction
|
||||
|
||||
fun stepIntoInlinedFunction(inlineFunction: IrFunction) {
|
||||
inlinedFunctionStack.push(inlineFunction)
|
||||
}
|
||||
|
||||
fun stepOutLastInlinedFunction() {
|
||||
inlinedFunctionStack.pop()
|
||||
}
|
||||
}
|
||||
+18
-4
@@ -7,18 +7,32 @@ package org.jetbrains.kotlin.backend.wasm.ir2wasm
|
||||
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrFileEntry
|
||||
import org.jetbrains.kotlin.ir.LineAndColumn
|
||||
import org.jetbrains.kotlin.wasm.ir.WasmExpressionBuilder
|
||||
import org.jetbrains.kotlin.wasm.ir.source.location.SourceLocation
|
||||
|
||||
fun IrElement.getSourceLocation(fileEntry: IrFileEntry?): SourceLocation {
|
||||
enum class LocationType {
|
||||
START {
|
||||
override fun getLineAndColumnNumberFor(irElement: IrElement, fileEntry: IrFileEntry) =
|
||||
fileEntry.getLineAndColumnNumbers(irElement.startOffset)
|
||||
},
|
||||
END {
|
||||
override fun getLineAndColumnNumberFor(irElement: IrElement, fileEntry: IrFileEntry) =
|
||||
fileEntry.getLineAndColumnNumbers(irElement.endOffset)
|
||||
};
|
||||
|
||||
abstract fun getLineAndColumnNumberFor(irElement: IrElement, fileEntry: IrFileEntry): LineAndColumn
|
||||
}
|
||||
|
||||
fun IrElement.getSourceLocation(fileEntry: IrFileEntry?, type: LocationType = LocationType.START): SourceLocation {
|
||||
if (fileEntry == null) return SourceLocation.NoLocation("fileEntry is null")
|
||||
|
||||
val path = fileEntry.name
|
||||
val (startLine, startColumn) = fileEntry.getLineAndColumnNumbers(startOffset)
|
||||
val (line, column) = type.getLineAndColumnNumberFor(this, fileEntry)
|
||||
|
||||
if (startLine < 0 || startColumn < 0) return SourceLocation.NoLocation("startLine or startColumn < 0")
|
||||
if (line < 0 || column < 0) return SourceLocation.NoLocation("startLine or startColumn < 0")
|
||||
|
||||
return SourceLocation.Location(path, startLine, startColumn)
|
||||
return SourceLocation.Location(path, line, column)
|
||||
}
|
||||
|
||||
fun WasmExpressionBuilder.buildUnreachableForVerifier() {
|
||||
|
||||
Reference in New Issue
Block a user