c47a58d34f833c15cf79976f9bd8f69e0e7b2491
some details: this is runtime based function resolving will be replaced with compile time soon.
example:
-----------------8<-----------------
> cat ../backend.native/tests/runtime/basic/hello2.kt
// TODO: remove kotlin_native.io once overrides are in place.
fun main(args : Array<String>) {
print("you entered '" + readLine() + "'")
}
-----------------8<-----------------
translator generates following (reduced)
-----------------8<-----------------
> llvm-dis-mp-3.8 ../backend.native/tests/runtime/basic/hello2.kt.bc -o -
; ModuleID = '../backend.native/tests/runtime/basic/hello2.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"(i8*) {
entry:
%args = alloca i8*
store i8* %0, i8** %args
%tmp_3 = call i8* @Kotlin_io_Console_readLine()
%tmp_1 = call i8* @"kfun:kotlin.String.plus"(i8* @"kstr:bwW55yLpGKEB25tD4IQg8ZiUSe0=", i8* %tmp_3)
%tmp_0 = call i8* @"kfun:kotlin.String.plus"(i8* %tmp_1, i8* @"kstr:u1idBiHlRy9HD6NCWiNMdLHiAug=")
call void @Kotlin_io_Console_print(i8* %tmp_0)
ret void
}
declare i8* @Kotlin_io_Console_readLine()
define i8* @"kfun:kotlin.String.plus"(i8*, i8*) {
entry:
%this = alloca i8*
store i8* %0, i8** %this
%other = alloca i8*
store i8* %1, i8** %other
%tmp_1 = load i8*, i8** %this
%tmp_3 = load i8*, i8** %other
%tmp_4 = bitcast i8* %tmp_3 to i8**
%tmp_5 = load i8*, i8** %tmp_4
%tmp_6 = bitcast i8* %tmp_5 to %struct.TypeInfo*
%tmp_7 = call i8* @LookupOpenMethod(%struct.TypeInfo* %tmp_6, i64 5382438289122769377) <-- runtime resolve method
%tmp_8 = bitcast i8* %tmp_7 to i8* (i8*)*
%tmp_2 = call i8* %tmp_8(i8* %tmp_3)
%tmp_0 = call i8* @Kotlin_String_plusImpl(i8* %tmp_1, i8* %tmp_2)
ret i8* %tmp_0
}
-----------------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%