JVM IR: invoke codegen after lowering all files in the module

Inspired by discussion in #2316
This commit is contained in:
Alexander Udalov
2019-05-28 17:56:42 +02:00
parent b060acf01d
commit e72388895b
6 changed files with 19 additions and 13 deletions
@@ -20,18 +20,20 @@ import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.util.render
import java.lang.AssertionError
class JvmBackend(val context: JvmBackendContext) {
private val lower = JvmLower(context)
private val codegen = JvmCodegen(context)
fun generateFile(irFile: IrFile) {
val extensions = IrGenerationExtension.getInstances(context.state.project)
extensions.forEach { it.generate(irFile, context, context.state.bindingContext) }
fun lowerFile(irFile: IrFile) {
for (extension in IrGenerationExtension.getInstances(context.state.project)) {
extension.generate(irFile, context, context.state.bindingContext)
}
lower.lower(irFile)
}
fun generateLoweredFile(irFile: IrFile) {
for (loweredClass in irFile.declarations) {
if (loweredClass !is IrClass) {
throw AssertionError("File-level declaration should be IrClass after JvmLower, got: " + loweredClass.render())
@@ -40,4 +42,4 @@ class JvmBackend(val context: JvmBackendContext) {
codegen.generateClass(loweredClass)
}
}
}
}
@@ -66,11 +66,19 @@ object JvmBackendFacade {
for (irFile in irModuleFragment.files) {
try {
jvmBackend.generateFile(irFile)
state.afterIndependentPart()
jvmBackend.lowerFile(irFile)
} catch (e: Throwable) {
errorHandler.reportException(e, null) // TODO ktFile.virtualFile.url
}
}
for (irFile in irModuleFragment.files) {
try {
jvmBackend.generateLoweredFile(irFile)
state.afterIndependentPart()
} catch (e: Throwable) {
errorHandler.reportException(e, null)
}
}
}
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// FILE: util.kt
inline fun ieq(x: Int, y: Int) = x == y
@@ -23,4 +22,4 @@ fun testge(x: Int) = ige(x, 0)
// 0 IF_ICMPGE
// 0 IF_ICMPGT
// 0 IF_ICMPLE
// 0 IF_ICMPLT
// 0 IF_ICMPLT
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// FILE: util.kt
const val FLAG = true
const val OTHER_FLAG = false
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// FILE: util.kt
const val MAGIC = 42
@@ -56,4 +55,4 @@ fun test() {
// 0 IFLT
// 0 IFLE
// 0 IFGE
// 0 IFGT
// 0 IFGT