backend.konan: apply common lowering
This commit is contained in:
committed by
SvyatoslavScherbina
parent
a37cabbd51
commit
7d5890e354
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package org.jetbrains.kotlin.backend.konan
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.common.BackendContext
|
||||||
|
import org.jetbrains.kotlin.backend.konan.llvm.KonanPlatform
|
||||||
|
|
||||||
|
open internal class KonanBackendContext : BackendContext {
|
||||||
|
override val builtIns = KonanPlatform.builtIns
|
||||||
|
|
||||||
|
override val sharedVariablesManager by lazy {
|
||||||
|
TODO()
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
package org.jetbrains.kotlin.backend.konan
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.common.lower.LocalFunctionsLowering
|
||||||
|
import org.jetbrains.kotlin.backend.common.lower.SharedVariablesLowering
|
||||||
|
import org.jetbrains.kotlin.backend.common.runOnFilePostfix
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
|
|
||||||
|
internal class KonanLower(val context: KonanBackendContext) {
|
||||||
|
|
||||||
|
fun lower(module: IrModuleFragment) {
|
||||||
|
module.files.forEach {
|
||||||
|
lower(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun lower(irFile: IrFile) {
|
||||||
|
SharedVariablesLowering(context).runOnFilePostfix(irFile)
|
||||||
|
LocalFunctionsLowering(context).runOnFilePostfix(irFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-1
@@ -1,14 +1,17 @@
|
|||||||
package org.jetbrains.kotlin.backend.konan.llvm
|
package org.jetbrains.kotlin.backend.konan.llvm
|
||||||
|
|
||||||
import llvm.*
|
import llvm.*
|
||||||
|
import org.jetbrains.kotlin.backend.konan.KonanBackendContext
|
||||||
import org.jetbrains.kotlin.backend.konan.ModuleIndex
|
import org.jetbrains.kotlin.backend.konan.ModuleIndex
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
|
|
||||||
|
// TODO: module-independent part should probably be extracted
|
||||||
internal class Context(val irModule: IrModuleFragment,
|
internal class Context(val irModule: IrModuleFragment,
|
||||||
val runtime: Runtime,
|
val runtime: Runtime,
|
||||||
val llvmModule: LLVMModuleRef,
|
val llvmModule: LLVMModuleRef,
|
||||||
val bindingContext: BindingContext) {
|
val bindingContext: BindingContext) : KonanBackendContext() {
|
||||||
|
|
||||||
val moduleIndex = ModuleIndex(irModule)
|
val moduleIndex = ModuleIndex(irModule)
|
||||||
|
|
||||||
private fun importFunction(name: String, otherModule: LLVMModuleRef): LLVMValueRef {
|
private fun importFunction(name: String, otherModule: LLVMModuleRef): LLVMValueRef {
|
||||||
|
|||||||
+2
@@ -36,6 +36,8 @@ fun emitLLVM(module: IrModuleFragment, runtimeFile: String, outFile: String) {
|
|||||||
val context = Context(
|
val context = Context(
|
||||||
module, runtime, llvmModule, BindingContext.EMPTY) // TODO: dispose
|
module, runtime, llvmModule, BindingContext.EMPTY) // TODO: dispose
|
||||||
|
|
||||||
|
KonanLower(context).lower(module)
|
||||||
|
|
||||||
module.acceptVoid(RTTIGeneratorVisitor(context))
|
module.acceptVoid(RTTIGeneratorVisitor(context))
|
||||||
println("\n--- Generate bitcode ------------------------------------------------------\n")
|
println("\n--- Generate bitcode ------------------------------------------------------\n")
|
||||||
module.acceptVoid(CodeGeneratorVisitor(context))
|
module.acceptVoid(CodeGeneratorVisitor(context))
|
||||||
|
|||||||
Reference in New Issue
Block a user