Vasily Levchenko cf466e0cd7 codegen: fix implementation of branch generation to generate 'ternary' operator
for code:
--------8<--------
> cat ../backend.native/tests/runtime/basic/hello4.kt
fun main(args : Array<String>) {
    val x = 2
    println(if (x == 2) "Hello" else "Привет")
    println(if (x == 3) "Bye" else "Пока")
 }
--------8<--------
code generator produces:
--------8<--------
> llvm-dis-mp-3.8 ../backend.native/tests/runtime/basic/hello4.kt.bc -o -
; ModuleID = '../backend.native/tests/runtime/basic/hello4.kt.bc'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.12.0"

...
define void @"kfun:main(Array<String>)"(i8*) {
entry:
  %args = alloca i8*
  store i8* %0, i8** %args
  %x = alloca i32
  store i32 2, i32* %x
  %tmp_1 = alloca i8*                             ; allocation of temporal variable (0)
  %tmp_3 = load i32, i32* %x
  %tmp_2 = icmp eq i32 %tmp_3, 2
  br i1 %tmp_2, label %label_2, label %label_1

label_0:                                          ; preds = %label_2, %label_1
  %tmp_0 = load i8*, i8** %tmp_1                  ; load value from tmp_1 (2)
  call void @Kotlin_io_Console_println(i8* %tmp_0)
  %tmp_8 = alloca i8*
  %tmp_10 = load i32, i32* %x
  %tmp_9 = icmp eq i32 %tmp_10, 3
  br i1 %tmp_9, label %label_5, label %label_4

label_1:                                          ; preds = %entry  store value to tmp_1 (1)
  store i8* @"kstr:KAWujn4S8YITX5L7kIQ7sQgNO+g=", i8** %tmp_1
  br label %label_0

label_2:                                          ; preds = %entry
  store i8* @"kstr:9/+ei3uy4Jtwk1pdeF4MxdnQq/A=", i8** %tmp_1
  br label %label_0

label_3:                                          ; preds = %label_5, %label_4
  %tmp_7 = load i8*, i8** %tmp_8
  call void @Kotlin_io_Console_println(i8* %tmp_7)
  ret void

label_4:                                          ; preds = %label_0
  store i8* @"kstr:q9lt9dN14ItE52B0fKxQuwMq4cc=", i8** %tmp_8
  br label %label_3

label_5:                                          ; preds = %label_0
  store i8* @"kstr:95JCQGTQyhp9FO/gWI8QwFLSjmk=", i8** %tmp_8
  br label %label_3
}

...
--------8<--------
2016-11-21 20:36:40 +03:00
2016-10-27 13:52:00 +03:00
2016-11-21 13:21:23 +03:00
2016-10-07 14:14:00 +03:00
2016-10-27 13:52:00 +03:00
2016-10-27 13:52:00 +03:00

Kotlin-native backend

Build

Download dependencies:

gradle :dependencies:update

To run native translator just use:

gradle :backend.native:run

And it will run simple example (currently prints out IR of test file). For more tests, use:

gradle :backend.native:tests:run
S
Description
The Kotlin Programming Language.
Readme 2.1 GiB
Languages
Kotlin 79.9%
Java 10.4%
Swift 4.3%
C 2.8%
C++ 2.1%
Other 0.3%