[FIR] Support including flow information when dumping CFG dot file
This commit is contained in:
+12
-8
@@ -14,17 +14,16 @@ import org.jetbrains.kotlin.test.frontend.fir.handlers.FirResolvedTypesVerifier
|
||||
import org.jetbrains.kotlin.test.frontend.fir.handlers.FirScopeDumpHandler
|
||||
|
||||
object FirDiagnosticsDirectives : SimpleDirectivesContainer() {
|
||||
val DUMP_CFG by directive(
|
||||
val DUMP_CFG by stringDirective(
|
||||
description = """
|
||||
Dumps control flow graphs of all declarations to `testName.dot` file
|
||||
This directive may be applied only to all modules
|
||||
This directive may be applied only to all modules.
|
||||
Syntax: DUMP_CFG(: [OPTIONS])
|
||||
|
||||
Additional options may be enabled :
|
||||
- ${DumpCfgOption.LEVELS}: Render levels of nodes in CFG dump.
|
||||
- ${DumpCfgOption.FLOW}: Include data analysis variable information in CFG dump for debugging purposes.
|
||||
""".trimIndent(),
|
||||
applicability = Global
|
||||
)
|
||||
|
||||
val RENDERER_CFG_LEVELS by directive(
|
||||
description = "Render leves of nodes in CFG dump",
|
||||
applicability = Global
|
||||
)
|
||||
|
||||
val FIR_DUMP by directive(
|
||||
@@ -96,6 +95,11 @@ object FirDiagnosticsDirectives : SimpleDirectivesContainer() {
|
||||
)
|
||||
}
|
||||
|
||||
object DumpCfgOption {
|
||||
const val LEVELS = "LEVELS"
|
||||
const val FLOW = "FLOW"
|
||||
}
|
||||
|
||||
fun TestConfigurationBuilder.configureFirParser(parser: FirParser) {
|
||||
defaultDirectives {
|
||||
FIR_PARSER with parser
|
||||
|
||||
+6
-3
@@ -6,8 +6,8 @@
|
||||
package org.jetbrains.kotlin.test.frontend.fir.handlers
|
||||
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.FirControlFlowGraphRenderVisitor
|
||||
import org.jetbrains.kotlin.test.directives.DumpCfgOption
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.RENDERER_CFG_LEVELS
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
@@ -24,9 +24,12 @@ class FirCfgDumpHandler(testServices: TestServices) : FirAnalysisHandler(testSer
|
||||
|
||||
override fun processModule(module: TestModule, info: FirOutputArtifact) {
|
||||
if (alreadyDumped || FirDiagnosticsDirectives.DUMP_CFG !in module.directives) return
|
||||
val options = module.directives[FirDiagnosticsDirectives.DUMP_CFG].map { it.uppercase() }
|
||||
|
||||
val file = info.mainFirFiles.values.first()
|
||||
val renderLevels = RENDERER_CFG_LEVELS in module.directives
|
||||
file.accept(FirControlFlowGraphRenderVisitor(builder, renderLevels))
|
||||
val renderLevels = DumpCfgOption.LEVELS in options
|
||||
val renderFlow = DumpCfgOption.FLOW in options
|
||||
file.accept(FirControlFlowGraphRenderVisitor(builder, renderLevels, renderFlow))
|
||||
alreadyDumped = true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user