0fff59a5164a9b46e741b14d9c3c81d5bb86106c
following code:
--------8<--------
> cat ../backend.native/tests/codegen/object/method_call.kt
class A(val a:Int) {
fun foo(i:Int) = a + i
}
fun fortyTwo() = A(41).foo(1)
--------8<--------
translator generates following getter
--------8<--------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/object/method_call.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/object/method_call.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:A.<get-a>()"(i8*) {
entry:
%this = alloca i8*
store i8* %0, i8** %this
%tmp_1 = load i8*, i8** %this
%tmp_2 = bitcast i8* %tmp_1 to %struct.ObjHeader*
%tmp_3 = getelementptr %struct.ObjHeader, %struct.ObjHeader* %tmp_2, i32 1
%tmp_4 = bitcast %struct.ObjHeader* %tmp_3 to %"kclass:A"*
%tmp_5 = getelementptr inbounds %"kclass:A", %"kclass:A"* %tmp_4, i32 0, i32 0
%tmp_6 = load i32, i32* %tmp_5
ret i32 %tmp_6
}
...
--------8<--------
similar history for global properties:
--------8<--------
> cat ../backend.native/tests/codegen/object/fields.kt
private var globalValue = 1
var global:Int
get() = globalValue
set(value:Int) {globalValue = value}
fun globalTest(i:Int):Int {
global += i
return global
}
--------8<--------
translator generates following code:
--------8<--------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/object/fields.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/object/fields.kt.bc'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.12.0"
...
@"kvar:<root>.globalValue" = global i32 1
...
define i32 @"kfun:<get-globalValue>()"() {
entry:
%tmp_1 = load i32, i32* @"kvar:<root>.globalValue"
ret i32 %tmp_1
}
define void @"kfun:<set-globalValue>(Int)"(i32) {
entry:
%"<set-?>" = alloca i32
store i32 %0, i32* %"<set-?>"
%tmp_0 = load i32, i32* %"<set-?>"
store i32 %tmp_0, i32* @"kvar:<root>.globalValue"
ret void
}
define i32 @"kfun:<get-global>()"() {
entry:
%tmp_0 = call i32 @"kfun:<get-globalValue>()"()
ret i32 %tmp_0
}
define void @"kfun:<set-global>(Int)"(i32) {
entry:
%value = alloca i32
store i32 %0, i32* %value
%tmp_0 = load i32, i32* %value
call void @"kfun:<set-globalValue>(Int)"(i32 %tmp_0)
ret void
}
--------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%