Konstantin Anisimov 69b7cdb866 Support for built in types com parision implemented
for following code snipped:
---------------8<---------------
> cat ../backend.native/tests/codegen/function/eqeq.kt
fun eqeqB  (a:Byte,   b:Byte  ) = a == b
fun eqeqS  (a:Short,  b:Short ) = a == b
fun eqeqI  (a:Int,    b:Int   ) = a == b
fun eqeqL  (a:Long,   b:Long  ) = a == b
fun eqeqF  (a:Float,  b:Float ) = a == b
fun eqeqD  (a:Double, b:Double) = a == b
fun eqeqStr(a:String, b:String) = a == b

fun gtI  (a:Int,    b:Int   ) = a >  b
fun ltI  (a:Int,    b:Int   ) = a >  b
fun geI  (a:Int,    b:Int   ) = a >= b
fun leI  (a:Int,    b:Int   ) = a <= b
fun neI  (a:Int,    b:Int   ) = a != b

fun gtF  (a:Float,  b:Float ) = a >  b
fun ltF  (a:Float,  b:Float ) = a >  b
fun geF  (a:Float,  b:Float ) = a >= b
fun leF  (a:Float,  b:Float ) = a <= b
fun neF  (a:Float,  b:Float ) = a != b

fun helloString()   =  "Hello"
fun goodbyeString() =  "Goodbye"

---------------8<---------------

interesting cases here are '==' for primitive and objects and any < =< > >= and separatelly !=

---------------8<---------------
; ModuleID = '../backend.native/tests/codegen/function/eqeq.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:eqeqB(Byte;Byte)"(i8, i8) {
entry:
  %a = alloca i8
  store i8 %0, i8* %a
  %b = alloca i8
  store i8 %1, i8* %b
  %tmp_1 = load i8, i8* %a
  %tmp_2 = load i8, i8* %b
  %tmp_0 = icmp eq i8 %tmp_1, %tmp_2 <- '==' for primitive
  ret i1 %tmp_0
}
...

define i1 @"kfun:eqeqStr(String;String)"(i8*, i8*) {
entry:
  %a = alloca i8*
  store i8* %0, i8** %a
  %b = alloca i8*
  store i8* %1, i8** %b
  %tmp_1 = load i8*, i8** %a
  %tmp_2 = load i8*, i8** %b
  %tmp_0 = call i1 @Kotlin_String_equals(i8* %tmp_1, i8* %tmp_2) <-- '==' for object
  ret i1 %tmp_0
}
...

define i1 @"kfun:gtI(Int;Int)"(i32, i32) {
entry:
  %a = alloca i32
  store i32 %0, i32* %a
  %b = alloca i32
  store i32 %1, i32* %b
  %tmp_2 = load i32, i32* %a
  %tmp_3 = load i32, i32* %b
  %tmp_1 = call i32 @Kotlin_Int_compareTo_Int(i32 %tmp_2, i32 %tmp_3) <-- '>' for primitive
  %tmp_0 = icmp sgt i32 %tmp_1, 0                                     <--/
  ret i1 %tmp_0
}
...

define i1 @"kfun:neI(Int;Int)"(i32, i32) {
entry:
  %a = alloca i32
  store i32 %0, i32* %a
  %b = alloca i32
  store i32 %1, i32* %b
  %tmp_2 = load i32, i32* %a
  %tmp_3 = load i32, i32* %b
  %tmp_1 = icmp eq i32 %tmp_2, %tmp_3  <---  '!=' fro primitive
  %tmp_0 = icmp ne i1 %tmp_1, true     <--/
  ret i1 %tmp_0
}

---------------8<---------------
2016-11-15 09:41:25 +03:00
2016-10-27 13:52:00 +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%