JVM IR: invoke codegen after lowering all files in the module
Inspired by discussion in #2316
This commit is contained in:
@@ -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.IrClass
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
import org.jetbrains.kotlin.ir.util.render
|
import org.jetbrains.kotlin.ir.util.render
|
||||||
import java.lang.AssertionError
|
|
||||||
|
|
||||||
class JvmBackend(val context: JvmBackendContext) {
|
class JvmBackend(val context: JvmBackendContext) {
|
||||||
private val lower = JvmLower(context)
|
private val lower = JvmLower(context)
|
||||||
private val codegen = JvmCodegen(context)
|
private val codegen = JvmCodegen(context)
|
||||||
|
|
||||||
fun generateFile(irFile: IrFile) {
|
fun lowerFile(irFile: IrFile) {
|
||||||
val extensions = IrGenerationExtension.getInstances(context.state.project)
|
for (extension in IrGenerationExtension.getInstances(context.state.project)) {
|
||||||
extensions.forEach { it.generate(irFile, context, context.state.bindingContext) }
|
extension.generate(irFile, context, context.state.bindingContext)
|
||||||
|
}
|
||||||
|
|
||||||
lower.lower(irFile)
|
lower.lower(irFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun generateLoweredFile(irFile: IrFile) {
|
||||||
for (loweredClass in irFile.declarations) {
|
for (loweredClass in irFile.declarations) {
|
||||||
if (loweredClass !is IrClass) {
|
if (loweredClass !is IrClass) {
|
||||||
throw AssertionError("File-level declaration should be IrClass after JvmLower, got: " + loweredClass.render())
|
throw AssertionError("File-level declaration should be IrClass after JvmLower, got: " + loweredClass.render())
|
||||||
|
|||||||
@@ -66,11 +66,19 @@ object JvmBackendFacade {
|
|||||||
|
|
||||||
for (irFile in irModuleFragment.files) {
|
for (irFile in irModuleFragment.files) {
|
||||||
try {
|
try {
|
||||||
jvmBackend.generateFile(irFile)
|
jvmBackend.lowerFile(irFile)
|
||||||
state.afterIndependentPart()
|
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
errorHandler.reportException(e, null) // TODO ktFile.virtualFile.url
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// IGNORE_LIGHT_ANALYSIS
|
// IGNORE_LIGHT_ANALYSIS
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
// FILE: util.kt
|
// FILE: util.kt
|
||||||
|
|
||||||
inline fun ieq(x: Int, y: Int) = x == y
|
inline fun ieq(x: Int, y: Int) = x == y
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
// FILE: util.kt
|
// FILE: util.kt
|
||||||
const val FLAG = true
|
const val FLAG = true
|
||||||
const val OTHER_FLAG = false
|
const val OTHER_FLAG = false
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
// FILE: util.kt
|
// FILE: util.kt
|
||||||
const val MAGIC = 42
|
const val MAGIC = 42
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user