JvmBackendFacade (initial import)
This commit is contained in:
committed by
Dmitry Petrov
parent
c4391ebce5
commit
c2a7890ac4
@@ -10,5 +10,6 @@
|
|||||||
<orderEntry type="module" module-name="util" />
|
<orderEntry type="module" module-name="util" />
|
||||||
<orderEntry type="module" module-name="ir.tree" />
|
<orderEntry type="module" module-name="ir.tree" />
|
||||||
<orderEntry type="module" module-name="frontend" />
|
<orderEntry type="module" module-name="frontend" />
|
||||||
|
<orderEntry type="module" module-name="backend" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* 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.codegen.CompilationErrorHandler
|
||||||
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
|
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus
|
||||||
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
|
||||||
|
object JvmBackendFacade {
|
||||||
|
fun compileCorrectFiles(state: GenerationState, errorHandler: CompilationErrorHandler) {
|
||||||
|
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
||||||
|
state.beforeCompile()
|
||||||
|
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
||||||
|
doGenerateFiles(state.files, state, errorHandler)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun doGenerateFiles(files: Collection<KtFile>, state: GenerationState, errorHandler: CompilationErrorHandler) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.psi2ir
|
package org.jetbrains.kotlin.psi2ir
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
|
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
|
||||||
@@ -28,11 +30,18 @@ class Psi2IrTranslator(val configuration: Psi2IrConfiguration) {
|
|||||||
fun generateModule(moduleDescriptor: ModuleDescriptor, ktFiles: List<KtFile>, bindingContext: BindingContext): IrModuleFragment {
|
fun generateModule(moduleDescriptor: ModuleDescriptor, ktFiles: List<KtFile>, bindingContext: BindingContext): IrModuleFragment {
|
||||||
val context = GeneratorContext(configuration, moduleDescriptor, bindingContext)
|
val context = GeneratorContext(configuration, moduleDescriptor, bindingContext)
|
||||||
val irModule = ModuleGenerator(context).generateModuleFragment(ktFiles)
|
val irModule = ModuleGenerator(context).generateModuleFragment(ktFiles)
|
||||||
postprocess(irModule)
|
postprocess(irModule.descriptor.builtIns, irModule)
|
||||||
return irModule
|
return irModule
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun postprocess(irModuleFragment: IrModuleFragment) {
|
fun generateSingleFileFragment(moduleDescriptor: ModuleDescriptor, ktFile: KtFile, bindingContext: BindingContext): IrModuleFragment {
|
||||||
insertImplicitCasts(irModuleFragment.descriptor.builtIns, irModuleFragment)
|
val context = GeneratorContext(configuration, moduleDescriptor, bindingContext)
|
||||||
|
val irFileFragment = ModuleGenerator(context).generateSingleFileFragment(ktFile)
|
||||||
|
postprocess(moduleDescriptor.builtIns, irFileFragment)
|
||||||
|
return irFileFragment
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun postprocess(builtIns: KotlinBuiltIns, irElement: IrElement) {
|
||||||
|
insertImplicitCasts(builtIns, irElement)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-12
@@ -24,26 +24,35 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
|||||||
|
|
||||||
class ModuleGenerator(override val context: GeneratorContext) : Generator {
|
class ModuleGenerator(override val context: GeneratorContext) : Generator {
|
||||||
fun generateModuleFragment(ktFiles: Collection<KtFile>): IrModuleFragment =
|
fun generateModuleFragment(ktFiles: Collection<KtFile>): IrModuleFragment =
|
||||||
IrModuleFragmentImpl(context.moduleDescriptor, context.irBuiltIns, generateFiles(ktFiles))
|
IrModuleFragmentImpl(context.moduleDescriptor, context.irBuiltIns,
|
||||||
|
generateFiles(ktFiles))
|
||||||
|
|
||||||
fun generateFiles(ktFiles: Collection<KtFile>): List<IrFile> {
|
fun generateFiles(ktFiles: Collection<KtFile>): List<IrFile> {
|
||||||
val irDeclarationGenerator = DeclarationGenerator(context)
|
val irDeclarationGenerator = DeclarationGenerator(context)
|
||||||
|
|
||||||
return ktFiles.map { ktFile ->
|
return ktFiles.map { ktFile ->
|
||||||
val irFile = createEmptyIrFile(ktFile)
|
generateSingleFile(irDeclarationGenerator, ktFile)
|
||||||
|
|
||||||
for (ktAnnotationEntry in ktFile.annotationEntries) {
|
|
||||||
irFile.addAnnotation(getOrFail(BindingContext.ANNOTATION, ktAnnotationEntry))
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ktDeclaration in ktFile.declarations) {
|
|
||||||
irFile.addDeclaration(irDeclarationGenerator.generateMemberDeclaration(ktDeclaration))
|
|
||||||
}
|
|
||||||
|
|
||||||
irFile
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun generateSingleFileFragment(ktFile: KtFile) =
|
||||||
|
IrModuleFragmentImpl(context.moduleDescriptor, context.irBuiltIns,
|
||||||
|
listOf(generateSingleFile(DeclarationGenerator(context), ktFile)))
|
||||||
|
|
||||||
|
private fun generateSingleFile(irDeclarationGenerator: DeclarationGenerator, ktFile: KtFile): IrFileImpl {
|
||||||
|
val irFile = createEmptyIrFile(ktFile)
|
||||||
|
|
||||||
|
for (ktAnnotationEntry in ktFile.annotationEntries) {
|
||||||
|
irFile.addAnnotation(getOrFail(BindingContext.ANNOTATION, ktAnnotationEntry))
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ktDeclaration in ktFile.declarations) {
|
||||||
|
irFile.addDeclaration(irDeclarationGenerator.generateMemberDeclaration(ktDeclaration))
|
||||||
|
}
|
||||||
|
|
||||||
|
return irFile
|
||||||
|
}
|
||||||
|
|
||||||
fun createEmptyIrFile(ktFile: KtFile): IrFileImpl {
|
fun createEmptyIrFile(ktFile: KtFile): IrFileImpl {
|
||||||
val fileEntry = context.sourceManager.getOrCreateFileEntry(ktFile)
|
val fileEntry = context.sourceManager.getOrCreateFileEntry(ktFile)
|
||||||
val packageFragmentDescriptor = getOrFail(BindingContext.FILE_TO_PACKAGE_FRAGMENT, ktFile)
|
val packageFragmentDescriptor = getOrFail(BindingContext.FILE_TO_PACKAGE_FRAGMENT, ktFile)
|
||||||
|
|||||||
Reference in New Issue
Block a user