[codegenerator][refactor] extract method for tramboline generation
This commit is contained in:
@@ -169,21 +169,12 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
putIfNotNull(GENERATE_INLINED_FUNCTION_BODY_MARKER, when (val it = arguments.generateInlinedFunctionMarkerString) {
|
putIfNotNull(GENERATE_DEBUG_TRAMPOLINE, when (val it = arguments.generateDebugTrampolineString) {
|
||||||
"enable" -> true
|
"enable" -> true
|
||||||
"disable" -> false
|
"disable" -> false
|
||||||
null -> null
|
null -> null
|
||||||
else -> {
|
else -> {
|
||||||
configuration.report(ERROR, "Unsupported -Xg-generate-inline-function-body-marker= value: $it. Possible values are 'enable'/'disable'")
|
configuration.report(ERROR, "Unsupported -Xg-generate-debug-tramboline= value: $it. Possible values are 'enable'/'disable'")
|
||||||
null
|
|
||||||
}
|
|
||||||
})
|
|
||||||
putIfNotNull(GENERATE_WHEN_MARKER, when (val it = arguments.generateWhenMarkerString) {
|
|
||||||
"enable" -> true
|
|
||||||
"disable" -> false
|
|
||||||
null -> null
|
|
||||||
else -> {
|
|
||||||
configuration.report(ERROR, "Unsupported -Xg-generate-when-marker= value: $it. Possible values are 'enable'/'disable'")
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
+3
-9
@@ -166,17 +166,11 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
|||||||
var lightDebugDeprecated: Boolean = false
|
var lightDebugDeprecated: Boolean = false
|
||||||
|
|
||||||
@Argument(
|
@Argument(
|
||||||
value = "-Xg-generate-inline-function-body-marker",
|
value = "-Xg-generate-debug-trampoline",
|
||||||
valueDescription = "{disable|enable}",
|
valueDescription = "{disable|enable}",
|
||||||
description = """generates marker of inlined function body on call site to make debugger breakpoint resolution more accurate"""
|
description = """generates trampolines to make debugger breakpoint resolution more accurate (inlines, when, etc.)"""
|
||||||
)
|
)
|
||||||
var generateInlinedFunctionMarkerString: String? = null
|
var generateDebugTrampolineString: String? = null
|
||||||
@Argument(
|
|
||||||
value = "-Xg-generate-when-marker",
|
|
||||||
valueDescription = "{disable|enable}",
|
|
||||||
description = """generates marker of when to make debugger breakpoint resolution more accurate"""
|
|
||||||
)
|
|
||||||
var generateWhenMarkerString: String? = null
|
|
||||||
|
|
||||||
|
|
||||||
@Argument(
|
@Argument(
|
||||||
|
|||||||
+1
-2
@@ -43,8 +43,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
|||||||
val debug: Boolean get() = configuration.getBoolean(KonanConfigKeys.DEBUG)
|
val debug: Boolean get() = configuration.getBoolean(KonanConfigKeys.DEBUG)
|
||||||
val lightDebug: Boolean = configuration.get(KonanConfigKeys.LIGHT_DEBUG)
|
val lightDebug: Boolean = configuration.get(KonanConfigKeys.LIGHT_DEBUG)
|
||||||
?: target.family.isAppleFamily // Default is true for Apple targets.
|
?: target.family.isAppleFamily // Default is true for Apple targets.
|
||||||
val generateInlinedBodyTrampoline = debug && configuration.get(KonanConfigKeys.GENERATE_INLINED_FUNCTION_BODY_MARKER) ?: false
|
val generateDebugTrampoline = debug && configuration.get(KonanConfigKeys.GENERATE_DEBUG_TRAMPOLINE) ?: false
|
||||||
val generateWhenTrampoline = debug && configuration.get(KonanConfigKeys.GENERATE_WHEN_MARKER) ?: false
|
|
||||||
|
|
||||||
val memoryModel: MemoryModel get() = configuration.get(KonanConfigKeys.MEMORY_MODEL)!!
|
val memoryModel: MemoryModel get() = configuration.get(KonanConfigKeys.MEMORY_MODEL)!!
|
||||||
val destroyRuntimeMode: DestroyRuntimeMode get() = configuration.get(KonanConfigKeys.DESTROY_RUNTIME_MODE)!!
|
val destroyRuntimeMode: DestroyRuntimeMode get() = configuration.get(KonanConfigKeys.DESTROY_RUNTIME_MODE)!!
|
||||||
|
|||||||
+2
-4
@@ -56,10 +56,8 @@ class KonanConfigKeys {
|
|||||||
= CompilerConfigurationKey.create("library version")
|
= CompilerConfigurationKey.create("library version")
|
||||||
val LIGHT_DEBUG: CompilerConfigurationKey<Boolean?>
|
val LIGHT_DEBUG: CompilerConfigurationKey<Boolean?>
|
||||||
= CompilerConfigurationKey.create("add light debug information")
|
= CompilerConfigurationKey.create("add light debug information")
|
||||||
val GENERATE_INLINED_FUNCTION_BODY_MARKER: CompilerConfigurationKey<Boolean?>
|
val GENERATE_DEBUG_TRAMPOLINE: CompilerConfigurationKey<Boolean?>
|
||||||
= CompilerConfigurationKey.create("generates inlined function body marker on call site")
|
= CompilerConfigurationKey.create("generates debug trampolines to make debugger breakpoint resolution more accurate")
|
||||||
val GENERATE_WHEN_MARKER: CompilerConfigurationKey<Boolean?>
|
|
||||||
= CompilerConfigurationKey.create("generates when marker on call site")
|
|
||||||
val LINKER_ARGS: CompilerConfigurationKey<List<String>>
|
val LINKER_ARGS: CompilerConfigurationKey<List<String>>
|
||||||
= CompilerConfigurationKey.create("additional linker arguments")
|
= CompilerConfigurationKey.create("additional linker arguments")
|
||||||
val LIST_PHASES: CompilerConfigurationKey<Boolean>
|
val LIST_PHASES: CompilerConfigurationKey<Boolean>
|
||||||
|
|||||||
+11
-12
@@ -1177,12 +1177,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
|
|
||||||
val whenEmittingContext = WhenEmittingContext(expression)
|
val whenEmittingContext = WhenEmittingContext(expression)
|
||||||
|
|
||||||
val generationContext = (currentCodeContext.functionScope() as? FunctionScope)?.functionGenerationContext
|
generateDebugTrambolineIf("when", expression)
|
||||||
.takeIf { context.config.generateWhenTrampoline }
|
|
||||||
generationContext?.basicBlock("when", expression.startLocation)?.let {
|
|
||||||
generationContext.br(it)
|
|
||||||
generationContext.positionAtEnd(it)
|
|
||||||
}
|
|
||||||
expression.branches.forEach {
|
expression.branches.forEach {
|
||||||
val bbNext = if (it == expression.branches.last())
|
val bbNext = if (it == expression.branches.last())
|
||||||
null
|
null
|
||||||
@@ -1202,6 +1197,15 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun generateDebugTrambolineIf(name: String, expression: IrExpression) {
|
||||||
|
val generationContext = (currentCodeContext.functionScope() as? FunctionScope)?.functionGenerationContext
|
||||||
|
.takeIf { context.config.generateDebugTrampoline }
|
||||||
|
generationContext?.basicBlock(name, expression.startLocation)?.let {
|
||||||
|
generationContext.br(it)
|
||||||
|
generationContext.positionAtEnd(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun generateWhenCase(whenEmittingContext: WhenEmittingContext, branch: IrBranch, bbNext: LLVMBasicBlockRef?) {
|
private fun generateWhenCase(whenEmittingContext: WhenEmittingContext, branch: IrBranch, bbNext: LLVMBasicBlockRef?) {
|
||||||
val brResult = if (isUnconditional(branch))
|
val brResult = if (isUnconditional(branch))
|
||||||
evaluateExpression(branch.result)
|
evaluateExpression(branch.result)
|
||||||
@@ -1824,12 +1828,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
context.log{"evaluateReturnableBlock : ${value.statements.forEach { ir2string(it) }}"}
|
context.log{"evaluateReturnableBlock : ${value.statements.forEach { ir2string(it) }}"}
|
||||||
|
|
||||||
val returnableBlockScope = ReturnableBlockScope(value)
|
val returnableBlockScope = ReturnableBlockScope(value)
|
||||||
val generationContext = (currentCodeContext.functionScope() as? FunctionScope)?.functionGenerationContext
|
generateDebugTrambolineIf("inline", value)
|
||||||
.takeIf { context.config.generateInlinedBodyTrampoline }
|
|
||||||
generationContext?.basicBlock("inline", value.startLocation)?.let {
|
|
||||||
generationContext.br(it)
|
|
||||||
generationContext.positionAtEnd(it)
|
|
||||||
}
|
|
||||||
using(returnableBlockScope) {
|
using(returnableBlockScope) {
|
||||||
using(VariableScope()) {
|
using(VariableScope()) {
|
||||||
value.statements.forEach {
|
value.statements.forEach {
|
||||||
|
|||||||
@@ -2413,7 +2413,7 @@ standaloneTest("check_stacktrace_format") {
|
|||||||
standaloneTest("stack_trace_inline") {
|
standaloneTest("stack_trace_inline") {
|
||||||
// TODO: Enable after the test has been fixed.
|
// TODO: Enable after the test has been fixed.
|
||||||
disabled = !isAppleTarget(project) || project.globalTestArgs.contains('-opt') || (project.testTarget == 'ios_arm64')
|
disabled = !isAppleTarget(project) || project.globalTestArgs.contains('-opt') || (project.testTarget == 'ios_arm64')
|
||||||
flags = ['-g', '-Xg-generate-inline-function-body-marker=enable']
|
flags = ['-g', '-Xg-generate-debug-trampoline=enable']
|
||||||
source = "runtime/exceptions/stack_trace_inline.kt"
|
source = "runtime/exceptions/stack_trace_inline.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -164,7 +164,7 @@ class LldbTests {
|
|||||||
|fun main(args: Array<String>) {
|
|fun main(args: Array<String>) {
|
||||||
| println(question("Subject", args))
|
| println(question("Subject", args))
|
||||||
|}
|
|}
|
||||||
""".trimMargin().binary("kt33055", "-g", "-Xg-generate-inline-function-body-marker=enable")
|
""".trimMargin().binary("kt33055", "-g", "-Xg-generate-debug-trampoline=enable")
|
||||||
"""
|
"""
|
||||||
> b 2
|
> b 2
|
||||||
Breakpoint 1: where = [..]`kfun:#question(kotlin.String;kotlin.Array<kotlin.String>){}kotlin.String [..] at kt33055.kt:2:12, [..]
|
Breakpoint 1: where = [..]`kfun:#question(kotlin.String;kotlin.Array<kotlin.String>){}kotlin.String [..] at kt33055.kt:2:12, [..]
|
||||||
@@ -192,7 +192,7 @@ class LldbTests {
|
|||||||
| else -> print("C")
|
| else -> print("C")
|
||||||
| }
|
| }
|
||||||
|}
|
|}
|
||||||
""".trimMargin().binary("kt33364", "-g", "-Xg-generate-when-marker=enable")
|
""".trimMargin().binary("kt33364", "-g", "-Xg-generate-debug-trampoline=enable")
|
||||||
"""
|
"""
|
||||||
> b 5
|
> b 5
|
||||||
Breakpoint 1: where = [..]kfun:#main(){} [..] at kt33364.kt:5:[..]
|
Breakpoint 1: where = [..]kfun:#main(){} [..] at kt33364.kt:5:[..]
|
||||||
|
|||||||
Reference in New Issue
Block a user