Commit Graph

1090 Commits

Author SHA1 Message Date
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
SvyatoslavScherbina 248d9ad2ef Merge pull request #56 from JetBrains/add-fun-signatures
Add function signatures to symbol names and RTTI
2016-11-14 14:13:12 +07:00
Svyatoslav Scherbina 3d36973022 backend/build: improve LLVM link options
Update options according to llvm-config:

* delete "--stdlib=libc++"  (it seems to provoke runtime link errors on Linux)
* remove "-lffi" (it doesn't seem to be required)
* remove "-lc++" on macOS

Also move Linux system libs options to llvm.def (as for macOS)
2016-11-14 14:12:25 +07:00
Konstantin Anisimov d1a303bb25 Refactoring:
1. generator -> codegen
2. tmpVariable -> newVar
3. All calls for LLVM* functions migrated to CodeGenerator
4. mutable list -> list for arguments.
2016-11-14 10:01:23 +03:00
Svyatoslav Scherbina f389ebf687 backend/tests: update resolved symbol names
according to new mangling scheme
2016-11-14 13:33:47 +07:00
Svyatoslav Scherbina cc4f0ca1a4 backend: add basic support for override by name 2016-11-14 13:31:14 +07:00
Konstantin Anisimov c47a58d34f codegen: implementation virtual calls and bit refactoring... callVirtual and callDirect become members of Ir2Bitcode.
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<-----------------
2016-11-11 17:43:44 +03:00
Konstantin Anisimov 24e0ae7d00 rtti: introduces functionName extension function to FunctionDescriptor for filling vtable with hashcode and reusing it in codegeneration 2016-11-11 17:43:44 +03:00
Konstantin Anisimov fa3943c8bd TEST: enabled hello2 test case 2016-11-11 17:43:44 +03:00
Nikolay Igotti 4a0b78f7b4 Make builtin classes final. (#53) 2016-11-11 17:35:37 +03:00
Nikolay Igotti 4b7f67d976 Fix array accessor signatures, add array test to fix. 2016-11-11 16:21:48 +03:00
Svyatoslav Scherbina edf3708515 build: fix linking tests on Linux
runtime now requires "-lm"
2016-11-11 19:22:34 +07:00
Svyatoslav Scherbina 66bd698270 build: make clang using gcc toolchain on Linux
also fix Mac build failure related to 'ar'
2016-11-11 19:22:34 +07:00
Svyatoslav Scherbina bee2a76008 build: refactor platform checks
also improve verbosity when downloading dependencies fails
2016-11-11 19:22:34 +07:00
Nikolay Igotti 720947facb Alloc arrays, fix RTTI for Any (#49) 2016-11-11 15:03:49 +03:00
Nikolay Igotti af85121b2c Add primitive types to String conversion. (#50) 2016-11-11 14:16:15 +03:00
Konstantin Anisimov a910627357 tests: added eqeq test
tests: sum-test: emproved test sum of int with various types of second argument (byte, short and etc)
tests: hello2 minor fix in test
2016-11-10 15:25:08 +03:00
Konstantin Anisimov 265f688425 runtime: operators' (+, -, %, /, *, inc, dec, boolean arithmetic, compareTo, unaryPlus, unaryMinus, conversions) implementations for primitive types (byte, short, int, long, float, double) 2016-11-10 15:25:08 +03:00
Konstantin Anisimov cb39f650f3 codegen: operator processing for primitive and other types 2016-11-10 15:25:08 +03:00
Nikolay Igotti 6c90ab1176 Use toolchain with relative paths on Linux. 2016-11-09 17:05:18 +03:00
Nikolay Igotti 71088c85ad Add more runtime, avoid codegen for interfaces. (#47)
* Add more runtime, avoid codegen for interfaces.

* backend: fix bug in RTTIGenerator

kotlin.Nothing has no supertypes

* runtime: enable kotlin.Nothing
2016-11-09 09:20:34 +03:00
Nikolay Igotti 00fdc90d43 Hack to run tests on Linux. 2016-11-08 18:31:45 +03:00