[IR] Drop ir.ir2cfg module

#KTI-952 Fixed
#KT-65773 Related
This commit is contained in:
Wojciech Litewka
2024-03-05 13:09:58 +01:00
committed by Space Team
parent 6fb6f04509
commit cbabfc0fe2
55 changed files with 0 additions and 1848 deletions
-2
View File
@@ -80,7 +80,6 @@
/compiler/ir/backend.wasm/ "Kotlin Wasm"
/compiler/ir/ir.actualization/ "Kotlin Compiler Core" "Kotlin Common Backend" Simon.Ogorodnik
/compiler/ir/ir.interpreter/ "Kotlin Common Backend"
/compiler/ir/ir.ir2cfg/ Mikhail.Glukhikh
/compiler/ir/ir.psi2ir/ "Kotlin JVM"
/compiler/ir/ir.tree/ "Kotlin Common Backend"
/compiler/ir/ir.objcinterop/ "Kotlin Native"
@@ -154,7 +153,6 @@
# UNKNOWN: /compiler/testData/integration/
/compiler/testData/ir/closureAnnotator/ "Kotlin JVM"
/compiler/testData/ir/interpreter/ "Kotlin Common Backend"
/compiler/testData/ir/irCfg/ "Kotlin JVM"
/compiler/testData/ir/irText/ "Kotlin Compiler Core"
/compiler/testData/ir/klibLayout/ "Kotlin Common Backend"
/compiler/testData/ir/sourceRanges/ "Kotlin Compiler Core"
-1
View File
@@ -24,7 +24,6 @@ dependencies {
testApi(projectTests(":compiler:fir:raw-fir:light-tree2fir"))
testApi(projectTests(":compiler:fir:analysis-tests:legacy-fir-tests"))
testApi(projectTests(":generators:test-generator"))
testApi(project(":compiler:ir.ir2cfg"))
testApi(project(":compiler:ir.tree")) // used for deepCopyWithSymbols call that is removed by proguard from the compiler TODO: make it more straightforward
testApi(project(":kotlin-scripting-compiler"))
-18
View File
@@ -1,18 +0,0 @@
plugins {
kotlin("jvm")
id("jps-compatible")
}
dependencies {
api(project(":compiler:util"))
api(project(":compiler:frontend"))
api(project(":compiler:ir.tree"))
}
optInToUnsafeDuringIrConstructionAPI()
sourceSets {
"main" { projectDefault() }
"test" {}
}
@@ -1,31 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.builders
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir2cfg.graph.BasicBlock
interface BasicBlockBuilder {
val incoming: BlockConnectorBuilder?
fun add(element: IrStatement)
val last: IrStatement?
fun build(): BasicBlock
}
@@ -1,29 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.builders
import org.jetbrains.kotlin.ir2cfg.graph.BasicBlock
import org.jetbrains.kotlin.ir2cfg.graph.BlockConnector
interface BlockConnectorBuilder {
fun addNext(basicBlock: BasicBlock)
fun addPrevious(basicBlock: BasicBlock)
fun build(): BlockConnector
}
@@ -1,37 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.builders
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir2cfg.graph.ControlFlowGraph
interface ControlFlowGraphBuilder {
// Add element to the builder pointer
fun add(element: IrStatement)
// Move builder pointer to element without changing graph
fun move(to: IrStatement)
// Connect builder pointer with the given element and move pointer to this element
fun jump(to: IrStatement)
// Connect from with to and move pointer to the destination
fun jump(to: IrStatement, from: IrStatement)
// Build CFG from builder
fun build(): ControlFlowGraph
}
@@ -1,36 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.generators
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir2cfg.graph.BasicBlock
import org.jetbrains.kotlin.ir2cfg.graph.BlockConnector
class BasicBlockImpl(override val elements: List<IrStatement>) : BasicBlock {
override var incoming: BlockConnector? = null
internal set(arg) {
if (field != null) throw AssertionError("Incoming connector cannot be changed after being set")
field = arg
}
override var outgoing: BlockConnector? = null
internal set(arg) {
if (field != null) throw AssertionError("Outgoing connector cannot be changed after being set")
field = arg
}
}
@@ -1,28 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.generators
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir2cfg.graph.BasicBlock
import org.jetbrains.kotlin.ir2cfg.graph.BlockConnector
import org.jetbrains.kotlin.ir2cfg.graph.ControlFlowGraph
class ControlFlowGraphImpl(
override val function: IrFunction,
override val blocks: List<BasicBlock>,
override val connectors: List<BlockConnector>
) : ControlFlowGraph
@@ -1,110 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.generators
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir2cfg.builders.BasicBlockBuilder
import org.jetbrains.kotlin.ir2cfg.builders.BlockConnectorBuilder
import org.jetbrains.kotlin.ir2cfg.builders.ControlFlowGraphBuilder
import org.jetbrains.kotlin.ir2cfg.graph.BasicBlock
import org.jetbrains.kotlin.ir2cfg.graph.BlockConnector
import org.jetbrains.kotlin.ir2cfg.graph.ControlFlowGraph
class FunctionBuilder(val function: IrFunction) : ControlFlowGraphBuilder {
private val blockBuilderMap = mutableMapOf<IrStatement, BasicBlockBuilder>()
private var currentBlockBuilder: BasicBlockBuilder? = null
private val blocks = mutableListOf<BasicBlock>()
private val connectorBuilderMap = mutableMapOf<IrStatement, BlockConnectorBuilder>()
private fun createBlockBuilder(after: BlockConnectorBuilder?): BasicBlockBuilder {
val result = GeneralBlockBuilder(after)
currentBlockBuilder = result
return result
}
private fun BasicBlockBuilder.shiftTo(element: IrStatement) {
blockBuilderMap.remove(last)
add(element)
blockBuilderMap[element] = this
}
override fun add(element: IrStatement) {
val blockBuilder = currentBlockBuilder ?: createBlockBuilder(connectorBuilderMap[element])
blockBuilder.shiftTo(element)
}
override fun move(to: IrStatement) {
val blockBuilder = blockBuilderMap[to]
?: connectorBuilderMap[to]?.let { createBlockBuilder(it) }
?: throw AssertionError("Function generator may move to an element only to the end of a block or to connector")
currentBlockBuilder = blockBuilder
}
override fun jump(to: IrStatement) {
val blockBuilder = currentBlockBuilder
?: throw AssertionError("Function generator: no default block builder for jump")
val block = blockBuilder.build()
blocks.add(block)
blockBuilderMap.values.remove(blockBuilder)
currentBlockBuilder = null
val nextConnectorBuilder = connectorBuilderMap[to] ?: GeneralConnectorBuilder(to)
nextConnectorBuilder.addPrevious(block)
val previousConnectorBuilder = blockBuilder.incoming
previousConnectorBuilder?.addNext(block)
connectorBuilderMap[to] = nextConnectorBuilder
move(to)
}
override fun jump(to: IrStatement, from: IrStatement) {
currentBlockBuilder = blockBuilderMap[from]
if (currentBlockBuilder == null) {
val blockBuilder = connectorBuilderMap[from]?.let { createBlockBuilder(it) }
?: throw AssertionError("Function generator may jump after an element only to the end of a block or to connector")
currentBlockBuilder = blockBuilder
}
jump(to)
}
override fun build(): ControlFlowGraph {
for (blockBuilder in blockBuilderMap.values) {
if (currentBlockBuilder == blockBuilder) {
currentBlockBuilder = null
}
val block = blockBuilder.build()
blocks.add(block)
blockBuilder.incoming?.addNext(block)
}
val connectors = mutableListOf<BlockConnector>()
for (connectorBuilder in connectorBuilderMap.values) {
connectors.add(connectorBuilder.build())
}
for (connector in connectors) {
for (previous in connector.previousBlocks) {
(previous as? BasicBlockImpl)?.outgoing = connector
}
for (next in connector.nextBlocks) {
(next as? BasicBlockImpl)?.incoming = connector
}
}
return ControlFlowGraphImpl(function, blocks, connectors)
}
}
@@ -1,201 +0,0 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.ir2cfg.generators
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrVariable
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.types.isNothing
import org.jetbrains.kotlin.ir.util.dump
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.ir2cfg.graph.ControlFlowGraph
import org.jetbrains.kotlin.ir2cfg.nodes.MergeCfgElement
class FunctionGenerator(val function: IrFunction) {
val builder = FunctionBuilder(function)
val exit = MergeCfgElement(function, "Function exit")
val loopEntries = mutableMapOf<IrLoop, IrStatement>()
val loopExits = mutableMapOf<IrLoop, IrStatement>()
fun generate(): ControlFlowGraph {
val visitor = FunctionVisitor()
function.accept(visitor, true)
return builder.build()
}
inner class FunctionVisitor : IrElementVisitor<IrStatement?, Boolean> {
private inline fun <reified IE : IrElement> IE.process(includeSelf: Boolean = true) = this.accept(this@FunctionVisitor, includeSelf)
override fun visitFunction(declaration: IrFunction, data: Boolean): IrStatement? {
if (data) {
builder.add(declaration)
}
val result = declaration.body?.process() ?: if (data) declaration else null
if (result != null && !result.isNothing()) {
builder.jump(exit, from = result)
}
return result
}
private fun IrStatementContainer.process(): IrStatement? {
var result: IrStatement? = null
for (statement in statements) {
result = statement.process()
}
return result
}
private fun IrElement?.isNothing() = this is IrExpression && type.isNothing()
override fun visitBlockBody(body: IrBlockBody, data: Boolean): IrStatement? {
return body.process()
}
override fun visitContainerExpression(expression: IrContainerExpression, data: Boolean): IrStatement? {
return expression.process() ?: expression
}
override fun visitVariable(declaration: IrVariable, data: Boolean): IrStatement? {
declaration.initializer?.process()
return if (data) {
builder.add(declaration)
declaration
} else null
}
override fun visitReturn(expression: IrReturn, data: Boolean): IrStatement? {
expression.value.process()
if (data) {
builder.add(expression)
}
builder.jump(exit)
return expression
}
override fun visitExpressionBody(body: IrExpressionBody, data: Boolean): IrStatement? {
return body.expression.process()
}
override fun visitExpression(expression: IrExpression, data: Boolean): IrStatement? {
if (data) {
builder.add(expression)
}
return expression
}
override fun visitWhen(expression: IrWhen, data: Boolean): IrStatement? {
if (data) {
builder.add(expression)
}
val whenExit = MergeCfgElement(expression, "When exit")
val branches = expression.branches
for (branch in branches) {
val condition = branch.condition
condition.process(includeSelf = false)
builder.jump(condition)
}
for (branch in branches) {
val result = branch.result
builder.move(branch.condition)
if (!result.process().isNothing()) {
builder.jump(whenExit)
} else {
builder.move(branch.condition)
}
}
return whenExit
}
override fun visitWhileLoop(loop: IrWhileLoop, data: Boolean): IrStatement? {
if (data) {
builder.add(loop)
}
val exit = MergeCfgElement(loop, "While exit")
loopExits[loop] = exit
val entry = MergeCfgElement(loop, "While entry")
loopEntries[loop] = entry
builder.jump(entry)
val condition = loop.condition
condition.process(includeSelf = false)
builder.jump(condition)
val body = loop.body
if (!body?.process().isNothing()) {
builder.jump(entry)
}
builder.jump(exit, from = condition)
return exit
}
override fun visitDoWhileLoop(loop: IrDoWhileLoop, data: Boolean): IrStatement? {
if (data) {
builder.add(loop)
}
val exit = MergeCfgElement(loop, "Do..while exit")
loopExits[loop] = exit
val entry = MergeCfgElement(loop, "Do..while entry")
loopEntries[loop] = entry
builder.jump(entry)
val body = loop.body
val condition = loop.condition
if (!body?.process().isNothing()) {
condition.process(includeSelf = false)
builder.jump(condition)
builder.jump(entry, from = condition)
builder.jump(exit, from = condition)
}
builder.move(exit)
return exit
}
override fun visitBreak(jump: IrBreak, data: Boolean): IrStatement? {
if (data) {
builder.add(jump)
}
builder.jump(loopExits[jump.loop] ?: throw AssertionError("Loop exit not found for ${jump.loop.dump()}"))
return jump
}
override fun visitContinue(jump: IrContinue, data: Boolean): IrStatement? {
if (data) {
builder.add(jump)
}
builder.jump(loopEntries[jump.loop] ?: throw AssertionError("Loop entry not found for ${jump.loop.dump()}"))
return jump
}
override fun visitMemberAccess(expression: IrMemberAccessExpression<*>, data: Boolean): IrStatement? {
expression.dispatchReceiver?.process()
expression.extensionReceiver?.process()
val callee = expression.symbol.owner as IrFunction
for (valueParameter in callee.valueParameters) {
expression.getValueArgument(valueParameter.index)?.process()
}
if (data) {
builder.add(expression)
}
return expression
}
override fun visitTypeOperator(expression: IrTypeOperatorCall, data: Boolean): IrStatement? {
expression.argument.process()
if (data) {
builder.add(expression)
}
return expression
}
override fun visitElement(element: IrElement, data: Boolean): IrStatement? {
TODO("not implemented")
}
}
}
@@ -1,35 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.generators
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir2cfg.builders.BasicBlockBuilder
import org.jetbrains.kotlin.ir2cfg.builders.BlockConnectorBuilder
class GeneralBlockBuilder(override val incoming: BlockConnectorBuilder?) : BasicBlockBuilder {
private val elements = mutableListOf<IrStatement>()
override fun add(element: IrStatement) {
elements.add(element)
}
override val last: IrStatement?
get() = elements.lastOrNull()
override fun build() = BasicBlockImpl(elements.toList())
}
@@ -1,43 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.generators
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir2cfg.builders.BlockConnectorBuilder
import org.jetbrains.kotlin.ir2cfg.graph.BasicBlock
class GeneralConnectorBuilder(private val element: IrStatement) : BlockConnectorBuilder {
private val next = linkedSetOf<BasicBlock>()
private val previous = linkedSetOf<BasicBlock>()
override fun addNext(basicBlock: BasicBlock) {
next.add(basicBlock)
}
override fun addPrevious(basicBlock: BasicBlock) {
previous.add(basicBlock)
}
override fun build() = when {
next.size <= 1 -> JoinBlockConnector(previous.toList(), element, next.firstOrNull())
previous.size == 1 -> SplitBlockConnector(previous.single(), element, next.toList())
else -> throw AssertionError("Connector should have either exactly one previous block or no more than one next block, " +
"actual previous = ${previous.size}, next = ${next.size}")
}
}
@@ -1,30 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.generators
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir2cfg.graph.BasicBlock
import org.jetbrains.kotlin.ir2cfg.graph.BlockConnector
class JoinBlockConnector(
override val previousBlocks: List<BasicBlock>,
override val element: IrStatement,
next: BasicBlock?
) : BlockConnector {
override val nextBlocks = listOfNotNull(next)
}
@@ -1,30 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.generators
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir2cfg.graph.BasicBlock
import org.jetbrains.kotlin.ir2cfg.graph.BlockConnector
class SplitBlockConnector(
previous: BasicBlock,
override val element: IrStatement,
override val nextBlocks: List<BasicBlock>
) : BlockConnector {
override val previousBlocks = listOf(previous)
}
@@ -1,34 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.graph
import org.jetbrains.kotlin.ir.IrStatement
interface BasicBlock : CfgNode {
val elements: List<IrStatement>
val incoming: BlockConnector?
val outgoing: BlockConnector?
override val predecessors: List<CfgNode>
get() = listOfNotNull(incoming)
override val successors: List<CfgNode>
get() = listOfNotNull(outgoing)
}
@@ -1,34 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.graph
import org.jetbrains.kotlin.ir.IrStatement
interface BlockConnector : CfgNode {
val previousBlocks: List<BasicBlock>
val element: IrStatement
val nextBlocks: List<BasicBlock>
override val predecessors: List<CfgNode>
get() = previousBlocks
override val successors: List<CfgNode>
get() = nextBlocks
}
@@ -1,24 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.graph
interface CfgNode {
val predecessors: List<CfgNode>
val successors: List<CfgNode>
}
@@ -1,32 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.graph
import org.jetbrains.kotlin.ir.declarations.IrFunction
interface ControlFlowGraph {
val function: IrFunction
// First block is the entry point
val blocks: List<BasicBlock>
val connectors: List<BlockConnector>
val nodes: List<CfgNode>
get() = blocks + connectors
}
@@ -1,21 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.nodes
import org.jetbrains.kotlin.ir.IrStatement
interface CfgIrElement : IrStatement
@@ -1,37 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.nodes
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.util.dump
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
class MergeCfgElement(val from: IrElement, val name: String) : CfgIrElement {
override val startOffset = from.startOffset
override val endOffset = from.endOffset
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D) = visitor.visitElement(this, data)
override fun <D> transform(transformer: IrElementTransformer<D>, data: D): IrElement = accept(transformer, data)
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) = Unit
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) = Unit
override fun toString() = "$name: ${from.dump()}"
}
@@ -1,79 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir2cfg.util
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.util.dump
import org.jetbrains.kotlin.ir2cfg.graph.BasicBlock
import org.jetbrains.kotlin.ir2cfg.graph.BlockConnector
import org.jetbrains.kotlin.ir2cfg.graph.ControlFlowGraph
import org.jetbrains.kotlin.ir2cfg.nodes.MergeCfgElement
private fun IrElement.cfgDump() = when (this) {
is MergeCfgElement -> "$this"
else -> dump()
}
fun BasicBlock.dump(builder: StringBuilder = StringBuilder(), indent: String = ""): String {
for ((index, element) in elements.withIndex()) {
builder.append(indent)
builder.append(String.format("%3d ", index + 1))
val dump = element.cfgDump()
builder.appendLine(dump.lines().first())
}
return builder.toString()
}
fun BlockConnector.dump(builder: StringBuilder = StringBuilder(), indent: String = ""): String {
builder.append(indent)
val dump = element.cfgDump()
builder.appendLine(dump.lines().first())
return builder.toString()
}
fun ControlFlowGraph.dump(): String {
val connectorIndex = hashMapOf<BlockConnector, Int>()
for ((index, connector) in connectors.withIndex()) {
connectorIndex[connector] = index
}
val blockIndex = hashMapOf<BasicBlock, Int>()
for ((index, block) in blocks.withIndex()) {
blockIndex[block] = index
}
val builder = StringBuilder()
for ((index, block) in blocks.withIndex()) {
builder.appendLine("BB $index")
val incoming = block.incoming
if (incoming != null) {
builder.appendLine(incoming.previousBlocks.joinToString(prefix = "INCOMING <- BB ") { blockIndex[it].toString() })
incoming.dump(builder, " ")
}
builder.appendLine("CONTENT")
block.dump(builder, " ")
val outgoing = block.outgoing
if (outgoing != null) {
if (outgoing.nextBlocks.isEmpty()) {
builder.appendLine("OUTGOING -> NONE")
}
else {
builder.appendLine(outgoing.nextBlocks.joinToString(prefix = "OUTGOING -> BB ") { blockIndex[it].toString() })
}
outgoing.dump(builder, " ")
}
}
return builder.toString()
}
-1
View File
@@ -1 +0,0 @@
fun foo(arg: Int) = arg
-14
View File
@@ -1,14 +0,0 @@
// FILE: /expressionFun.kt
// FUN: foo
BB 0
CONTENT
1 FUN name:foo visibility:public modality:FINAL <> (arg:kotlin.Int) returnType:kotlin.Int
2 GET_VAR 'arg: kotlin.Int declared in <root>.foo' type=kotlin.Int origin=null
3 RETURN type=kotlin.Nothing from='public final fun foo (arg: kotlin.Int): kotlin.Int declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:foo visibility:public modality:FINAL <> (arg:kotlin.Int) returnType:kotlin.Int
// END FUN: foo
// END FILE: /expressionFun.kt
-1
View File
@@ -1 +0,0 @@
fun foo() = Unit
-14
View File
@@ -1,14 +0,0 @@
// FILE: /expressionUnit.kt
// FUN: foo
BB 0
CONTENT
1 FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
2 GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
3 RETURN type=kotlin.Nothing from='public final fun foo (): kotlin.Unit declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
// END FUN: foo
// END FILE: /expressionUnit.kt
-11
View File
@@ -1,11 +0,0 @@
fun digitCountInNumber(n: Int, m: Int): Int {
var count = 0
var number = n
do {
if (m == number % 10) {
count++
}
number /= 10
} while (number > 0)
return count
}
-68
View File
@@ -1,68 +0,0 @@
// FILE: /digitCount.kt
// FUN: digitCountInNumber
BB 0
CONTENT
1 FUN name:digitCountInNumber visibility:public modality:FINAL <> (n:kotlin.Int, m:kotlin.Int) returnType:kotlin.Int
2 CONST Int type=kotlin.Int value=0
3 VAR name:count type:kotlin.Int [var]
4 GET_VAR 'n: kotlin.Int declared in <root>.digitCountInNumber' type=kotlin.Int origin=null
5 VAR name:number type:kotlin.Int [var]
6 DO_WHILE label=null origin=DO_WHILE_LOOP
OUTGOING -> BB 1
Do..while entry: DO_WHILE label=null origin=DO_WHILE_LOOP
BB 1
INCOMING <- BB 0, 4
Do..while entry: DO_WHILE label=null origin=DO_WHILE_LOOP
CONTENT
1 WHEN type=kotlin.Unit origin=IF
2 GET_VAR 'm: kotlin.Int declared in <root>.digitCountInNumber' type=kotlin.Int origin=null
3 GET_VAR 'var number: kotlin.Int [var] declared in <root>.digitCountInNumber' type=kotlin.Int origin=null
4 CONST Int type=kotlin.Int value=10
5 CALL 'public final fun rem (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PERC
OUTGOING -> BB 2
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
BB 2
INCOMING <- BB 1
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
CONTENT
1 GET_VAR 'var count: kotlin.Int [var] declared in <root>.digitCountInNumber' type=kotlin.Int origin=POSTFIX_INCR
2 VAR IR_TEMPORARY_VARIABLE name:tmp0 type:kotlin.Int [val]
3 SET_VAR 'var count: kotlin.Int [var] declared in <root>.digitCountInNumber' type=kotlin.Unit origin=POSTFIX_INCR
4 GET_VAR 'val tmp0: kotlin.Int [val] declared in <root>.digitCountInNumber' type=kotlin.Int origin=null
5 TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
OUTGOING -> BB 3
When exit: WHEN type=kotlin.Unit origin=IF
BB 3
INCOMING <- BB 2
When exit: WHEN type=kotlin.Unit origin=IF
CONTENT
1 SET_VAR 'var number: kotlin.Int [var] declared in <root>.digitCountInNumber' type=kotlin.Unit origin=DIVEQ
2 GET_VAR 'var number: kotlin.Int [var] declared in <root>.digitCountInNumber' type=kotlin.Int origin=null
3 CONST Int type=kotlin.Int value=0
OUTGOING -> BB 4, 5
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
BB 4
INCOMING <- BB 3
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
CONTENT
OUTGOING -> BB 1
Do..while entry: DO_WHILE label=null origin=DO_WHILE_LOOP
BB 5
INCOMING <- BB 3
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
CONTENT
OUTGOING -> BB 6
Do..while exit: DO_WHILE label=null origin=DO_WHILE_LOOP
BB 6
INCOMING <- BB 5
Do..while exit: DO_WHILE label=null origin=DO_WHILE_LOOP
CONTENT
1 GET_VAR 'var count: kotlin.Int [var] declared in <root>.digitCountInNumber' type=kotlin.Int origin=null
2 RETURN type=kotlin.Nothing from='public final fun digitCountInNumber (n: kotlin.Int, m: kotlin.Int): kotlin.Int declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:digitCountInNumber visibility:public modality:FINAL <> (n:kotlin.Int, m:kotlin.Int) returnType:kotlin.Int
// END FUN: digitCountInNumber
// END FILE: /digitCount.kt
-7
View File
@@ -1,7 +0,0 @@
fun factorial(i: Int): Int {
var result = 1
for (j in 2..i) {
result *= j
}
return result
}
-51
View File
@@ -1,51 +0,0 @@
// FILE: /factorial.kt
// FUN: factorial
BB 0
CONTENT
1 FUN name:factorial visibility:public modality:FINAL <> (i:kotlin.Int) returnType:kotlin.Int
2 CONST Int type=kotlin.Int value=1
3 VAR name:result type:kotlin.Int [var]
4 CONST Int type=kotlin.Int value=2
5 GET_VAR 'i: kotlin.Int declared in <root>.factorial' type=kotlin.Int origin=null
6 CALL 'public final fun rangeTo (other: kotlin.Int): kotlin.ranges.IntRange [operator] declared in kotlin.Int' type=kotlin.ranges.IntRange origin=RANGE
7 CALL 'public open fun iterator (): kotlin.collections.IntIterator [fake_override,operator] declared in kotlin.ranges.IntRange' type=kotlin.collections.IntIterator origin=FOR_LOOP_ITERATOR
8 VAR FOR_LOOP_ITERATOR name:tmp0_iterator type:kotlin.collections.IntIterator [val]
9 WHILE label=null origin=FOR_LOOP_INNER_WHILE
OUTGOING -> BB 1
While entry: WHILE label=null origin=FOR_LOOP_INNER_WHILE
BB 1
INCOMING <- BB 0, 2
While entry: WHILE label=null origin=FOR_LOOP_INNER_WHILE
CONTENT
1 GET_VAR 'val tmp0_iterator: kotlin.collections.IntIterator [val] declared in <root>.factorial' type=kotlin.collections.IntIterator origin=null
OUTGOING -> BB 2, 3
CALL 'public abstract fun hasNext (): kotlin.Boolean [fake_override,operator] declared in kotlin.collections.IntIterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
BB 2
INCOMING <- BB 1
CALL 'public abstract fun hasNext (): kotlin.Boolean [fake_override,operator] declared in kotlin.collections.IntIterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
CONTENT
1 GET_VAR 'val tmp0_iterator: kotlin.collections.IntIterator [val] declared in <root>.factorial' type=kotlin.collections.IntIterator origin=null
2 CALL 'public final fun next (): kotlin.Int [operator] declared in kotlin.collections.IntIterator' type=kotlin.Int origin=FOR_LOOP_NEXT
3 VAR FOR_LOOP_VARIABLE name:j type:kotlin.Int [val]
4 SET_VAR 'var result: kotlin.Int [var] declared in <root>.factorial' type=kotlin.Unit origin=MULTEQ
OUTGOING -> BB 1
While entry: WHILE label=null origin=FOR_LOOP_INNER_WHILE
BB 3
INCOMING <- BB 1
CALL 'public abstract fun hasNext (): kotlin.Boolean [fake_override,operator] declared in kotlin.collections.IntIterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
CONTENT
OUTGOING -> BB 4
While exit: WHILE label=null origin=FOR_LOOP_INNER_WHILE
BB 4
INCOMING <- BB 3
While exit: WHILE label=null origin=FOR_LOOP_INNER_WHILE
CONTENT
1 GET_VAR 'var result: kotlin.Int [var] declared in <root>.factorial' type=kotlin.Int origin=null
2 RETURN type=kotlin.Nothing from='public final fun factorial (i: kotlin.Int): kotlin.Int declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:factorial visibility:public modality:FINAL <> (i:kotlin.Int) returnType:kotlin.Int
// END FUN: factorial
// END FILE: /factorial.kt
-9
View File
@@ -1,9 +0,0 @@
fun isPerfect(n: Int): Boolean {
var sum = 1
for (m in 2..n/2) {
if (n % m > 0) continue
sum += m
if (sum > n) break
}
return sum == n
}
-89
View File
@@ -1,89 +0,0 @@
// FILE: /isPerfect.kt
// FUN: isPerfect
BB 0
CONTENT
1 FUN name:isPerfect visibility:public modality:FINAL <> (n:kotlin.Int) returnType:kotlin.Boolean
2 CONST Int type=kotlin.Int value=1
3 VAR name:sum type:kotlin.Int [var]
4 CONST Int type=kotlin.Int value=2
5 GET_VAR 'n: kotlin.Int declared in <root>.isPerfect' type=kotlin.Int origin=null
6 CONST Int type=kotlin.Int value=2
7 CALL 'public final fun div (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=DIV
8 CALL 'public final fun rangeTo (other: kotlin.Int): kotlin.ranges.IntRange [operator] declared in kotlin.Int' type=kotlin.ranges.IntRange origin=RANGE
9 CALL 'public open fun iterator (): kotlin.collections.IntIterator [fake_override,operator] declared in kotlin.ranges.IntRange' type=kotlin.collections.IntIterator origin=FOR_LOOP_ITERATOR
10 VAR FOR_LOOP_ITERATOR name:tmp0_iterator type:kotlin.collections.IntIterator [val]
11 WHILE label=null origin=FOR_LOOP_INNER_WHILE
OUTGOING -> BB 1
While entry: WHILE label=null origin=FOR_LOOP_INNER_WHILE
BB 1
INCOMING <- BB 0, 3, 6
While entry: WHILE label=null origin=FOR_LOOP_INNER_WHILE
CONTENT
1 GET_VAR 'val tmp0_iterator: kotlin.collections.IntIterator [val] declared in <root>.isPerfect' type=kotlin.collections.IntIterator origin=null
OUTGOING -> BB 2, 7
CALL 'public abstract fun hasNext (): kotlin.Boolean [fake_override,operator] declared in kotlin.collections.IntIterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
BB 2
INCOMING <- BB 1
CALL 'public abstract fun hasNext (): kotlin.Boolean [fake_override,operator] declared in kotlin.collections.IntIterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
CONTENT
1 GET_VAR 'val tmp0_iterator: kotlin.collections.IntIterator [val] declared in <root>.isPerfect' type=kotlin.collections.IntIterator origin=null
2 CALL 'public final fun next (): kotlin.Int [operator] declared in kotlin.collections.IntIterator' type=kotlin.Int origin=FOR_LOOP_NEXT
3 VAR FOR_LOOP_VARIABLE name:m type:kotlin.Int [val]
4 WHEN type=kotlin.Unit origin=IF
5 GET_VAR 'n: kotlin.Int declared in <root>.isPerfect' type=kotlin.Int origin=null
6 GET_VAR 'val m: kotlin.Int [val] declared in <root>.isPerfect' type=kotlin.Int origin=null
7 CALL 'public final fun rem (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PERC
8 CONST Int type=kotlin.Int value=0
OUTGOING -> BB 3, 4
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
BB 3
INCOMING <- BB 2
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
CONTENT
1 CONTINUE label=null loop.label=null
OUTGOING -> BB 1
While entry: WHILE label=null origin=FOR_LOOP_INNER_WHILE
BB 4
INCOMING <- BB 2
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
CONTENT
1 SET_VAR 'var sum: kotlin.Int [var] declared in <root>.isPerfect' type=kotlin.Unit origin=PLUSEQ
2 WHEN type=kotlin.Unit origin=IF
3 GET_VAR 'var sum: kotlin.Int [var] declared in <root>.isPerfect' type=kotlin.Int origin=null
4 GET_VAR 'n: kotlin.Int declared in <root>.isPerfect' type=kotlin.Int origin=null
OUTGOING -> BB 5, 6
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
BB 5
INCOMING <- BB 4
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
CONTENT
1 BREAK label=null loop.label=null
OUTGOING -> BB 8
While exit: WHILE label=null origin=FOR_LOOP_INNER_WHILE
BB 6
INCOMING <- BB 4
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
CONTENT
OUTGOING -> BB 1
While entry: WHILE label=null origin=FOR_LOOP_INNER_WHILE
BB 7
INCOMING <- BB 1
CALL 'public abstract fun hasNext (): kotlin.Boolean [fake_override,operator] declared in kotlin.collections.IntIterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
CONTENT
OUTGOING -> BB 8
While exit: WHILE label=null origin=FOR_LOOP_INNER_WHILE
BB 8
INCOMING <- BB 5, 7
While exit: WHILE label=null origin=FOR_LOOP_INNER_WHILE
CONTENT
1 GET_VAR 'var sum: kotlin.Int [var] declared in <root>.isPerfect' type=kotlin.Int origin=null
2 GET_VAR 'n: kotlin.Int declared in <root>.isPerfect' type=kotlin.Int origin=null
3 CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
4 RETURN type=kotlin.Nothing from='public final fun isPerfect (n: kotlin.Int): kotlin.Boolean declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:isPerfect visibility:public modality:FINAL <> (n:kotlin.Int) returnType:kotlin.Boolean
// END FUN: isPerfect
// END FILE: /isPerfect.kt
-3
View File
@@ -1,3 +0,0 @@
fun foo() {
return Unit
}
-14
View File
@@ -1,14 +0,0 @@
// FILE: /returnUnit.kt
// FUN: foo
BB 0
CONTENT
1 FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
2 GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
3 RETURN type=kotlin.Nothing from='public final fun foo (): kotlin.Unit declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
// END FUN: foo
// END FILE: /returnUnit.kt
-4
View File
@@ -1,4 +0,0 @@
fun foo(arg: Int): Int {
val dbl = arg * 2
return dbl
}
-18
View File
@@ -1,18 +0,0 @@
// FILE: /sequentialFun.kt
// FUN: foo
BB 0
CONTENT
1 FUN name:foo visibility:public modality:FINAL <> (arg:kotlin.Int) returnType:kotlin.Int
2 GET_VAR 'arg: kotlin.Int declared in <root>.foo' type=kotlin.Int origin=null
3 CONST Int type=kotlin.Int value=2
4 CALL 'public final fun times (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=MUL
5 VAR name:dbl type:kotlin.Int [val]
6 GET_VAR 'val dbl: kotlin.Int [val] declared in <root>.foo' type=kotlin.Int origin=null
7 RETURN type=kotlin.Nothing from='public final fun foo (arg: kotlin.Int): kotlin.Int declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:foo visibility:public modality:FINAL <> (arg:kotlin.Int) returnType:kotlin.Int
// END FUN: foo
// END FILE: /sequentialFun.kt
-1
View File
@@ -1 +0,0 @@
fun foo() {}
-12
View File
@@ -1,12 +0,0 @@
// FILE: /simpleFun.kt
// FUN: foo
BB 0
CONTENT
1 FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
OUTGOING -> NONE
Function exit: FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
// END FUN: foo
// END FILE: /simpleFun.kt
-3
View File
@@ -1,3 +0,0 @@
fun foo() {
return
}
-14
View File
@@ -1,14 +0,0 @@
// FILE: /simpleReturn.kt
// FUN: foo
BB 0
CONTENT
1 FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
2 GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
3 RETURN type=kotlin.Nothing from='public final fun foo (): kotlin.Unit declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
// END FUN: foo
// END FILE: /simpleReturn.kt
-1
View File
@@ -1 +0,0 @@
fun compare(x: Int, y: Int) = if (x > y) 1 else if (x < y) -1 else 0
-57
View File
@@ -1,57 +0,0 @@
// FILE: /cascadeIf.kt
// FUN: compare
BB 0
CONTENT
1 FUN name:compare visibility:public modality:FINAL <> (x:kotlin.Int, y:kotlin.Int) returnType:kotlin.Int
2 WHEN type=kotlin.Int origin=IF
3 GET_VAR 'x: kotlin.Int declared in <root>.compare' type=kotlin.Int origin=null
4 GET_VAR 'y: kotlin.Int declared in <root>.compare' type=kotlin.Int origin=null
OUTGOING -> BB 1, 3
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
BB 1
INCOMING <- BB 0
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
CONTENT
1 GET_VAR 'x: kotlin.Int declared in <root>.compare' type=kotlin.Int origin=null
2 GET_VAR 'y: kotlin.Int declared in <root>.compare' type=kotlin.Int origin=null
OUTGOING -> BB 2, 4
CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
BB 2
INCOMING <- BB 1
CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
CONTENT
OUTGOING -> BB 5
CONST Boolean type=kotlin.Boolean value=true
BB 3
INCOMING <- BB 0
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
CONTENT
1 CONST Int type=kotlin.Int value=1
OUTGOING -> BB 6
When exit: WHEN type=kotlin.Int origin=IF
BB 4
INCOMING <- BB 1
CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
CONTENT
1 CONST Int type=kotlin.Int value=-1
OUTGOING -> BB 6
When exit: WHEN type=kotlin.Int origin=IF
BB 5
INCOMING <- BB 2
CONST Boolean type=kotlin.Boolean value=true
CONTENT
1 CONST Int type=kotlin.Int value=0
OUTGOING -> BB 6
When exit: WHEN type=kotlin.Int origin=IF
BB 6
INCOMING <- BB 3, 4, 5
When exit: WHEN type=kotlin.Int origin=IF
CONTENT
1 RETURN type=kotlin.Nothing from='public final fun compare (x: kotlin.Int, y: kotlin.Int): kotlin.Int declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:compare visibility:public modality:FINAL <> (x:kotlin.Int, y:kotlin.Int) returnType:kotlin.Int
// END FUN: compare
// END FILE: /cascadeIf.kt
-3
View File
@@ -1,3 +0,0 @@
fun empty() = when {
else -> 42
}
-27
View File
@@ -1,27 +0,0 @@
// FILE: /emptyWhen.kt
// FUN: empty
BB 0
CONTENT
1 FUN name:empty visibility:public modality:FINAL <> () returnType:kotlin.Int
2 WHEN type=kotlin.Int origin=WHEN
OUTGOING -> BB 1
CONST Boolean type=kotlin.Boolean value=true
BB 1
INCOMING <- BB 0
CONST Boolean type=kotlin.Boolean value=true
CONTENT
1 CONST Int type=kotlin.Int value=42
OUTGOING -> BB 2
When exit: WHEN type=kotlin.Int origin=WHEN
BB 2
INCOMING <- BB 1
When exit: WHEN type=kotlin.Int origin=WHEN
CONTENT
1 RETURN type=kotlin.Nothing from='public final fun empty (): kotlin.Int declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:empty visibility:public modality:FINAL <> () returnType:kotlin.Int
// END FUN: empty
// END FILE: /emptyWhen.kt
-1
View File
@@ -1 +0,0 @@
fun max(x: Int, y: Int) = if (x > y) x else y
-42
View File
@@ -1,42 +0,0 @@
// FILE: /expressionIf.kt
// FUN: max
BB 0
CONTENT
1 FUN name:max visibility:public modality:FINAL <> (x:kotlin.Int, y:kotlin.Int) returnType:kotlin.Int
2 WHEN type=kotlin.Int origin=IF
3 GET_VAR 'x: kotlin.Int declared in <root>.max' type=kotlin.Int origin=null
4 GET_VAR 'y: kotlin.Int declared in <root>.max' type=kotlin.Int origin=null
OUTGOING -> BB 1, 2
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
BB 1
INCOMING <- BB 0
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
CONTENT
OUTGOING -> BB 3
CONST Boolean type=kotlin.Boolean value=true
BB 2
INCOMING <- BB 0
CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
CONTENT
1 GET_VAR 'x: kotlin.Int declared in <root>.max' type=kotlin.Int origin=null
OUTGOING -> BB 4
When exit: WHEN type=kotlin.Int origin=IF
BB 3
INCOMING <- BB 1
CONST Boolean type=kotlin.Boolean value=true
CONTENT
1 GET_VAR 'y: kotlin.Int declared in <root>.max' type=kotlin.Int origin=null
OUTGOING -> BB 4
When exit: WHEN type=kotlin.Int origin=IF
BB 4
INCOMING <- BB 2, 3
When exit: WHEN type=kotlin.Int origin=IF
CONTENT
1 RETURN type=kotlin.Nothing from='public final fun max (x: kotlin.Int, y: kotlin.Int): kotlin.Int declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:max visibility:public modality:FINAL <> (x:kotlin.Int, y:kotlin.Int) returnType:kotlin.Int
// END FUN: max
// END FILE: /expressionIf.kt
-14
View File
@@ -1,14 +0,0 @@
fun minBiRoot(a: Double, b: Double, c: Double): Double {
if (a == 0.0) {
if (b == 0.0) return 1.0
val bc = -c / b
if (bc < 0.0) return 2.0
return -bc
}
val d = b * b - 4 * a * c
if (d < 0.0) return 3.0
val y1 = (-b + d) / (2 * a)
val y2 = (-b - d) / (2 * a)
val y3 = if (y1 > y2) y1 else y2
return if (y3 < 0.0) 4.0 else -y3
}
-175
View File
@@ -1,175 +0,0 @@
// FILE: /ifChain.kt
// FUN: minBiRoot
BB 0
CONTENT
1 FUN name:minBiRoot visibility:public modality:FINAL <> (a:kotlin.Double, b:kotlin.Double, c:kotlin.Double) returnType:kotlin.Double
2 WHEN type=kotlin.Unit origin=IF
3 GET_VAR 'a: kotlin.Double declared in <root>.minBiRoot' type=kotlin.Double origin=null
4 CONST Double type=kotlin.Double value=0.0
OUTGOING -> BB 1, 6
CALL 'public final fun ieee754equals (arg0: kotlin.Double?, arg1: kotlin.Double?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
BB 1
INCOMING <- BB 0
CALL 'public final fun ieee754equals (arg0: kotlin.Double?, arg1: kotlin.Double?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
CONTENT
1 WHEN type=kotlin.Unit origin=IF
2 GET_VAR 'b: kotlin.Double declared in <root>.minBiRoot' type=kotlin.Double origin=null
3 CONST Double type=kotlin.Double value=0.0
OUTGOING -> BB 2, 3
CALL 'public final fun ieee754equals (arg0: kotlin.Double?, arg1: kotlin.Double?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
BB 2
INCOMING <- BB 1
CALL 'public final fun ieee754equals (arg0: kotlin.Double?, arg1: kotlin.Double?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
CONTENT
1 CONST Double type=kotlin.Double value=1.0
2 RETURN type=kotlin.Nothing from='public final fun minBiRoot (a: kotlin.Double, b: kotlin.Double, c: kotlin.Double): kotlin.Double declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:minBiRoot visibility:public modality:FINAL <> (a:kotlin.Double, b:kotlin.Double, c:kotlin.Double) returnType:kotlin.Double
BB 3
INCOMING <- BB 1
CALL 'public final fun ieee754equals (arg0: kotlin.Double?, arg1: kotlin.Double?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
CONTENT
1 GET_VAR 'c: kotlin.Double declared in <root>.minBiRoot' type=kotlin.Double origin=null
2 CALL 'public final fun unaryMinus (): kotlin.Double [operator] declared in kotlin.Double' type=kotlin.Double origin=UMINUS
3 GET_VAR 'b: kotlin.Double declared in <root>.minBiRoot' type=kotlin.Double origin=null
4 CALL 'public final fun div (other: kotlin.Double): kotlin.Double [operator] declared in kotlin.Double' type=kotlin.Double origin=DIV
5 VAR name:bc type:kotlin.Double [val]
6 WHEN type=kotlin.Unit origin=IF
7 GET_VAR 'val bc: kotlin.Double [val] declared in <root>.minBiRoot' type=kotlin.Double origin=null
8 CONST Double type=kotlin.Double value=0.0
OUTGOING -> BB 4, 5
CALL 'public final fun less (arg0: kotlin.Double, arg1: kotlin.Double): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
BB 4
INCOMING <- BB 3
CALL 'public final fun less (arg0: kotlin.Double, arg1: kotlin.Double): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
CONTENT
1 CONST Double type=kotlin.Double value=2.0
2 RETURN type=kotlin.Nothing from='public final fun minBiRoot (a: kotlin.Double, b: kotlin.Double, c: kotlin.Double): kotlin.Double declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:minBiRoot visibility:public modality:FINAL <> (a:kotlin.Double, b:kotlin.Double, c:kotlin.Double) returnType:kotlin.Double
BB 5
INCOMING <- BB 3
CALL 'public final fun less (arg0: kotlin.Double, arg1: kotlin.Double): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
CONTENT
1 GET_VAR 'val bc: kotlin.Double [val] declared in <root>.minBiRoot' type=kotlin.Double origin=null
2 CALL 'public final fun unaryMinus (): kotlin.Double [operator] declared in kotlin.Double' type=kotlin.Double origin=UMINUS
3 RETURN type=kotlin.Nothing from='public final fun minBiRoot (a: kotlin.Double, b: kotlin.Double, c: kotlin.Double): kotlin.Double declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:minBiRoot visibility:public modality:FINAL <> (a:kotlin.Double, b:kotlin.Double, c:kotlin.Double) returnType:kotlin.Double
BB 6
INCOMING <- BB 0
CALL 'public final fun ieee754equals (arg0: kotlin.Double?, arg1: kotlin.Double?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
CONTENT
1 GET_VAR 'b: kotlin.Double declared in <root>.minBiRoot' type=kotlin.Double origin=null
2 GET_VAR 'b: kotlin.Double declared in <root>.minBiRoot' type=kotlin.Double origin=null
3 CALL 'public final fun times (other: kotlin.Double): kotlin.Double [operator] declared in kotlin.Double' type=kotlin.Double origin=MUL
4 CONST Int type=kotlin.Int value=4
5 GET_VAR 'a: kotlin.Double declared in <root>.minBiRoot' type=kotlin.Double origin=null
6 CALL 'public final fun times (other: kotlin.Double): kotlin.Double [operator] declared in kotlin.Int' type=kotlin.Double origin=MUL
7 GET_VAR 'c: kotlin.Double declared in <root>.minBiRoot' type=kotlin.Double origin=null
8 CALL 'public final fun times (other: kotlin.Double): kotlin.Double [operator] declared in kotlin.Double' type=kotlin.Double origin=MUL
9 CALL 'public final fun minus (other: kotlin.Double): kotlin.Double [operator] declared in kotlin.Double' type=kotlin.Double origin=MINUS
10 VAR name:d type:kotlin.Double [val]
11 WHEN type=kotlin.Unit origin=IF
12 GET_VAR 'val d: kotlin.Double [val] declared in <root>.minBiRoot' type=kotlin.Double origin=null
13 CONST Double type=kotlin.Double value=0.0
OUTGOING -> BB 7, 8
CALL 'public final fun less (arg0: kotlin.Double, arg1: kotlin.Double): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
BB 7
INCOMING <- BB 6
CALL 'public final fun less (arg0: kotlin.Double, arg1: kotlin.Double): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
CONTENT
1 CONST Double type=kotlin.Double value=3.0
2 RETURN type=kotlin.Nothing from='public final fun minBiRoot (a: kotlin.Double, b: kotlin.Double, c: kotlin.Double): kotlin.Double declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:minBiRoot visibility:public modality:FINAL <> (a:kotlin.Double, b:kotlin.Double, c:kotlin.Double) returnType:kotlin.Double
BB 8
INCOMING <- BB 6
CALL 'public final fun less (arg0: kotlin.Double, arg1: kotlin.Double): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
CONTENT
1 GET_VAR 'b: kotlin.Double declared in <root>.minBiRoot' type=kotlin.Double origin=null
2 CALL 'public final fun unaryMinus (): kotlin.Double [operator] declared in kotlin.Double' type=kotlin.Double origin=UMINUS
3 GET_VAR 'val d: kotlin.Double [val] declared in <root>.minBiRoot' type=kotlin.Double origin=null
4 CALL 'public final fun plus (other: kotlin.Double): kotlin.Double [operator] declared in kotlin.Double' type=kotlin.Double origin=PLUS
5 CONST Int type=kotlin.Int value=2
6 GET_VAR 'a: kotlin.Double declared in <root>.minBiRoot' type=kotlin.Double origin=null
7 CALL 'public final fun times (other: kotlin.Double): kotlin.Double [operator] declared in kotlin.Int' type=kotlin.Double origin=MUL
8 CALL 'public final fun div (other: kotlin.Double): kotlin.Double [operator] declared in kotlin.Double' type=kotlin.Double origin=DIV
9 VAR name:y1 type:kotlin.Double [val]
10 GET_VAR 'b: kotlin.Double declared in <root>.minBiRoot' type=kotlin.Double origin=null
11 CALL 'public final fun unaryMinus (): kotlin.Double [operator] declared in kotlin.Double' type=kotlin.Double origin=UMINUS
12 GET_VAR 'val d: kotlin.Double [val] declared in <root>.minBiRoot' type=kotlin.Double origin=null
13 CALL 'public final fun minus (other: kotlin.Double): kotlin.Double [operator] declared in kotlin.Double' type=kotlin.Double origin=MINUS
14 CONST Int type=kotlin.Int value=2
15 GET_VAR 'a: kotlin.Double declared in <root>.minBiRoot' type=kotlin.Double origin=null
16 CALL 'public final fun times (other: kotlin.Double): kotlin.Double [operator] declared in kotlin.Int' type=kotlin.Double origin=MUL
17 CALL 'public final fun div (other: kotlin.Double): kotlin.Double [operator] declared in kotlin.Double' type=kotlin.Double origin=DIV
18 VAR name:y2 type:kotlin.Double [val]
19 WHEN type=kotlin.Double origin=IF
20 GET_VAR 'val y1: kotlin.Double [val] declared in <root>.minBiRoot' type=kotlin.Double origin=null
21 GET_VAR 'val y2: kotlin.Double [val] declared in <root>.minBiRoot' type=kotlin.Double origin=null
OUTGOING -> BB 9, 10
CALL 'public final fun greater (arg0: kotlin.Double, arg1: kotlin.Double): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
BB 9
INCOMING <- BB 8
CALL 'public final fun greater (arg0: kotlin.Double, arg1: kotlin.Double): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
CONTENT
OUTGOING -> BB 11
CONST Boolean type=kotlin.Boolean value=true
BB 10
INCOMING <- BB 8
CALL 'public final fun greater (arg0: kotlin.Double, arg1: kotlin.Double): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT
CONTENT
1 GET_VAR 'val y1: kotlin.Double [val] declared in <root>.minBiRoot' type=kotlin.Double origin=null
OUTGOING -> BB 12
When exit: WHEN type=kotlin.Double origin=IF
BB 11
INCOMING <- BB 9
CONST Boolean type=kotlin.Boolean value=true
CONTENT
1 GET_VAR 'val y2: kotlin.Double [val] declared in <root>.minBiRoot' type=kotlin.Double origin=null
OUTGOING -> BB 12
When exit: WHEN type=kotlin.Double origin=IF
BB 12
INCOMING <- BB 10, 11
When exit: WHEN type=kotlin.Double origin=IF
CONTENT
1 VAR name:y3 type:kotlin.Double [val]
2 WHEN type=kotlin.Double origin=IF
3 GET_VAR 'val y3: kotlin.Double [val] declared in <root>.minBiRoot' type=kotlin.Double origin=null
4 CONST Double type=kotlin.Double value=0.0
OUTGOING -> BB 13, 14
CALL 'public final fun less (arg0: kotlin.Double, arg1: kotlin.Double): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
BB 13
INCOMING <- BB 12
CALL 'public final fun less (arg0: kotlin.Double, arg1: kotlin.Double): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
CONTENT
OUTGOING -> BB 15
CONST Boolean type=kotlin.Boolean value=true
BB 14
INCOMING <- BB 12
CALL 'public final fun less (arg0: kotlin.Double, arg1: kotlin.Double): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT
CONTENT
1 CONST Double type=kotlin.Double value=4.0
OUTGOING -> BB 16
When exit: WHEN type=kotlin.Double origin=IF
BB 15
INCOMING <- BB 13
CONST Boolean type=kotlin.Boolean value=true
CONTENT
1 GET_VAR 'val y3: kotlin.Double [val] declared in <root>.minBiRoot' type=kotlin.Double origin=null
2 CALL 'public final fun unaryMinus (): kotlin.Double [operator] declared in kotlin.Double' type=kotlin.Double origin=UMINUS
OUTGOING -> BB 16
When exit: WHEN type=kotlin.Double origin=IF
BB 16
INCOMING <- BB 14, 15
When exit: WHEN type=kotlin.Double origin=IF
CONTENT
1 RETURN type=kotlin.Nothing from='public final fun minBiRoot (a: kotlin.Double, b: kotlin.Double, c: kotlin.Double): kotlin.Double declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:minBiRoot visibility:public modality:FINAL <> (a:kotlin.Double, b:kotlin.Double, c:kotlin.Double) returnType:kotlin.Double
// END FUN: minBiRoot
// END FILE: /ifChain.kt
-10
View File
@@ -1,10 +0,0 @@
fun toString(grade: String): String {
when (grade) {
"A" -> return "Excellent"
"B" -> return "Good"
"C" -> return "Mediocre"
"D" -> return "Fair"
else -> return "Failure"
}
return "???"
}
-95
View File
@@ -1,95 +0,0 @@
// FILE: /whenReturn.kt
// FUN: toString
BB 0
CONTENT
1 FUN name:toString visibility:public modality:FINAL <> (grade:kotlin.String) returnType:kotlin.String
2 GET_VAR 'grade: kotlin.String declared in <root>.toString' type=kotlin.String origin=null
3 VAR IR_TEMPORARY_VARIABLE name:tmp0_subject type:kotlin.String [val]
4 WHEN type=kotlin.Unit origin=WHEN
5 GET_VAR 'val tmp0_subject: kotlin.String [val] declared in <root>.toString' type=kotlin.String origin=null
6 CONST String type=kotlin.String value="A"
OUTGOING -> BB 1, 5
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
BB 1
INCOMING <- BB 0
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
CONTENT
1 GET_VAR 'val tmp0_subject: kotlin.String [val] declared in <root>.toString' type=kotlin.String origin=null
2 CONST String type=kotlin.String value="B"
OUTGOING -> BB 2, 6
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
BB 2
INCOMING <- BB 1
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
CONTENT
1 GET_VAR 'val tmp0_subject: kotlin.String [val] declared in <root>.toString' type=kotlin.String origin=null
2 CONST String type=kotlin.String value="C"
OUTGOING -> BB 3, 7
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
BB 3
INCOMING <- BB 2
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
CONTENT
1 GET_VAR 'val tmp0_subject: kotlin.String [val] declared in <root>.toString' type=kotlin.String origin=null
2 CONST String type=kotlin.String value="D"
OUTGOING -> BB 4, 8
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
BB 4
INCOMING <- BB 3
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
CONTENT
OUTGOING -> BB 9, 10
CONST Boolean type=kotlin.Boolean value=true
BB 5
INCOMING <- BB 0
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
CONTENT
1 CONST String type=kotlin.String value="Excellent"
2 RETURN type=kotlin.Nothing from='public final fun toString (grade: kotlin.String): kotlin.String declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:toString visibility:public modality:FINAL <> (grade:kotlin.String) returnType:kotlin.String
BB 6
INCOMING <- BB 1
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
CONTENT
1 CONST String type=kotlin.String value="Good"
2 RETURN type=kotlin.Nothing from='public final fun toString (grade: kotlin.String): kotlin.String declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:toString visibility:public modality:FINAL <> (grade:kotlin.String) returnType:kotlin.String
BB 7
INCOMING <- BB 2
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
CONTENT
1 CONST String type=kotlin.String value="Mediocre"
2 RETURN type=kotlin.Nothing from='public final fun toString (grade: kotlin.String): kotlin.String declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:toString visibility:public modality:FINAL <> (grade:kotlin.String) returnType:kotlin.String
BB 8
INCOMING <- BB 3
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
CONTENT
1 CONST String type=kotlin.String value="Fair"
2 RETURN type=kotlin.Nothing from='public final fun toString (grade: kotlin.String): kotlin.String declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:toString visibility:public modality:FINAL <> (grade:kotlin.String) returnType:kotlin.String
BB 9
INCOMING <- BB 4
CONST Boolean type=kotlin.Boolean value=true
CONTENT
1 CONST String type=kotlin.String value="Failure"
2 RETURN type=kotlin.Nothing from='public final fun toString (grade: kotlin.String): kotlin.String declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:toString visibility:public modality:FINAL <> (grade:kotlin.String) returnType:kotlin.String
BB 10
INCOMING <- BB 4
CONST Boolean type=kotlin.Boolean value=true
CONTENT
1 CONST String type=kotlin.String value="???"
2 RETURN type=kotlin.Nothing from='public final fun toString (grade: kotlin.String): kotlin.String declared in <root>'
OUTGOING -> NONE
Function exit: FUN name:toString visibility:public modality:FINAL <> (grade:kotlin.String) returnType:kotlin.String
// END FUN: toString
// END FILE: /whenReturn.kt
-1
View File
@@ -32,7 +32,6 @@ dependencies {
testApi(project(":compiler:fir:checkers:checkers.wasm"))
testApi(project(":compiler:fir:java"))
testApi(project(":compiler:fir:entrypoint"))
testApi(project(":compiler:ir.ir2cfg"))
testApi(project(":compiler:frontend"))
testApi(project(":compiler:frontend.java"))
testApi(project(":compiler:util"))
@@ -1,61 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.path
import org.jetbrains.kotlin.ir2cfg.generators.FunctionGenerator
import org.jetbrains.kotlin.ir2cfg.util.dump
import org.jetbrains.kotlin.test.KotlinTestUtils
import java.io.File
abstract class AbstractIrCfgTestCase : AbstractIrGeneratorTestCase() {
private fun IrFile.cfgDump(): String {
val builder = StringBuilder()
for (declaration in this.declarations) {
if (declaration is IrFunction) {
builder.appendLine("// FUN: ${declaration.name}")
val cfg = FunctionGenerator(declaration).generate()
builder.appendLine(cfg.dump())
builder.appendLine("// END FUN: ${declaration.name}")
}
}
return builder.toString()
}
private fun IrModuleFragment.cfgDump(): String {
val builder = StringBuilder()
for (file in this.files) {
builder.appendLine("// FILE: ${file.path}")
builder.appendLine(file.cfgDump())
builder.appendLine("// END FILE: ${file.path}")
builder.appendLine()
}
return builder.toString()
}
override fun doTest(wholeFile: File, testFiles: List<TestFile>) {
val irModule = generateIrModule(false)
val irModuleDump = irModule.cfgDump()
val expectedPath = wholeFile.canonicalPath.replace(".kt", ".txt")
val expectedFile = File(expectedPath)
KotlinTestUtils.assertEqualsToFile(expectedFile, irModuleDump)
}
}
@@ -13,7 +13,6 @@ dependencies {
testApi(project(":compiler:util"))
testApi(project(":compiler:tests-mutes"))
testApi(project(":compiler:backend"))
testApi(project(":compiler:ir.ir2cfg"))
testApi(project(":compiler:frontend"))
testApi(project(":compiler:frontend.java"))
testApi(project(":compiler:util"))
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.generators.impl.generateTestGroupSuite
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
import org.jetbrains.kotlin.integration.AbstractAntTaskTest
import org.jetbrains.kotlin.ir.AbstractIrCfgTestCase
import org.jetbrains.kotlin.jvm.compiler.*
import org.jetbrains.kotlin.jvm.compiler.ir.*
import org.jetbrains.kotlin.jvm.compiler.javac.AbstractLoadJavaUsingJavacTest
@@ -110,10 +109,6 @@ fun generateJUnit3CompilerTests(args: Array<String>, mainClassName: String?) {
model("codegen/customScript", pattern = "^(.*)$", targetBackend = TargetBackend.JVM_IR)
}
testClass<AbstractIrCfgTestCase> {
model("ir/irCfg")
}
testClass<AbstractTopLevelMembersInvocationTest> {
model("codegen/topLevelMemberInvocation", extension = null, recursive = false)
}
@@ -1,127 +0,0 @@
/*
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.ir;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.test.generators.GenerateCompilerTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/ir/irCfg")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class IrCfgTestCaseGenerated extends AbstractIrCfgTestCase {
private void runTest(String testDataFilePath) {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInIrCfg() {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/irCfg"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("expressionFun.kt")
public void testExpressionFun() {
runTest("compiler/testData/ir/irCfg/expressionFun.kt");
}
@TestMetadata("expressionUnit.kt")
public void testExpressionUnit() {
runTest("compiler/testData/ir/irCfg/expressionUnit.kt");
}
@TestMetadata("returnUnit.kt")
public void testReturnUnit() {
runTest("compiler/testData/ir/irCfg/returnUnit.kt");
}
@TestMetadata("sequentialFun.kt")
public void testSequentialFun() {
runTest("compiler/testData/ir/irCfg/sequentialFun.kt");
}
@TestMetadata("simpleFun.kt")
public void testSimpleFun() {
runTest("compiler/testData/ir/irCfg/simpleFun.kt");
}
@TestMetadata("simpleReturn.kt")
public void testSimpleReturn() {
runTest("compiler/testData/ir/irCfg/simpleReturn.kt");
}
@TestMetadata("compiler/testData/ir/irCfg/loop")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Loop extends AbstractIrCfgTestCase {
private void runTest(String testDataFilePath) {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInLoop() {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/irCfg/loop"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("digitCount.kt")
public void testDigitCount() {
runTest("compiler/testData/ir/irCfg/loop/digitCount.kt");
}
@TestMetadata("factorial.kt")
public void testFactorial() {
runTest("compiler/testData/ir/irCfg/loop/factorial.kt");
}
@TestMetadata("isPerfect.kt")
public void testIsPerfect() {
runTest("compiler/testData/ir/irCfg/loop/isPerfect.kt");
}
}
@TestMetadata("compiler/testData/ir/irCfg/when")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class When extends AbstractIrCfgTestCase {
private void runTest(String testDataFilePath) {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInWhen() {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/irCfg/when"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("cascadeIf.kt")
public void testCascadeIf() {
runTest("compiler/testData/ir/irCfg/when/cascadeIf.kt");
}
@TestMetadata("emptyWhen.kt")
public void testEmptyWhen() {
runTest("compiler/testData/ir/irCfg/when/emptyWhen.kt");
}
@TestMetadata("expressionIf.kt")
public void testExpressionIf() {
runTest("compiler/testData/ir/irCfg/when/expressionIf.kt");
}
@TestMetadata("ifChain.kt")
public void testIfChain() {
runTest("compiler/testData/ir/irCfg/when/ifChain.kt");
}
@TestMetadata("whenReturn.kt")
public void testWhenReturn() {
runTest("compiler/testData/ir/irCfg/when/whenReturn.kt");
}
}
}
-2
View File
@@ -70,7 +70,6 @@ include ":benchmarks",
":compiler:ir.tree",
":compiler:ir.tree:tree-generator",
":compiler:ir.psi2ir",
":compiler:ir.ir2cfg",
":compiler:ir.objcinterop",
":compiler:ir.backend.common",
":compiler:ir.actualization",
@@ -699,7 +698,6 @@ project(':kotlin-ant').projectDir = "$rootDir/ant" as File
project(':compiler:ir.tree').projectDir = "$rootDir/compiler/ir/ir.tree" as File
project(':compiler:ir.tree:tree-generator').projectDir = "$rootDir/compiler/ir/ir.tree/tree-generator" as File
project(':compiler:ir.psi2ir').projectDir = "$rootDir/compiler/ir/ir.psi2ir" as File
project(':compiler:ir.ir2cfg').projectDir = "$rootDir/compiler/ir/ir.ir2cfg" as File
project(':compiler:ir.objcinterop').projectDir = "$rootDir/compiler/ir/ir.objcinterop" as File
project(':compiler:ir.backend.common').projectDir = "$rootDir/compiler/ir/backend.common" as File
project(':compiler:ir.actualization').projectDir = "$rootDir/compiler/ir/ir.actualization" as File