0cd4512dd5b632c7f1089b84a1d364aca7ba2818
for code:
--------8<--------
> cat ../backend.native/tests/codegen/basics/null_check.kt
//--- Test "eqeq" -------------------------------------------------------------//
fun check_eqeq(a: Any?) = a == null
fun null_check_eqeq1() : Boolean {
return check_eqeq(Any())
}
fun null_check_eqeq2() : Boolean {
return check_eqeq(null)
}
//--- Test "eqeqeq" -----------------------------------------------------------//
fun check_eqeqeq(a: Any?) = a === null
fun null_check_eqeqeq1() : Boolean {
return check_eqeqeq(Any())
}
fun null_check_eqeqeq2() : Boolean {
return check_eqeqeq(null)
}
--------8<--------
code generator produces, following code:
--------8<--------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/basics/null_check.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/basics/null_check.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 i1 @"kfun:check_eqeq(Any?)"(i8*) {
entry:
%a = alloca i8*
store i8* %0, i8** %a
%tmp_1 = load i8*, i8** %a
%tmp_3 = alloca i1
%tmp_4 = icmp eq i8* %tmp_1, null
br i1 %tmp_4, label %label_1, label %label_0
label_0: ; preds = %entry
%tmp_7 = bitcast i8* %tmp_1 to i8**
%tmp_8 = load i8*, i8** %tmp_7
%tmp_9 = bitcast i8* %tmp_8 to %struct.TypeInfo*
%tmp_10 = call i8* @LookupOpenMethod(%struct.TypeInfo* %tmp_9, i64 5922905592022884074)
%tmp_11 = bitcast i8* %tmp_10 to i1 (i8*, i8*)*
%tmp_6 = call i1 %tmp_11(i8* %tmp_1, i8* null)
store i1 %tmp_6, i1* %tmp_3
br label %label_2
label_1: ; preds = %entry
%tmp_5 = icmp eq i8* %tmp_1, null
store i1 %tmp_5, i1* %tmp_3
br label %label_2
label_2: ; preds = %label_1, %label_0
%tmp_0 = load i1, i1* %tmp_3
ret i1 %tmp_0
}
define i1 @"kfun:null_check_eqeq1()"() {
entry:
%tmp_1 = call i8* @AllocInstance(%struct.TypeInfo* @"ktype:kotlin.Any", i32 1)
%tmp_11 = call i8* @"kfun:kotlin.Any.<init>()"(i8* %tmp_1)
%tmp_0 = call i1 @"kfun:check_eqeq(Any?)"(i8* %tmp_11)
ret i1 %tmp_0
}
declare i8* @"kfun:kotlin.Any.<init>()"(i8*)
define i1 @"kfun:null_check_eqeq2()"() {
entry:
%tmp_0 = call i1 @"kfun:check_eqeq(Any?)"(i8* null)
ret i1 %tmp_0
}
define i1 @"kfun:check_eqeqeq(Any?)"(i8*) {
entry:
%a = alloca i8*
store i8* %0, i8** %a
%tmp_1 = load i8*, i8** %a
%tmp_0 = icmp eq i8* %tmp_1, null
ret i1 %tmp_0
}
define i1 @"kfun:null_check_eqeqeq1()"() {
entry:
%tmp_1 = call i8* @AllocInstance(%struct.TypeInfo* @"ktype:kotlin.Any", i32 1)
%tmp_11 = call i8* @"kfun:kotlin.Any.<init>()"(i8* %tmp_1)
%tmp_0 = call i1 @"kfun:check_eqeqeq(Any?)"(i8* %tmp_11)
ret i1 %tmp_0
}
define i1 @"kfun:null_check_eqeqeq2()"() {
entry:
%tmp_0 = call i1 @"kfun:check_eqeqeq(Any?)"(i8* null)
ret i1 %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%