diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/RTTIGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/RTTIGenerator.kt index 2788b5172c2..91bcea62ff0 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/RTTIGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/RTTIGenerator.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.OverridingUtil +import org.jetbrains.kotlin.resolve.constants.StringValue import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassOrAny @@ -116,6 +117,16 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils { return allMethods.filter { it.modality != Modality.FINAL } } + private fun exportTypeInfoIfRequired(classDesc: ClassDescriptor, typeInfoGlobal: LLVMOpaqueValue?) { + val annot = classDesc.annotations.findAnnotation(FqName("kotlin_native.ExportTypeInfo")) + if (annot != null) { + val nameValue = annot.allValueArguments.values.single() as StringValue + // TODO: use LLVMAddAlias? + val global = LLVMAddGlobal(context.llvmModule, pointerType(runtime.typeInfoType), nameValue.value) + LLVMSetInitializer(global, typeInfoGlobal) + } + } + fun generate(classDesc: ClassDescriptor) { val className = classDesc.fqNameSafe @@ -176,6 +187,8 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils { val typeInfoGlobal = classDesc.llvmTypeInfoPtr.getLlvmValue() // TODO: it is a hack LLVMSetInitializer(typeInfoGlobal, typeInfo.getLlvmValue()) LLVMSetGlobalConstant(typeInfoGlobal, 1) + + exportTypeInfoIfRequired(classDesc, typeInfoGlobal) } } diff --git a/runtime/src/main/kotlin/kotlin_native/annotations.kt b/runtime/src/main/kotlin/kotlin_native/annotations.kt index 28bc223294a..49424e6d40f 100644 --- a/runtime/src/main/kotlin/kotlin_native/annotations.kt +++ b/runtime/src/main/kotlin/kotlin_native/annotations.kt @@ -1,5 +1,7 @@ package kotlin_native +// TODO: shouldn't these annotation be located in 'kotlin_native.internal' package? + /** * Forces the compiler to use specified symbol name for the target `external` function. * @@ -7,5 +9,12 @@ package kotlin_native * so it should probably be allowed on `internal` and `private` functions only. */ @Target(AnnotationTarget.FUNCTION) -@Retention(AnnotationRetention.BINARY) +@Retention(AnnotationRetention.SOURCE) annotation class SymbolName(val name: kotlin.String) + +/** + * Exports the TypeInfo of this class by given name to use it from runtime. + */ +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.SOURCE) +annotation class ExportTypeInfo(val name: kotlin.String)