let processing IrWhen as any level expresssion
(cherry picked from commit 00bf82fc5c1a67af16aa2c9c386da8e873a02449)
This commit is contained in:
+19
-11
@@ -88,16 +88,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
|
|
||||||
override fun visitWhen(expression: IrWhen) {
|
override fun visitWhen(expression: IrWhen) {
|
||||||
logger.log("visitWhen : ${ir2string(expression)}")
|
logger.log("visitWhen : ${ir2string(expression)}")
|
||||||
var bbExit:LLVMOpaqueBasicBlock? = null // By default "when" does not have "exit"
|
evaluateWhen(expression)
|
||||||
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.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
@@ -313,6 +304,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
is IrReturn -> return evaluateReturn ( value)
|
is IrReturn -> return evaluateReturn ( value)
|
||||||
is IrBlock -> return evaluateBlock ( value)
|
is IrBlock -> return evaluateBlock ( value)
|
||||||
is IrExpressionBody -> return evaluateExpression (tmpVariableName, value.expression)
|
is IrExpressionBody -> return evaluateExpression (tmpVariableName, value.expression)
|
||||||
|
is IrWhen -> return evaluateWhen ( value)
|
||||||
null -> return null
|
null -> return null
|
||||||
else -> {
|
else -> {
|
||||||
TODO()
|
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 {
|
private fun evaluateGetValue(tmpVariableName: String, value: IrGetValue): LLVMOpaqueValue {
|
||||||
logger.log("evaluateGetValue : $tmpVariableName = ${ir2string(value)}")
|
logger.log("evaluateGetValue : $tmpVariableName = ${ir2string(value)}")
|
||||||
when (value.descriptor) {
|
when (value.descriptor) {
|
||||||
@@ -491,8 +499,8 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
})
|
})
|
||||||
|
|
||||||
when {
|
when {
|
||||||
value.descriptor is FunctionDescriptor -> return evaluateFunctionCall(tmpVariableName, value as IrCall, args)
|
|
||||||
value is IrDelegatingConstructorCall -> return superCall(tmpVariableName, value.descriptor, args)
|
value is IrDelegatingConstructorCall -> return superCall(tmpVariableName, value.descriptor, args)
|
||||||
|
value.descriptor is FunctionDescriptor -> return evaluateFunctionCall(tmpVariableName, value as IrCall, args)
|
||||||
else -> {
|
else -> {
|
||||||
TODO()
|
TODO()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user