Commit Graph

1111 Commits

Author SHA1 Message Date
Alexander Gorshenev 1d265bc50c Here goes stdlib separation.
$ gradlew backend.native:stdlib

builds you stdlib.kt.bc now.

The test runs are taught to supply
-library stdlib.kt.bc to kotlin compiler for proper imports resolution,
and then later stdlib.kt.bc is provided to clang for the final link step.
2016-11-18 19:11:38 +04:00
Alexander Gorshenev b0d10e45d8 changed DynamicTypesAllowed() to DynamicTypesSettings() in KonanPlatformConfigurator.kt 2016-11-18 19:11:38 +04:00
Konstantin Anisimov dfd486a9ea RUNTIME: Code rearranged between Memory.* and Types.* 2016-11-18 16:22:27 +03:00
Konstantin Anisimov d86b387f9c CODEGEN: Implemented support for "instanceOf", operations "Boolean" type implemented, operator NOT_INSTANCEOF implemented
for code
--------8<--------
> cat ../backend.native/tests/codegen/basics/check_type.kt
interface I
class A() : I {}
class B() {}

//-----------------------------------------------------------------------------//

fun isTypeOf(a: Any) : Boolean {
  return a is A
}

fun check_type(): Boolean {
  val a = A()
  return isTypeOf(a)
}

//-----------------------------------------------------------------------------//

fun isNotTypeOf(a: Any) : Boolean {
  return a !is A
}

fun check_not_type(): Boolean {
  val b = B()
  return isNotTypeOf(b)
}

//-----------------------------------------------------------------------------//

fun isTypeOfInterface(a: Any) : Boolean {
  return a is I
}

fun check_interface(): Boolean {
  val a = A()
  return isTypeOfInterface(a)
}
--------8<--------

translator generates:

--------8<--------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/basics/check_type.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/basics/check_type.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:isTypeOf(Any)"(i8*) {
entry:
  %a = alloca i8*
  store i8* %0, i8** %a
  %tmp_1 = load i8*, i8** %a
  %tmp_2 = bitcast i8* %tmp_1 to %struct.ObjHeader*
  %tmp_3 = call i8 @IsInstance(%struct.ObjHeader* %tmp_2, %struct.TypeInfo* @"ktype:A")
  %tmp_0 = trunc i8 %tmp_3 to i1
  ret i1 %tmp_0
}
...
define i1 @"kfun:isNotTypeOf(Any)"(i8*) {
entry:
  %a = alloca i8*
  store i8* %0, i8** %a
  %tmp_2 = load i8*, i8** %a
  %tmp_3 = bitcast i8* %tmp_2 to %struct.ObjHeader*
  %tmp_4 = call i8 @IsInstance(%struct.ObjHeader* %tmp_3, %struct.TypeInfo* @"ktype:A")
  %tmp_1 = trunc i8 %tmp_4 to i1
  %tmp_0 = xor i1 %tmp_1, true
  ret i1 %tmp_0
}
...
define i1 @"kfun:isTypeOfInterface(Any)"(i8*) {
entry:
  %a = alloca i8*
  store i8* %0, i8** %a
  %tmp_1 = load i8*, i8** %a
  %tmp_2 = bitcast i8* %tmp_1 to %struct.ObjHeader*
  %tmp_3 = call i8 @IsInstance(%struct.ObjHeader* %tmp_2, %struct.TypeInfo* @"ktype:I")
  %tmp_0 = trunc i8 %tmp_3 to i1
  ret i1 %tmp_0
}

--------8<--------
2016-11-18 16:22:27 +03:00
Konstantin Anisimov c1bb762417 TESTS: "for" and INSTANCEOF, NOT_INSTANCEOF, isInstanceOf on interface are added 2016-11-18 16:22:27 +03:00
Konstantin Anisimov 3a49e69046 Support for objects' cast implemented
for code

--------8<--------
> cat ../backend.native/tests/codegen/basics/cast_simple.kt
open class A() {}
class B(): A() {}

fun castSimple(o: Any) : A = o as A

fun castTest(): Boolean {
  val b = B()
  castSimple(b)
  return true
}
--------8<--------
translator generates

--------8<--------
>llvm-dis-mp-3.8 ../backend.native/tests/codegen/basics/cast_simple.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/basics/cast_simple.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 i8* @"kfun:castSimple(Any)"(i8*) {
entry:
  %o = alloca i8*
  store i8* %0, i8** %o
  %tmp_1 = load i8*, i8** %o
  %tmp_2 = bitcast i8* %tmp_1 to %struct.ObjHeader*
  call void @CheckInstance(%struct.ObjHeader* %tmp_2, %struct.TypeInfo* @"ktype:A")
  ret i8* %tmp_1
}
--------8<--------
2016-11-18 15:47:28 +03:00
Konstantin Anisimov 9c28555e55 Test for cast added 2016-11-18 15:47:28 +03:00
Konstantin Anisimov 103509d75d Tests fixed 2016-11-18 14:30:32 +03:00
Vasily Levchenko f588814927 tests: disable method_call test until #74 won't be applied 2016-11-18 13:56:14 +03:00
Vasily Levchenko 514d1a16ec test: minus_eq fix 2016-11-18 13:54:34 +03:00
Konstantin Anisimov eb2046fe5d Tests fixed 2016-11-18 12:57:47 +03:00
Konstantin Anisimov 04d441ef21 Test fixed 2016-11-18 12:44:00 +03:00
Vasily Levchenko 8b37001cdf typo in unit test runner 2016-11-18 12:30:27 +03:00
Vasily Levchenko 26710e52a1 use exit(3) in unit tests 2016-11-18 12:27:13 +03:00
Vasily Levchenko d00614ce1b to safe kotlin style main with return type Unit.
Revert "runtime: kotlinNativeMain should return status code and main should return it to the system"

This reverts commit 8161c8ddac.
2016-11-18 12:18:53 +03:00
Vasily Levchenko 8161c8ddac runtime: kotlinNativeMain should return status code and main should return it to the system
(cherry picked from commit acef5ed7e2f7e1d9478d77a1d3405873a7537db1)
2016-11-18 11:22:15 +03:00
Vasily Levchenko 72ef6d43a9 let processing IrWhen as any level expresssion
(cherry picked from commit 00bf82fc5c1a67af16aa2c9c386da8e873a02449)
2016-11-18 06:21:51 +03:00
Nikolay Igotti c20df35c78 Exception classes (#68) 2016-11-17 17:56:34 +03:00
Alexander Gorshenev 8321c14e36 Introduced KonanPlatform, KonanConfig, TopDownAnalyzerFacadeForKonan
and several other supporting facilities
2016-11-17 18:16:15 +04:00
Vasily Levchenko cae9094705 cosmetic: visitField log message formating 2016-11-17 14:57:19 +03:00
Vasily Levchenko 4495c86c2c call of void function
(cherry picked from commit feeacab2bb6e1789e91075dc1b519340cd4f4172)
2016-11-17 14:45:31 +03:00
Vasily Levchenko e4c384e99a replace in-place generation llvm values for true and false with constants
(cherry picked from commit 4a16460b2d778e9406b805f7b6b517b162e77dd8)
2016-11-17 14:45:31 +03:00
Nikolay Igotti fa7bcd90e3 Remove duplicated test. 2016-11-17 14:27:45 +03:00
Alexander Gorshenev 16e4107dee kotlin-compiler: 1.1-20161116.235936-256 2016-11-17 14:56:07 +04:00
Konstantin Anisimov 0fff59a516 Support for object properties access implemented. Minor refactoring
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<--------
2016-11-17 12:25:12 +03:00
Konstantin Anisimov f80697817e Test for getters/setters added 2016-11-17 12:25:12 +03:00
Konstantin Anisimov f393dc3a03 Pasto fixed 2016-11-17 11:02:55 +03:00
Konstantin Anisimov da230bf7b2 Implementation of simple functions for Char
(cherry picked from commit 462c0fb50e3b85a58220d53e34e90e66081cf1ba)
2016-11-17 10:48:49 +03:00
Svyatoslav Scherbina 69ee5a619a backend: add tests for === 2016-11-17 12:17:47 +07:00
Svyatoslav Scherbina 5db25a3985 backend: add tests for duplicated string literals 2016-11-17 12:17:47 +07:00
Svyatoslav Scherbina c622d4cd02 backend: implement === operator 2016-11-17 12:17:47 +07:00
Svyatoslav Scherbina e5d4dc932b backend: don't generate the same string literal twice 2016-11-17 12:17:47 +07:00
Nikolay Igotti cc1b2b9684 Add CheckCast(). 2016-11-16 18:41:36 +03:00
Nikolay Igotti 060163d1c4 Add ClassCastException thrower, small refactoring. (#67) 2016-11-16 18:34:35 +03:00
Nikolay Igotti 16a44ef765 Fix test that would require autoboxing. 2016-11-16 16:28:25 +03:00
Nikolay Igotti 26e8b4860a Enable array1 test. 2016-11-16 16:24:33 +03:00
Vasily Levchenko ab83f5b681 pasto fixed in const evaluation 2016-11-16 15:11:44 +03:00
Nikolay Igotti 0f12daa591 Fix expectations. 2016-11-16 11:23:05 +03:00
Svyatoslav Scherbina 1ff59e2cd2 backend: add some trivial tests for RTTI 2016-11-16 14:58:57 +07:00
Svyatoslav Scherbina f147860fea backend: fix some bugs and improve RTTI
* fix incorrect assert at RTTIGenerator.kt:109
* add `final override` methods to methods table (aka openMethods)
* fix NPE when building vtable  with `final override` methods
* make vtable generation impl more clear
2016-11-16 14:58:57 +07:00
Nikolay Igotti db15540a74 Review feedback on previous changes. (#64) 2016-11-16 10:46:56 +03:00
Alexander Gorshenev ca193efa5c Introduced shims for LLVM StubGenerator.
Run your gradlew task with -Dshims=true to dump the trace

This is not a complete executable solution yet, but already very useful for llvm api tracing
2016-11-16 02:07:51 +04:00
SvyatoslavScherbina 755194486b backend, runtime: improve support for abstract methods (#62)
backend, runtime: improve support for abstract methods

Do not generate vtable and openMethods for abstract classes and interfaces
2016-11-15 17:30:49 +07:00
Nikolay Igotti c5cfa0ac4f Add String.subSequence implementation. (#61) 2016-11-15 13:27:21 +03:00
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
Konstantin Anisimov 04822dda69 Tests for integer cmp operation added 2016-11-15 09:41:25 +03:00
Konstantin Anisimov 59fff52e0c to_master: formatting fix
(cherry picked from commit f7b1ce10f84371bc9f00e91c1f1fb7ed56df9a87)
2016-11-15 09:22:57 +03:00
Vasily Levchenko c99baeaf5d kotlin-compiler: 1.1-20161111.171344-253 2016-11-14 14:41:22 +03:00
Nikolay Igotti fe032a8ba9 Add missing classes to work without builtins. (#57) 2016-11-14 14:08:20 +03:00
Nikolay Igotti ae5e838305 Add overrides by name. (#54) 2016-11-14 13:25:50 +03:00