Fix IR entry point generation for partial IR compilation
This commit is contained in:
committed by
SvyatoslavScherbina
parent
912a889b68
commit
fe591aafab
+16
-1
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.addChild
|
||||
import org.jetbrains.kotlin.ir.util.addFile
|
||||
import org.jetbrains.kotlin.ir.util.file
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration
|
||||
@@ -343,7 +344,21 @@ internal val entryPointPhase = SameTypeNamedPhaseWrapper(
|
||||
override fun invoke(phaseConfig: PhaseConfig, phaserState: PhaserState<IrModuleFragment>,
|
||||
context: Context, input: IrModuleFragment): IrModuleFragment {
|
||||
assert(context.config.produce == CompilerOutputKind.PROGRAM)
|
||||
context.ir.symbols.entryPoint!!.owner.file.addChild(makeEntryPoint(context))
|
||||
|
||||
val originalFile = context.ir.symbols.entryPoint!!.owner.file
|
||||
val originalModule = originalFile.packageFragmentDescriptor.containingDeclaration
|
||||
val file = if (context.llvmModuleSpecification.containsModule(originalModule)) {
|
||||
originalFile
|
||||
} else {
|
||||
// `main` function is compiled to other LLVM module.
|
||||
// For example, test running support uses `main` defined in stdlib.
|
||||
context.irModule!!.addFile(originalFile.fileEntry, originalFile.fqName)
|
||||
}
|
||||
|
||||
require(context.llvmModuleSpecification.containsModule(
|
||||
file.packageFragmentDescriptor.containingDeclaration))
|
||||
|
||||
file.addChild(makeEntryPoint(context))
|
||||
return input
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -19,7 +19,9 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.SourceManager
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
@@ -38,8 +40,10 @@ import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.isRestrictsSuspensionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.immediateSupertypes
|
||||
@@ -83,6 +87,15 @@ internal fun IrFile.addTopLevelInitializer(expression: IrExpression, context: Ko
|
||||
addChild(irField)
|
||||
}
|
||||
|
||||
fun IrModuleFragment.addFile(fileEntry: SourceManager.FileEntry, packageFqName: FqName): IrFile {
|
||||
val packageFragmentDescriptor = object : PackageFragmentDescriptorImpl(this.descriptor, packageFqName) {
|
||||
override fun getMemberScope(): MemberScope = MemberScope.Empty
|
||||
}
|
||||
|
||||
return IrFileImpl(fileEntry, packageFragmentDescriptor)
|
||||
.also { this.files += it }
|
||||
}
|
||||
|
||||
inline fun <reified T> stub(name: String): T {
|
||||
return Proxy.newProxyInstance(T::class.java.classLoader, arrayOf(T::class.java)) {
|
||||
_ /* proxy */, method, _ /* methodArgs */ ->
|
||||
|
||||
Reference in New Issue
Block a user