org.jetbrains.kotlin.backend.konan.Context.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-native-compiler-embeddable Show documentation
Show all versions of kotlin-native-compiler-embeddable Show documentation
Embeddable JAR of Kotlin/Native compiler
/*
* Copyright 2010-2022 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.konan
import llvm.LLVMTypeRef
import org.jetbrains.kotlin.backend.common.LoggingContext
import org.jetbrains.kotlin.backend.common.linkage.partial.createPartialLinkageSupportForLowerings
import org.jetbrains.kotlin.backend.konan.cexport.CAdapterExportedElements
import org.jetbrains.kotlin.backend.konan.ir.*
import org.jetbrains.kotlin.backend.konan.llvm.KonanMetadata
import org.jetbrains.kotlin.backend.konan.lower.*
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportCodeSpec
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportedInterface
import org.jetbrains.kotlin.backend.konan.serialization.KonanIrLinker
import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns
import org.jetbrains.kotlin.config.messageCollector
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.types.IrTypeSystemContext
import org.jetbrains.kotlin.ir.types.IrTypeSystemContextImpl
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import java.util.concurrent.ConcurrentHashMap
// TODO: Can be renamed or merged with KonanBackendContext
internal class Context(
config: KonanConfig,
val sourcesModules: Set,
override val builtIns: KonanBuiltIns,
override val irBuiltIns: IrBuiltIns,
val irModules: Map,
val irLinker: KonanIrLinker,
symbols: KonanSymbols,
) : KonanBackendContext(config) {
override val ir: KonanIr = KonanIr(this, symbols)
override val configuration get() = config.configuration
override val internalPackageFqn: FqName = RuntimeNames.kotlinNativeInternalPackageName
override val optimizeLoopsOverUnsignedArrays = true
override val innerClassesSupport: NativeInnerClassesSupport by lazy { NativeInnerClassesSupport(irFactory) }
val bridgesSupport by lazy { BridgesSupport(irBuiltIns, irFactory) }
val enumsSupport by lazy { EnumsSupport(irBuiltIns, irFactory) }
val cachesAbiSupport by lazy { CachesAbiSupport(mapping, irFactory) }
// TODO: Remove after adding special property to IrDeclaration.
private val layoutBuilders = ConcurrentHashMap()
fun getLayoutBuilder(irClass: IrClass): ClassLayoutBuilder =
(irClass.metadata as? KonanMetadata.Class)?.layoutBuilder
?: layoutBuilders.getOrPut(irClass) { ClassLayoutBuilder(irClass, this) }
lateinit var globalHierarchyAnalysisResult: GlobalHierarchyAnalysisResult
override val typeSystem: IrTypeSystemContext
get() = IrTypeSystemContextImpl(irBuiltIns)
var cAdapterExportedElements: CAdapterExportedElements? = null
var objCExportedInterface: ObjCExportedInterface? = null
var objCExportCodeSpec: ObjCExportCodeSpec? = null
fun ghaEnabled() = ::globalHierarchyAnalysisResult.isInitialized
val stdlibModule
get() = this.builtIns.any.module
val declaredLocalArrays: MutableMap = HashMap()
val targetAbiInfo = config.target.abiInfo
override fun dispose() {}
override val partialLinkageSupport = createPartialLinkageSupportForLowerings(
config.partialLinkageConfig,
irBuiltIns,
configuration.messageCollector
)
}
internal class ContextLogger(val context: LoggingContext) {
operator fun String.unaryPlus() = context.log { this }
}
internal fun LoggingContext.logMultiple(messageBuilder: ContextLogger.() -> Unit) {
if (!inVerbosePhase) return
with(ContextLogger(this)) { messageBuilder() }
}