backend.native: improve type mapping
including types of functions
This commit is contained in:
+2
-1
@@ -49,7 +49,8 @@ internal interface ContextUtils {
|
|||||||
assert (this.kind.isReal)
|
assert (this.kind.isReal)
|
||||||
val globalName = this.symbolName
|
val globalName = this.symbolName
|
||||||
val module = context.llvmModule
|
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)
|
val function = LLVMGetNamedFunction(module, globalName) ?: LLVMAddFunction(module, globalName, functionType)
|
||||||
return compileTimeValue(function)
|
return compileTimeValue(function)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -6,10 +6,12 @@ import org.jetbrains.kotlin.types.KotlinType
|
|||||||
|
|
||||||
internal fun getLLVMType(type: KotlinType): LLVMOpaqueType {
|
internal fun getLLVMType(type: KotlinType): LLVMOpaqueType {
|
||||||
return when {
|
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.isShort(type) || KotlinBuiltIns.isChar(type) -> LLVMInt16Type()
|
||||||
KotlinBuiltIns.isInt(type) -> LLVMInt32Type()
|
KotlinBuiltIns.isInt(type) -> LLVMInt32Type()
|
||||||
KotlinBuiltIns.isLong(type) -> LLVMInt64Type()
|
KotlinBuiltIns.isLong(type) -> LLVMInt64Type()
|
||||||
|
KotlinBuiltIns.isUnit(type) -> LLVMVoidType() // TODO: handle Unit parameter case
|
||||||
!KotlinBuiltIns.isPrimitiveType(type) -> LLVMPointerType(LLVMInt8Type(), 0)
|
!KotlinBuiltIns.isPrimitiveType(type) -> LLVMPointerType(LLVMInt8Type(), 0)
|
||||||
else -> throw NotImplementedError()
|
else -> throw NotImplementedError()
|
||||||
}!!
|
}!!
|
||||||
|
|||||||
+15
-1
@@ -2,6 +2,8 @@ package org.jetbrains.kotlin.backend.native.llvm
|
|||||||
|
|
||||||
import kotlin_native.interop.mallocNativeArrayOf
|
import kotlin_native.interop.mallocNativeArrayOf
|
||||||
import llvm.*
|
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
|
* 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 val int32Type = LLVMInt32Type()
|
||||||
|
|
||||||
internal fun pointerType(pointeeType: LLVMOpaqueType?) = LLVMPointerType(pointeeType, 0)
|
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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user