From db810e55d3fae28c1cfcbeb16882ac7f9b52f755 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 26 Aug 2016 17:31:27 +0300 Subject: [PATCH] Basic CFG interfaces --- .../kotlin/ir2cfg/graph/BasicBlock.kt | 34 +++++++++++++++++++ .../kotlin/ir2cfg/graph/BlockConnector.kt | 34 +++++++++++++++++++ .../jetbrains/kotlin/ir2cfg/graph/CfgNode.kt | 24 +++++++++++++ .../kotlin/ir2cfg/graph/ControlFlowGraph.kt | 32 +++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/BasicBlock.kt create mode 100644 compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/BlockConnector.kt create mode 100644 compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/CfgNode.kt create mode 100644 compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/ControlFlowGraph.kt diff --git a/compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/BasicBlock.kt b/compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/BasicBlock.kt new file mode 100644 index 00000000000..5c3ceed413b --- /dev/null +++ b/compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/BasicBlock.kt @@ -0,0 +1,34 @@ +/* + * 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.IrElement + +interface BasicBlock : CfgNode { + + val elements: List + + val incoming: BlockConnector? + + val outgoing: BlockConnector? + + override val predecessors: List + get() = listOfNotNull(incoming) + + override val successors: List + get() = listOfNotNull(outgoing) +} \ No newline at end of file diff --git a/compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/BlockConnector.kt b/compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/BlockConnector.kt new file mode 100644 index 00000000000..2a45c59fb6f --- /dev/null +++ b/compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/BlockConnector.kt @@ -0,0 +1,34 @@ +/* + * 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.IrElement + +interface BlockConnector : CfgNode { + + val previousBlocks: List + + val element: IrElement + + val nextBlocks: List + + override val predecessors: List + get() = previousBlocks + + override val successors: List + get() = nextBlocks +} \ No newline at end of file diff --git a/compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/CfgNode.kt b/compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/CfgNode.kt new file mode 100644 index 00000000000..315d5f8c088 --- /dev/null +++ b/compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/CfgNode.kt @@ -0,0 +1,24 @@ +/* + * 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 + + val successors: List +} \ No newline at end of file diff --git a/compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/ControlFlowGraph.kt b/compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/ControlFlowGraph.kt new file mode 100644 index 00000000000..e7dc6a31178 --- /dev/null +++ b/compiler/ir/ir.ir2cfg/src/org/jetbrains/kotlin/ir2cfg/graph/ControlFlowGraph.kt @@ -0,0 +1,32 @@ +/* + * 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 + + val connectors: List + + val nodes: List + get() = blocks + connectors +} \ No newline at end of file