From 72ef6d43a9e4b28ed0208a4c986cf4ee10e10566 Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Fri, 18 Nov 2016 06:06:07 +0300 Subject: [PATCH] let processing IrWhen as any level expresssion (cherry picked from commit 00bf82fc5c1a67af16aa2c9c386da8e873a02449) --- .../kotlin/backend/konan/llvm/IrToBitcode.kt | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) 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 ac7bf91b896..cdc8298ad32 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 @@ -88,16 +88,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid override fun visitWhen(expression: IrWhen) { logger.log("visitWhen : ${ir2string(expression)}") - var bbExit:LLVMOpaqueBasicBlock? = null // By default "when" does not have "exit" - if (!KotlinBuiltIns.isNothing(expression.type)) // If "when" has "exit". - bbExit = codegen.basicBlock() // Create basic block to process "exit". - - expression.branches.forEach { // Iterate through "when" branches (clauses). - var bbNext = bbExit // For last clause bbNext coincides with bbExit. - if (it != expression.branches.last()) // If it is not last clause. - bbNext = codegen.basicBlock() // Create new basic block for next clause. - generateWhenCase(it, bbNext, bbExit) // Generate code for current clause. - } + evaluateWhen(expression) } //-------------------------------------------------------------------------// @@ -313,6 +304,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid is IrReturn -> return evaluateReturn ( value) is IrBlock -> return evaluateBlock ( value) is IrExpressionBody -> return evaluateExpression (tmpVariableName, value.expression) + is IrWhen -> return evaluateWhen ( value) null -> return null else -> { TODO() @@ -322,6 +314,22 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid //-------------------------------------------------------------------------// + private fun evaluateWhen(expression: IrWhen): LLVMOpaqueValue? { + var bbExit:LLVMOpaqueBasicBlock? = null // By default "when" does not have "exit" + if (!KotlinBuiltIns.isNothing(expression.type)) // If "when" has "exit". + bbExit = codegen.basicBlock() // Create basic block to process "exit". + + expression.branches.forEach { // Iterate through "when" branches (clauses). + var bbNext = bbExit // For last clause bbNext coincides with bbExit. + if (it != expression.branches.last()) // If it is not last clause. + bbNext = codegen.basicBlock() // Create new basic block for next clause. + generateWhenCase(it, bbNext, bbExit) // Generate code for current clause. + } + return null + } + + //-------------------------------------------------------------------------// + private fun evaluateGetValue(tmpVariableName: String, value: IrGetValue): LLVMOpaqueValue { logger.log("evaluateGetValue : $tmpVariableName = ${ir2string(value)}") when (value.descriptor) { @@ -491,8 +499,8 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid }) when { - value.descriptor is FunctionDescriptor -> return evaluateFunctionCall(tmpVariableName, value as IrCall, args) value is IrDelegatingConstructorCall -> return superCall(tmpVariableName, value.descriptor, args) + value.descriptor is FunctionDescriptor -> return evaluateFunctionCall(tmpVariableName, value as IrCall, args) else -> { TODO() }