From c622d4cd025ba400458c5269653ba513ad512116 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Thu, 17 Nov 2016 11:36:03 +0700 Subject: [PATCH] backend: implement `===` operator --- .../kotlin/backend/konan/llvm/IrToBitcode.kt | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index 788b27b6ffd..3fa58b655b8 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -429,6 +429,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid //-------------------------------------------------------------------------// private val kEqeq = Name.identifier("EQEQ") + private val ktEqeqeq = Name.identifier("EQEQEQ") private val kGt0 = Name.identifier("GT0") private val kGteq0 = Name.identifier("GTEQ0") private val kLt0 = Name.identifier("LT0") @@ -444,13 +445,15 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid val descriptor = callee.descriptor when (descriptor.name) { kEqeq -> return evaluateOperatorEqeq(callee as IrBinaryPrimitiveImpl, args[0]!!, args[1]!!, tmpVariableName) + ktEqeqeq -> + return evaluateOperatorEqeqeq(callee as IrBinaryPrimitiveImpl, args[0]!!, args[1]!!, tmpVariableName) kGt0 -> return codegen.icmpGt(args[0]!!, kImmZero, tmpVariableName) kGteq0 -> return codegen.icmpGe(args[0]!!, kImmZero, tmpVariableName) kLt0 -> return codegen.icmpLt(args[0]!!, kImmZero, tmpVariableName) kLteq0 -> return codegen.icmpLe(args[0]!!, kImmZero, tmpVariableName) kNot -> return codegen.icmpNe(args[0]!!, kTrue, tmpVariableName) else -> { - TODO() + TODO(descriptor.name.toString()) } } } @@ -478,6 +481,23 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid //-------------------------------------------------------------------------// + private fun evaluateOperatorEqeqeq(callee: IrBinaryPrimitiveImpl, + arg0: LLVMOpaqueValue, arg1: LLVMOpaqueValue, + tmpVariableName: String):LLVMOpaqueValue { + + val arg0Type = callee.argument0.type + val arg1Type = callee.argument1.type + + assert (arg0Type == arg1Type) + + return when { + KotlinBuiltIns.isPrimitiveType(arg0Type) -> TODO() + else -> codegen.icmpEq(arg0, arg1, tmpVariableName) + } + } + + //-------------------------------------------------------------------------// + private fun generateWhenCase(branch: IrBranch, bbNext: LLVMOpaqueBasicBlock?, bbExit: LLVMOpaqueBasicBlock?) { if (isUnconditional(branch)) { // It is the "else" clause. evaluateExpression(codegen.newVar(), branch.result) // Generate clause body.