JVM IR: inline JvmBackend, JvmCodegen
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.backend.jvm
|
||||
|
||||
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
|
||||
|
||||
class JvmBackend(val context: JvmBackendContext) {
|
||||
private val lower = JvmLower(context)
|
||||
private val codegen = JvmCodegen(context)
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
codegen.generateClass(loweredClass)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
||||
import org.jetbrains.kotlin.backend.common.ir.createParameterDeclarations
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.codegen.CompilationErrorHandler
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildClass
|
||||
@@ -15,6 +17,7 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator
|
||||
@@ -58,7 +61,7 @@ object JvmBackendFacade {
|
||||
phaseConfig: PhaseConfig,
|
||||
firMode: Boolean = false
|
||||
) {
|
||||
val jvmBackendContext = JvmBackendContext(
|
||||
val context = JvmBackendContext(
|
||||
state, sourceManager, irModuleFragment.irBuiltins, irModuleFragment, symbolTable, phaseConfig, firMode
|
||||
)
|
||||
//TODO
|
||||
@@ -70,11 +73,15 @@ object JvmBackendFacade {
|
||||
facadeClassGenerator = ::facadeClassGenerator
|
||||
).generateUnboundSymbolsAsDependencies()
|
||||
|
||||
val jvmBackend = JvmBackend(jvmBackendContext)
|
||||
val lower = JvmLower(context)
|
||||
|
||||
for (irFile in irModuleFragment.files) {
|
||||
try {
|
||||
jvmBackend.lowerFile(irFile)
|
||||
for (extension in IrGenerationExtension.getInstances(context.state.project)) {
|
||||
extension.generate(irFile, context, context.state.bindingContext)
|
||||
}
|
||||
|
||||
lower.lower(irFile)
|
||||
} catch (e: Throwable) {
|
||||
errorHandler.reportException(e, null) // TODO ktFile.virtualFile.url
|
||||
}
|
||||
@@ -82,7 +89,13 @@ object JvmBackendFacade {
|
||||
|
||||
for (irFile in irModuleFragment.files) {
|
||||
try {
|
||||
jvmBackend.generateLoweredFile(irFile)
|
||||
for (loweredClass in irFile.declarations) {
|
||||
if (loweredClass !is IrClass) {
|
||||
throw AssertionError("File-level declaration should be IrClass after JvmLower, got: " + loweredClass.render())
|
||||
}
|
||||
|
||||
ClassCodegen.generate(loweredClass, context)
|
||||
}
|
||||
state.afterIndependentPart()
|
||||
} catch (e: Throwable) {
|
||||
errorHandler.reportException(e, null)
|
||||
|
||||
@@ -1,26 +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.backend.jvm
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
|
||||
class JvmCodegen(val context: JvmBackendContext) {
|
||||
fun generateClass(irClass: IrClass) {
|
||||
ClassCodegen.generate(irClass, context)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user