Refactoring + synced vtable for DFG and for bitcode

This commit is contained in:
Igor Chevdar
2018-04-18 16:11:46 +03:00
parent 3572c98a8b
commit 211d219b04
4 changed files with 23 additions and 25 deletions
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.backend.konan.*
import org.jetbrains.kotlin.backend.konan.irasdescriptors.*
import org.jetbrains.kotlin.backend.konan.llvm.functionName
import org.jetbrains.kotlin.backend.konan.llvm.localHash
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.util.simpleFunctions
@@ -49,15 +50,19 @@ internal class OverriddenFunctionDescriptor(
&& descriptor.target.overrides(overriddenDescriptor)
&& descriptor.bridgeDirectionsTo(overriddenDescriptor).allNotNeeded()
fun getImplementation(context: Context): SimpleFunctionDescriptor {
fun getImplementation(context: Context): SimpleFunctionDescriptor? {
val target = descriptor.target
if (!needBridge) return target
val bridgeOwner = if (inheritsBridge) {
target // Bridge is inherited from superclass.
} else {
descriptor
val implementation = if (!needBridge)
target
else {
val bridgeOwner = if (inheritsBridge) {
target // Bridge is inherited from superclass.
} else {
descriptor
}
context.specialDeclarationsFactory.getBridgeDescriptor(OverriddenFunctionDescriptor(bridgeOwner, overriddenDescriptor))
}
return context.specialDeclarationsFactory.getBridgeDescriptor(OverriddenFunctionDescriptor(bridgeOwner, overriddenDescriptor))
return if (implementation.modality == Modality.ABSTRACT) null else implementation
}
override fun toString(): String {
@@ -200,7 +200,7 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
// TODO: compile-time resolution limits binary compatibility
val vtableEntries = context.getVtableBuilder(classDesc).vtableEntries.map {
val implementation = it.implementation
if (implementation.isExternalObjCClassMethod() || implementation.modality == Modality.ABSTRACT) {
if (implementation == null || implementation.isExternalObjCClassMethod()) {
NullPointer(int8Type)
} else {
implementation.entryPointAddress
@@ -220,11 +220,7 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
// TODO: compile-time resolution limits binary compatibility
val implementation = it.implementation
val methodEntryPoint = if (implementation.modality == Modality.ABSTRACT) {
null
} else {
implementation.entryPointAddress
}
val methodEntryPoint = implementation?.entryPointAddress
MethodTableRecord(nameSignature, methodEntryPoint)
}.sortedBy { it.nameSignature.value }
}
@@ -1178,9 +1178,11 @@ internal object DFGSerializer {
allTypes.forEach {
println(it)
println(" SUPER TYPES:")
it.superTypes.forEach {
println(" $it")
}
it.superTypes.forEach { println(" $it") }
println(" VTABLE:")
it.vtable.forEach { println(" $it") }
println(" ITABLE:")
it.itable.forEach { t, u -> println(" $t: $u") }
}
functions.forEach {
@@ -483,16 +483,11 @@ internal object DataFlowIR {
Type.Public(name.localHash.value, isFinal, isAbstract, module, symbolTableIndex, takeName { name })
else
Type.Private(privateTypeIndex++, isFinal, isAbstract, module, symbolTableIndex, takeName { name })
if (!descriptor.isInterface) {
if (!isAbstract) {
val vtableBuilder = context.getVtableBuilder(descriptor)
type.vtable += vtableBuilder.vtableEntries.map { mapFunction(it.getImplementation(context)) }
if (!isAbstract) {
vtableBuilder.methodTableEntries.forEach {
type.itable.put(
it.overriddenDescriptor.functionName.localHash.value,
mapFunction(it.getImplementation(context))
)
}
type.vtable += vtableBuilder.vtableEntries.map { mapFunction(it.getImplementation(context)!!) }
vtableBuilder.methodTableEntries.forEach {
type.itable[it.overriddenDescriptor.functionName.localHash.value] = mapFunction(it.getImplementation(context)!!)
}
}
classMap.put(descriptor, type)