4e5e7d37ee520085cbb778fa58ea80f94959b3d5
for code "while loop":
-------------8<-------------
> cat ../backend.native/tests/codegen/cycles/cycle.kt
fun cycle(cnt: Int): Int {
var sum = 1
while (sum == cnt) {
sum = sum + 1
}
return sum
}
-------------8<-------------
translator generates:
-------------8<-------------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/cycles/cycle.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/cycles/cycle.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 i32 @"kfun:cycle"(i32) {
entry:
%cnt = alloca i32
store i32 %0, i32* %cnt
%sum = alloca i32
store i32 1, i32* %sum
br label %label_0
label_0: ; preds = %label_1, %entry
%tmp1 = load i32, i32* %sum
%tmp2 = load i32, i32* %cnt
%tmp0 = icmp eq i32 %tmp1, %tmp2
br i1 %tmp0, label %label_1, label %label_2
label_1: ; preds = %label_0
%tmp6 = load i32, i32* %sum
%tmp5 = add i32 %tmp6, 1
store i32 %tmp5, i32* %sum
br label %label_0
label_2: ; preds = %label_0
%tmp8 = load i32, i32* %sum
ret i32 %tmp8
}
-------------8<-------------
for "do-while" code:
-------------8<-------------
> cat ../backend.native/tests/codegen/cycles/cycle_do.kt
fun cycle_do(cnt: Int): Int {
var sum = 1
do {
sum = sum + 2
} while (sum == cnt)
return sum
}
-------------8<-------------
translator produces:
-------------8<-------------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/cycles/cycle_do.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/cycles/cycle_do.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 i32 @"kfun:cycle_do"(i32) {
entry:
%cnt = alloca i32
store i32 %0, i32* %cnt
%sum = alloca i32
store i32 1, i32* %sum
br label %label_0
label_0: ; preds = %label_1, %entry
%tmp3 = load i32, i32* %sum
%tmp2 = add i32 %tmp3, 2
store i32 %tmp2, i32* %sum
br label %label_1
label_1: ; preds = %label_0
%tmp6 = load i32, i32* %sum
%tmp7 = load i32, i32* %cnt
%tmp5 = icmp eq i32 %tmp6, %tmp7
br i1 %tmp5, label %label_0, label %label_2
label_2: ; preds = %label_1
%tmp8 = load i32, i32* %sum
ret i32 %tmp8
}
-------------8<-------------
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
Description
Languages
Kotlin
79.9%
Java
10.4%
Swift
4.3%
C
2.8%
C++
2.1%
Other
0.3%