diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/ContextUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/ContextUtils.kt index 133e20bdf8c..02c69f65a52 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/ContextUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/ContextUtils.kt @@ -49,7 +49,8 @@ internal interface ContextUtils { assert (this.kind.isReal) val globalName = this.symbolName val module = context.llvmModule - val functionType = LLVMFunctionType(LLVMVoidType(), null, 0, 0) // FIXME: use correct types + + val functionType = getLlvmFunctionType(this) val function = LLVMGetNamedFunction(module, globalName) ?: LLVMAddFunction(module, globalName, functionType) return compileTimeValue(function) } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/DataLayout.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/DataLayout.kt index a859f49f706..48082cca35f 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/DataLayout.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/DataLayout.kt @@ -6,10 +6,12 @@ import org.jetbrains.kotlin.types.KotlinType internal fun getLLVMType(type: KotlinType): LLVMOpaqueType { return when { - KotlinBuiltIns.isBoolean(type) || KotlinBuiltIns.isByte(type) -> LLVMInt8Type() + KotlinBuiltIns.isBoolean(type) -> LLVMInt1Type() + KotlinBuiltIns.isByte(type) -> LLVMInt8Type() KotlinBuiltIns.isShort(type) || KotlinBuiltIns.isChar(type) -> LLVMInt16Type() KotlinBuiltIns.isInt(type) -> LLVMInt32Type() KotlinBuiltIns.isLong(type) -> LLVMInt64Type() + KotlinBuiltIns.isUnit(type) -> LLVMVoidType() // TODO: handle Unit parameter case !KotlinBuiltIns.isPrimitiveType(type) -> LLVMPointerType(LLVMInt8Type(), 0) else -> throw NotImplementedError() }!! diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/LlvmUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/LlvmUtils.kt index c64179906fc..f3ab701e56b 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/LlvmUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/LlvmUtils.kt @@ -2,6 +2,8 @@ package org.jetbrains.kotlin.backend.native.llvm import kotlin_native.interop.mallocNativeArrayOf import llvm.* +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.utils.singletonOrEmptyList /** * Represents the value which can be emitted as bitcode const value @@ -55,4 +57,16 @@ internal fun compileTimeValue(value: LLVMOpaqueValue?) = object : CompileTimeVal internal val int32Type = LLVMInt32Type() -internal fun pointerType(pointeeType: LLVMOpaqueType?) = LLVMPointerType(pointeeType, 0) \ No newline at end of file +internal fun pointerType(pointeeType: LLVMOpaqueType?) = LLVMPointerType(pointeeType, 0) + +internal fun getLlvmFunctionType(function: FunctionDescriptor): LLVMOpaqueType? { + val returnType = getLLVMType(function.returnType!!) + val params = function.dispatchReceiverParameter.singletonOrEmptyList() + + 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) +} \ No newline at end of file