backend.native, runtime: implement @ExportTypeInfo
This commit is contained in:
committed by
Nikolay Igotti
parent
6bfbf1050b
commit
991c8ea905
+13
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
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.fqNameSafe
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassOrAny
|
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 }
|
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) {
|
fun generate(classDesc: ClassDescriptor) {
|
||||||
|
|
||||||
val className = classDesc.fqNameSafe
|
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
|
val typeInfoGlobal = classDesc.llvmTypeInfoPtr.getLlvmValue() // TODO: it is a hack
|
||||||
LLVMSetInitializer(typeInfoGlobal, typeInfo.getLlvmValue())
|
LLVMSetInitializer(typeInfoGlobal, typeInfo.getLlvmValue())
|
||||||
LLVMSetGlobalConstant(typeInfoGlobal, 1)
|
LLVMSetGlobalConstant(typeInfoGlobal, 1)
|
||||||
|
|
||||||
|
exportTypeInfoIfRequired(classDesc, typeInfoGlobal)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package kotlin_native
|
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.
|
* 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.
|
* so it should probably be allowed on `internal` and `private` functions only.
|
||||||
*/
|
*/
|
||||||
@Target(AnnotationTarget.FUNCTION)
|
@Target(AnnotationTarget.FUNCTION)
|
||||||
@Retention(AnnotationRetention.BINARY)
|
@Retention(AnnotationRetention.SOURCE)
|
||||||
annotation class SymbolName(val name: kotlin.String)
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user