fun toFormattedString()

in jvm-agent/src/main/org/jetbrains/lincheck/jvm/agent/analysis/controlflow/BasicBlockControlFlowGraph.kt [352:387]


    fun toFormattedString(): String {
        val sb = StringBuilder()

        // Blocks section
        sb.appendLine("BLOCKS")
        val lastInsnIndex = (graph.instructions.size() - 1).takeIf { it >= 0 } ?: 0
        val insnIndexWidth = lastInsnIndex.toString().length
        for (block in graph.basicBlocks) {
            val first = block.range.firstOrNull()
            val last = block.range.lastOrNull()
            val range = when {
                first == null -> "[]"
                first == last -> "[$first]"
                else          -> "[$first..$last]"
            }
            sb.appendLine("B${block.index}: $range")

            // Instructions section
            for (insnIndex in block.range) {
                val insn = graph.instructions.get(insnIndex)
                val text = insn.toFormattedString()
                val idx = insnIndex.toString().padStart(insnIndexWidth, ' ')
                sb.appendLine("  $idx: $text")
            }
        }
        sb.appendLine()

        // Edges section
        sb.appendLine("EDGES")
        graph.edges.let {
            if (it.isNotEmpty()) sb.append(
                it.toFormattedString().prependIndent("  ")
            )
        }
        return sb.toString()
    }