[Native] Replace consequence line and column calls with a single one
This commit is contained in:
+11
-6
@@ -6,16 +6,20 @@
|
||||
package org.jetbrains.kotlin.backend.konan.llvm
|
||||
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import kotlinx.cinterop.cValuesOf
|
||||
import kotlinx.cinterop.memScoped
|
||||
import kotlinx.cinterop.toCValues
|
||||
import kotlinx.cinterop.toKString
|
||||
import llvm.*
|
||||
import org.jetbrains.kotlin.backend.konan.*
|
||||
import org.jetbrains.kotlin.backend.konan.MemoryModel
|
||||
import org.jetbrains.kotlin.backend.konan.NativeGenerationState
|
||||
import org.jetbrains.kotlin.backend.konan.RuntimeNames
|
||||
import org.jetbrains.kotlin.backend.konan.cgen.CBridgeOrigin
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.ClassGlobalHierarchyInfo
|
||||
import org.jetbrains.kotlin.backend.konan.ir.*
|
||||
import org.jetbrains.kotlin.backend.konan.ir.isAny
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.ThreadState.Native
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.ThreadState.Runnable
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.objc.*
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.objc.ObjCDataGenerator
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.objcinterop.*
|
||||
@@ -343,7 +347,8 @@ private fun CodeGenerator.getVirtualFunctionTrampolineImpl(irFunction: IrSimpleF
|
||||
}
|
||||
}
|
||||
@Suppress("UNCHECKED_CAST") val location = diFunctionScope?.let {
|
||||
LocationInfo(it as DIScopeOpaqueRef, file.fileEntry.line(offset!!), file.fileEntry.column(offset))
|
||||
val (line, column) = file.fileEntry.lineAndColumn(offset!!)
|
||||
LocationInfo(it as DIScopeOpaqueRef, line, column)
|
||||
}
|
||||
generateFunction(this, proto, needSafePoint = false, startLocation = location, endLocation = location) {
|
||||
val args = proto.signature.parameterTypes.indices.map { param(it) }
|
||||
|
||||
+6
-3
@@ -259,7 +259,7 @@ internal class DebugInfo(override val generationState: NativeGenerationState) :
|
||||
/**
|
||||
* File entry starts offsets from zero while dwarf number lines/column starting from 1.
|
||||
*/
|
||||
private val NO_SOURCE_FILE = "no source file"
|
||||
private const val NO_SOURCE_FILE = "no source file"
|
||||
private fun IrFileEntry.location(offset: Int, offsetToNumber: (Int) -> Int): Int {
|
||||
// Part "name.isEmpty() || name == NO_SOURCE_FILE" is an awful hack, @minamoto, please fix properly.
|
||||
if (offset == UNDEFINED_OFFSET) return 0
|
||||
@@ -270,9 +270,12 @@ private fun IrFileEntry.location(offset: Int, offsetToNumber: (Int) -> Int): Int
|
||||
return result
|
||||
}
|
||||
|
||||
internal fun IrFileEntry.line(offset: Int) = location(offset, this::getLineNumber)
|
||||
internal fun IrFileEntry.lineAndColumn(offset: Int): Pair<Int, Int> {
|
||||
val (line, column) = this.getLineAndColumnNumbers(offset)
|
||||
return location(offset) { line } to location(offset) { column }
|
||||
}
|
||||
|
||||
internal fun IrFileEntry.column(offset: Int) = location(offset, this::getColumnNumber)
|
||||
internal fun IrFileEntry.line(offset: Int) = location(offset, this::getLineNumber)
|
||||
|
||||
internal data class FileAndFolder(val file: String, val folder: String) {
|
||||
companion object {
|
||||
|
||||
+23
-17
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.backend.konan.llvm
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import llvm.*
|
||||
import org.jetbrains.kotlin.ir.util.inlineFunction
|
||||
import org.jetbrains.kotlin.backend.common.ir.isUnconditional
|
||||
import org.jetbrains.kotlin.backend.common.lower.coroutines.getOrCreateFunctionWithContinuationStub
|
||||
import org.jetbrains.kotlin.backend.common.lower.inline.INLINED_FUNCTION_ARGUMENTS
|
||||
@@ -28,10 +27,10 @@ import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.objcinterop.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.objcinterop.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
@@ -781,7 +780,12 @@ internal class CodeGeneratorVisitor(
|
||||
}
|
||||
|
||||
private val fileScope = (fileScope() as? FileScope)
|
||||
override fun location(offset: Int) = scope?.let { scope -> fileScope?.let{LocationInfo(scope, it.file.fileEntry.line(offset), it.file.fileEntry.column(offset)) } }
|
||||
override fun location(offset: Int) = scope?.let { scope ->
|
||||
fileScope?.let {
|
||||
val (line, column) = it.file.fileEntry.lineAndColumn(offset)
|
||||
LocationInfo(scope, line, column)
|
||||
}
|
||||
}
|
||||
|
||||
override fun scope() = scope
|
||||
|
||||
@@ -909,12 +913,12 @@ internal class CodeGeneratorVisitor(
|
||||
verifyModule(llvm.module, "${ir2string(declaration.parent)}::${ir2string(declaration)}")
|
||||
}
|
||||
|
||||
private fun IrFunction.location(start: Boolean) =
|
||||
if (context.shouldContainLocationDebugInfo() && startOffset != UNDEFINED_OFFSET) LocationInfo(
|
||||
scope = scope()!!,
|
||||
line = if (start) startLine() else endLine(),
|
||||
column = if (start) startColumn() else endColumn())
|
||||
else null
|
||||
private fun IrFunction.location(start: Boolean): LocationInfo? {
|
||||
if (!context.shouldContainLocationDebugInfo() || startOffset == UNDEFINED_OFFSET) return null
|
||||
|
||||
val (line, column) = if (start) startLineAndColumn() else endLineAndColumn()
|
||||
return LocationInfo(scope = scope()!!, line = line, column = column)
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
@@ -2115,7 +2119,8 @@ internal class CodeGeneratorVisitor(
|
||||
return if (returnableBlock.inlineFunction != null) {
|
||||
val diScope = functionScope ?: return null
|
||||
val inlinedAt = outerContext.location(returnableBlock.startOffset) ?: return null
|
||||
LocationInfo(diScope, file.fileEntry.line(offset), file.fileEntry.column(offset), inlinedAt)
|
||||
val (line, column) = file.fileEntry.lineAndColumn(offset)
|
||||
LocationInfo(diScope, line, column, inlinedAt)
|
||||
} else {
|
||||
outerContext.location(offset)
|
||||
}
|
||||
@@ -2128,7 +2133,8 @@ internal class CodeGeneratorVisitor(
|
||||
if (!context.shouldContainLocationDebugInfo() || returnableBlock.startOffset == UNDEFINED_OFFSET)
|
||||
return@lazy null
|
||||
val lexicalBlockFile = DICreateLexicalBlockFile(debugInfo.builder, functionScope()!!.scope(), super.file.diFileScope())
|
||||
DICreateLexicalBlock(debugInfo.builder, lexicalBlockFile, super.file.diFileScope(), returnableBlock.startLine(), returnableBlock.startColumn())!!
|
||||
val (line, column) = returnableBlock.startLineAndColumn()
|
||||
DICreateLexicalBlock(debugInfo.builder, lexicalBlockFile, super.file.diFileScope(), line, column)!!
|
||||
}
|
||||
|
||||
override fun scope() = scope
|
||||
@@ -2140,7 +2146,10 @@ internal class CodeGeneratorVisitor(
|
||||
private open inner class FileScope(val file: IrFile) : InnerScopeImpl() {
|
||||
override fun fileScope(): CodeContext? = this
|
||||
|
||||
override fun location(offset: Int) = scope()?.let { LocationInfo(it, file.fileEntry.line(offset), file.fileEntry.column(offset)) }
|
||||
override fun location(offset: Int) = scope()?.let {
|
||||
val (line, column) = file.fileEntry.lineAndColumn(offset)
|
||||
LocationInfo(it, line, column)
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private val scope by lazy {
|
||||
@@ -2271,13 +2280,10 @@ internal class CodeGeneratorVisitor(
|
||||
private fun IrElement.startLine() = file().fileEntry.line(this.startOffset)
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
private fun IrElement.startColumn() = file().fileEntry.column(this.startOffset)
|
||||
private fun IrElement.startLineAndColumn() = file().fileEntry.lineAndColumn(this.startOffset)
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
private fun IrElement.endLine() = file().fileEntry.line(this.endOffset)
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
private fun IrElement.endColumn() = file().fileEntry.column(this.endOffset)
|
||||
private fun IrElement.endLineAndColumn() = file().fileEntry.lineAndColumn(this.endOffset)
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
private fun debugFieldDeclaration(expression: IrField) {
|
||||
|
||||
+6
-13
@@ -4,9 +4,8 @@
|
||||
*/
|
||||
package org.jetbrains.kotlin.backend.konan.llvm.coverage
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.column
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.line
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.computeSymbolName
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.lineAndColumn
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
@@ -25,17 +24,11 @@ class Region(
|
||||
val file: IrFile,
|
||||
val kind: RegionKind
|
||||
) {
|
||||
val startLine: Int
|
||||
get() = file.fileEntry.line(startOffset)
|
||||
val startLineAndColumn: Pair<Int, Int>
|
||||
get() = file.fileEntry.lineAndColumn(startOffset)
|
||||
|
||||
val startColumn: Int
|
||||
get() = file.fileEntry.column(startOffset)
|
||||
|
||||
val endLine: Int
|
||||
get() = file.fileEntry.line(endOffset)
|
||||
|
||||
val endColumn: Int
|
||||
get() = file.fileEntry.column(endOffset)
|
||||
val endLineAndColumn: Pair<Int, Int>
|
||||
get() = file.fileEntry.lineAndColumn(endOffset)
|
||||
|
||||
companion object {
|
||||
fun fromIr(irElement: IrElement, irFile: IrFile, kind: RegionKind = RegionKind.Code) =
|
||||
@@ -48,7 +41,7 @@ class Region(
|
||||
|
||||
override fun toString(): String {
|
||||
val expansion = (kind as? RegionKind.Expansion)?.let { " expand to " + it.expandedFile.name } ?: ""
|
||||
return "${file.name}$expansion: ${kind::class.simpleName} $startLine, $startColumn -> $endLine, $endColumn"
|
||||
return "${file.name}$expansion: ${kind::class.simpleName} $startLineAndColumn -> $endLineAndColumn"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-6
@@ -6,9 +6,7 @@ package org.jetbrains.kotlin.backend.konan.llvm.coverage
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import llvm.*
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.NativeGenerationState
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.name
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.path
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
@@ -20,11 +18,14 @@ private fun RegionKind.toLLVMCoverageRegionKind(): LLVMCoverageRegionKind = when
|
||||
}
|
||||
|
||||
private fun LLVMCoverageRegion.populateFrom(region: Region, regionId: Int, filesIndex: Map<IrFile, Int>) = apply {
|
||||
val (lineStart, columnStart) = region.startLineAndColumn
|
||||
val (lineEnd, columnEnd) = region.endLineAndColumn
|
||||
|
||||
fileId = filesIndex.getValue(region.file)
|
||||
lineStart = region.startLine
|
||||
columnStart = region.startColumn
|
||||
lineEnd = region.endLine
|
||||
columnEnd = region.endColumn
|
||||
this.lineStart = lineStart
|
||||
this.columnStart = columnStart
|
||||
this.lineEnd = lineEnd
|
||||
this.columnEnd = columnEnd
|
||||
counterId = regionId
|
||||
kind = region.kind.toLLVMCoverageRegionKind()
|
||||
expandedFileId = if (region.kind is RegionKind.Expansion) filesIndex.getValue(region.kind.expandedFile) else 0
|
||||
|
||||
Reference in New Issue
Block a user