Review fixes
This commit is contained in:
committed by
Pavel Punegov
parent
8352e5f7d9
commit
45985d9a7f
+6
-7
@@ -28,11 +28,13 @@ import org.jetbrains.kotlin.builtins.isFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isSuspendFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.*
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
@@ -70,13 +72,7 @@ internal fun <T : CallableMemberDescriptor> T.resolveFakeOverride(): T {
|
||||
private val intrinsicAnnotation = FqName("konan.internal.Intrinsic")
|
||||
|
||||
internal val CallableDescriptor.isIntrinsic: Boolean
|
||||
get() = when {
|
||||
this.annotations.hasAnnotation(intrinsicAnnotation) -> {
|
||||
// check(isExternal, { "Intrinsic function $name should be external" })
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
get() = this.annotations.hasAnnotation(intrinsicAnnotation)
|
||||
|
||||
private val intrinsicTypes = setOf(
|
||||
"kotlin.Boolean", "kotlin.Char",
|
||||
@@ -345,3 +341,6 @@ val ClassDescriptor.enumEntries: List<ClassDescriptor>
|
||||
|
||||
internal val DeclarationDescriptor.isExpectMember: Boolean
|
||||
get() = this is MemberDescriptor && this.isExpect
|
||||
|
||||
fun FunctionDescriptor.isComparisonDescriptor(map: Map<SimpleType, IrSimpleFunction>): Boolean =
|
||||
map.values.any { it.descriptor == this }
|
||||
+23
-29
@@ -2341,41 +2341,35 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
||||
context.log{"evaluateOperatorCall : origin:${ir2string(callee)}"}
|
||||
val descriptor = callee.descriptor
|
||||
val ib = context.irModule!!.irBuiltins
|
||||
val funGen = functionGenerationContext
|
||||
|
||||
return when {
|
||||
descriptor == ib.eqeqeq -> funGen.icmpEq(args[0], args[1])
|
||||
descriptor == ib.booleanNot -> funGen.icmpNe(args[0], kTrue)
|
||||
with(functionGenerationContext) {
|
||||
val arg0 = args[0]
|
||||
val arg1 = args[1]
|
||||
return when {
|
||||
descriptor == ib.eqeqeq -> icmpEq(arg0, arg1)
|
||||
descriptor == ib.booleanNot -> icmpNe(arg0, kTrue)
|
||||
|
||||
descriptor.isComparisonDescriptor(ib.greaterFunByOperandType) -> {
|
||||
if (args[0].type.isFloatingPoint()) funGen.fcmpGt(args[0], args[1])
|
||||
else funGen.icmpGt(args[0], args[1])
|
||||
descriptor.isComparisonDescriptor(ib.greaterFunByOperandType) -> {
|
||||
if (arg0.type.isFloatingPoint()) fcmpGt(arg0, arg1)
|
||||
else icmpGt(arg0, arg1)
|
||||
}
|
||||
descriptor.isComparisonDescriptor(ib.greaterOrEqualFunByOperandType) -> {
|
||||
if (arg0.type.isFloatingPoint()) fcmpGe(arg0, arg1)
|
||||
else icmpGe(arg0, arg1)
|
||||
}
|
||||
descriptor.isComparisonDescriptor(ib.lessFunByOperandType) -> {
|
||||
if (arg0.type.isFloatingPoint()) fcmpLt(arg0, arg1)
|
||||
else icmpLt(arg0, arg1)
|
||||
}
|
||||
descriptor.isComparisonDescriptor(ib.lessOrEqualFunByOperandType) -> {
|
||||
if (arg0.type.isFloatingPoint()) fcmpLe(arg0, arg1)
|
||||
else icmpLe(arg0, arg1)
|
||||
}
|
||||
else -> TODO(descriptor.name.toString())
|
||||
}
|
||||
descriptor.isComparisonDescriptor(ib.greaterOrEqualFunByOperandType) -> {
|
||||
if (args[0].type.isFloatingPoint()) funGen.fcmpGe(args[0], args[1])
|
||||
else funGen.icmpGe(args[0], args[1])
|
||||
}
|
||||
descriptor.isComparisonDescriptor(ib.lessFunByOperandType) -> {
|
||||
if (args[0].type.isFloatingPoint()) funGen.fcmpLt(args[0], args[1])
|
||||
else funGen.icmpLt(args[0], args[1])
|
||||
}
|
||||
descriptor.isComparisonDescriptor(ib.lessOrEqualFunByOperandType) -> {
|
||||
if (args[0].type.isFloatingPoint()) funGen.fcmpLe(args[0], args[1])
|
||||
else funGen.icmpLe(args[0], args[1])
|
||||
}
|
||||
else -> TODO(descriptor.name.toString())
|
||||
}
|
||||
}
|
||||
|
||||
private fun LLVMTypeRef.isFloatingPoint(): Boolean {
|
||||
val typeKind = LLVMGetTypeKind(this)
|
||||
return typeKind == LLVMTypeKind.LLVMFloatTypeKind || typeKind == LLVMTypeKind.LLVMDoubleTypeKind
|
||||
}
|
||||
|
||||
private fun FunctionDescriptor.isComparisonDescriptor(map: Map<SimpleType, IrSimpleFunction>): Boolean {
|
||||
return map.values.any { it.descriptor == this }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
private fun generateWhenCase(resultPhi: LLVMValueRef?, branch: IrBranch,
|
||||
|
||||
+5
@@ -307,3 +307,8 @@ internal fun String.mdString() = LLVMMDString(this, this.length)!!
|
||||
internal fun node(vararg it:LLVMValueRef) = LLVMMDNode(it.toList().toCValues(), it.size)
|
||||
|
||||
internal fun LLVMValueRef.setUnaligned() = apply { LLVMSetAlignment(this, 1) }
|
||||
|
||||
fun LLVMTypeRef.isFloatingPoint(): Boolean = when (llvm.LLVMGetTypeKind(this)) {
|
||||
LLVMTypeKind.LLVMFloatTypeKind, LLVMTypeKind.LLVMDoubleTypeKind -> true
|
||||
else -> false
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// IGNORE_BACKEND: JS!
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
inline fun less(a: Comparable<Double>, b: Double): Boolean {
|
||||
return a < b
|
||||
|
||||
@@ -1016,11 +1016,7 @@ public final class Float : Number(), Comparable<Float> {
|
||||
val otherBits = other.toBits()
|
||||
|
||||
// Canonical NaN bits representation higher than any other bit representvalue
|
||||
return when {
|
||||
(thisBits > otherBits) -> 1
|
||||
(thisBits < otherBits) -> -1
|
||||
else -> 0
|
||||
}
|
||||
return thisBits.compareTo(otherBits)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1028,7 +1024,7 @@ public final class Float : Number(), Comparable<Float> {
|
||||
* Returns zero if this value is equal to the specified other value, a negative number if its less than other,
|
||||
* or a positive number if its greater than other.
|
||||
*/
|
||||
public operator fun compareTo(other: Double): Int = - other.toDouble().compareTo(this)
|
||||
public operator fun compareTo(other: Double): Int = - other.compareTo(this)
|
||||
|
||||
/** Adds the other value to this value. */
|
||||
@SymbolName("Kotlin_Float_plus_Byte")
|
||||
@@ -1250,11 +1246,7 @@ public final class Double : Number(), Comparable<Double> {
|
||||
val otherBits = other.toBits()
|
||||
|
||||
// Canonical NaN bits representation higher than any other bit representvalue
|
||||
return when {
|
||||
(thisBits > otherBits) -> 1
|
||||
(thisBits < otherBits) -> -1
|
||||
else -> 0
|
||||
}
|
||||
return thisBits.compareTo(otherBits)
|
||||
}
|
||||
|
||||
/** Adds the other value to this value. */
|
||||
@@ -1371,8 +1363,8 @@ public final class Double : Number(), Comparable<Double> {
|
||||
|
||||
public override fun toShort(): Short = this.toInt().toShort()
|
||||
|
||||
public override fun toInt(): Int = this.toLong().toInt()
|
||||
|
||||
@SymbolName("Kotlin_Double_toInt")
|
||||
external public override fun toInt(): Int
|
||||
@SymbolName("Kotlin_Double_toLong")
|
||||
external public override fun toLong(): Long
|
||||
@SymbolName("Kotlin_Double_toFloat")
|
||||
|
||||
Reference in New Issue
Block a user