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)
}
}
}
}