+7
-3
@@ -39,6 +39,10 @@ internal open class Struct(val type: LLVMOpaqueType?, val elements: List<Compile
|
||||
}
|
||||
}
|
||||
|
||||
internal class Int8(val value: Byte) : CompileTimeValue() {
|
||||
override fun getLlvmValue() = LLVMConstInt(LLVMInt8Type(), value.toLong(), 1)
|
||||
}
|
||||
|
||||
internal class Int32(val value: Int) : CompileTimeValue() {
|
||||
override fun getLlvmValue() = LLVMConstInt(LLVMInt32Type(), value.toLong(), 1)
|
||||
}
|
||||
@@ -63,11 +67,11 @@ internal fun pointerType(pointeeType: LLVMOpaqueType?) = LLVMPointerType(pointee
|
||||
internal fun getLlvmFunctionType(function: FunctionDescriptor): LLVMOpaqueType? {
|
||||
val returnType = getLLVMType(function.returnType!!)
|
||||
val params = function.dispatchReceiverParameter.singletonOrEmptyList() +
|
||||
function.extensionReceiverParameter.singletonOrEmptyList() +
|
||||
function.valueParameters
|
||||
function.extensionReceiverParameter.singletonOrEmptyList() +
|
||||
function.valueParameters
|
||||
|
||||
val paramTypes = params.map { getLLVMType(it.type) }.toTypedArray()
|
||||
|
||||
val paramTypesPtr = mallocNativeArrayOf(LLVMOpaqueType, *paramTypes)[0] // TODO: dispose
|
||||
return LLVMFunctionType(returnType, paramTypesPtr, paramTypes.size, 0)
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -39,7 +39,7 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
|
||||
Struct(
|
||||
runtime.typeInfoType,
|
||||
|
||||
Int64(name),
|
||||
Struct(runtime.globalhHashType, ConstArray(LLVMInt8Type(), Array(20, {i -> Int8(1)}).toList())),
|
||||
Int32(size),
|
||||
|
||||
superType,
|
||||
@@ -102,7 +102,7 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
|
||||
|
||||
private fun getMethodTableEntries(classDesc: ClassDescriptor): List<FunctionDescriptor> {
|
||||
val contributedDescriptors = classDesc.unsubstitutedMemberScope.getContributedDescriptors()
|
||||
// (includes declarations from supers)
|
||||
// (includes declarations from supers)
|
||||
|
||||
val functions = contributedDescriptors.filterIsInstance<FunctionDescriptor>()
|
||||
|
||||
@@ -166,16 +166,16 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
|
||||
val methodsPtr = addGlobalConstArray("kmethods:$className", runtime.methodTableRecordType, methods)
|
||||
|
||||
val typeInfo = TypeInfo(name, size,
|
||||
superType,
|
||||
objOffsetsPtr, objOffsets.size,
|
||||
interfacesPtr, interfaces.size,
|
||||
vtablePtr,
|
||||
methodsPtr, methods.size,
|
||||
fieldsPtr, fields.size)
|
||||
superType,
|
||||
objOffsetsPtr, objOffsets.size,
|
||||
interfacesPtr, interfaces.size,
|
||||
vtablePtr,
|
||||
methodsPtr, methods.size,
|
||||
fieldsPtr, fields.size)
|
||||
|
||||
val typeInfoGlobal = classDesc.llvmTypeInfoPtr.getLlvmValue() // TODO: it is a hack
|
||||
LLVMSetInitializer(typeInfoGlobal, typeInfo.getLlvmValue())
|
||||
LLVMSetGlobalConstant(typeInfoGlobal, 1)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -33,6 +33,7 @@ class Runtime(private val bitcodeFile: String) {
|
||||
val typeInfoType = LLVMGetTypeByName(llvmModule, "struct.TypeInfo")
|
||||
val fieldTableRecordType = LLVMGetTypeByName(llvmModule, "struct.FieldTableRecord")
|
||||
val methodTableRecordType = LLVMGetTypeByName(llvmModule, "struct.MethodTableRecord")
|
||||
val globalhHashType = LLVMGetTypeByName(llvmModule, "struct.GlobalHash")
|
||||
|
||||
val target = LLVMGetTarget(llvmModule)!!.asCString().toString()
|
||||
|
||||
@@ -40,4 +41,4 @@ class Runtime(private val bitcodeFile: String) {
|
||||
|
||||
val targetData = LLVMCreateTargetData(dataLayout)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
var x : Int = 3
|
||||
}
|
||||
Reference in New Issue
Block a user