Commit Graph

1061 Commits

Author SHA1 Message Date
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
Nikolay Igotti 91035b692b Add more console operations, nicer naming in natives. (#46) 2016-11-08 17:38:36 +03:00
Vasily Levchenko 5b7d0257e8 upgrade kotlin-compiler: 20161108.133759-248 2016-11-08 17:38:09 +03:00
Alexander Udalov a7bef2d0ee Lower priority of compiler built-ins in resolution (#43)
* Remove unneeded module context creation in K2Native

Calling this method is useful only when its result is used

* Use JvmAbi from compiler instead of reflection implementation

Package "kotlin.reflect.jvm.internal.impl" is internal implementation detail of
kotlin-reflect and should not be used

* Run native back-end with "-ea"

This allows to get more detailed messages in case something fails

* Lower priority of compiler built-ins in resolution

CREATE_BUILT_INS_FROM_MODULE_DEPENDENCIES makes sure that the "built-ins" that
the compiler front-end uses during the resolution are loaded from the module
being resolved itself, i.e. from its sources and/or dependencies. E.g. if
there's a class named kotlin.Any in module sources, it'll become the default
supertype for any class without an explicit supertype.

ADD_BUILT_INS_FROM_COMPILER_TO_DEPENDENCIES adds the built-ins from the
compiler jar to the end of the dependencies list of the module being resolved.
This option makes sure that if there's no built-in class in module
sources/dependencies and it is required by the front-end, the class definition
from the compiler jar will be taken instead of failing with an exception.

If both of these options are turned on, the effect is basically that compiler
built-ins are still there in the classpath, but have a lower priority than
classes explicitly declared in sources
2016-11-08 16:20:33 +03:00
Nikolay Igotti a354f4b605 Make String CharSequence compatible. 2016-11-08 14:16:59 +03:00
alexander-gorshenev d2bf3a6ceb Merge pull request #44 from JetBrains/relocation
Further relocation from 'native' to 'kotlin'
2016-11-08 14:52:47 +04:00
Alexander Gorshenev 67889cb31c Further relocation from 'native' to 'kotlin'
Moved the left behind files and renamed the package.
2016-11-08 13:22:24 +03:00
Konstantin Anisimov 4a20e37c9f code generator fixes:
1. IR visitor does not stop children processing on IrClass entry.
2. method call (namely property getter).
2016-11-08 11:13:26 +03:00
Svyatoslav Scherbina 55f8257f92 build: simplify clang(++) configuration
also introduce 'execClang' block
2016-11-08 13:51:25 +07:00
Konstantin Anisimov 4e5e7d37ee Implemented support for loop codegeneration: "while" and "do-while".
for code "while loop":
-------------8<-------------
> cat ../backend.native/tests/codegen/cycles/cycle.kt
fun cycle(cnt: Int): Int {
  var sum = 1
  while (sum == cnt) {
    sum = sum + 1
  }
  return sum
}

-------------8<-------------
translator generates:
-------------8<-------------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/cycles/cycle.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/cycles/cycle.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:cycle"(i32) {
entry:
  %cnt = alloca i32
  store i32 %0, i32* %cnt
  %sum = alloca i32
  store i32 1, i32* %sum
  br label %label_0

label_0:                                          ; preds = %label_1, %entry
  %tmp1 = load i32, i32* %sum
  %tmp2 = load i32, i32* %cnt
  %tmp0 = icmp eq i32 %tmp1, %tmp2
  br i1 %tmp0, label %label_1, label %label_2

label_1:                                          ; preds = %label_0
  %tmp6 = load i32, i32* %sum
  %tmp5 = add i32 %tmp6, 1
  store i32 %tmp5, i32* %sum
  br label %label_0

label_2:                                          ; preds = %label_0
  %tmp8 = load i32, i32* %sum
  ret i32 %tmp8
}

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

for "do-while" code:
-------------8<-------------
> cat ../backend.native/tests/codegen/cycles/cycle_do.kt
fun cycle_do(cnt: Int): Int {
  var sum = 1
  do {
    sum = sum + 2
  } while (sum == cnt)
  return sum
}

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

translator produces:
-------------8<-------------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/cycles/cycle_do.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/cycles/cycle_do.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:cycle_do"(i32) {
entry:
  %cnt = alloca i32
  store i32 %0, i32* %cnt
  %sum = alloca i32
  store i32 1, i32* %sum
  br label %label_0

label_0:                                          ; preds = %label_1, %entry
  %tmp3 = load i32, i32* %sum
  %tmp2 = add i32 %tmp3, 2
  store i32 %tmp2, i32* %sum
  br label %label_1

label_1:                                          ; preds = %label_0
  %tmp6 = load i32, i32* %sum
  %tmp7 = load i32, i32* %cnt
  %tmp5 = icmp eq i32 %tmp6, %tmp7
  br i1 %tmp5, label %label_0, label %label_2

label_2:                                          ; preds = %label_1
  %tmp8 = load i32, i32* %sum
  ret i32 %tmp8
}

-------------8<-------------
2016-11-08 06:35:50 +03:00
Konstantin Anisimov 152e738e23 Tests for "while" and "do-while" loop generation 2016-11-08 06:35:50 +03:00
Nikolay Igotti bfb6e448c5 Remove gradle wrapper in experiments. 2016-11-07 19:22:56 +03:00
alexander-gorshenev bbbec132e5 Merge pull request #41 from JetBrains/metadata
Metadata
2016-11-07 20:14:54 +04:00
Alexander Gorshenev 9a5454c333 Disentangled class metadata and llvm metadata.
It was decided to call class data 'link data'.
And retain the metadata name for LLVM metadata.
2016-11-07 18:47:34 +03:00
Alexander Gorshenev dab43d9862 Added some type info to fun metadata 2016-11-07 18:16:00 +03:00
Alexander Gorshenev 4afc7be7b7 'native' is a java keyword, so javac doesn't allow it as a package name component.
Renamed 'native' to 'konan'.
Moved BinaryMetadata.proto to konan/llvm where it belongs for now.
2016-11-07 18:16:00 +03:00
Alexander Gorshenev 56f574684a Code style and nullables fixes 2016-11-07 18:16:00 +03:00
Alexander Gorshenev 26e3101014 Now we can add metadata nodes to bitcode module.
We just put in the names of functions for now.
2016-11-07 18:14:50 +03:00
Alexander Gorshenev f76a4f6dc9 A simple protobuf description for bitcode metadata 2016-11-07 18:14:50 +03:00
Alexander Gorshenev 62f8b31cf0 Google protobuf has been added to the build 2016-11-07 18:14:50 +03:00
Konstantin Anisimov d4c3d6dabd plus'n'minus_eq operation: support for integer comparison operations
for code (plus_eq):

--------------8<------------------
> cat ../backend.native/tests/codegen/function/plus_eq.kt
fun plus_eq(a: Int): Int {
  var b = 11
  b += a
  return b
}
--------------8<------------------

generator produces:

--------------8<------------------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/function/plus_eq.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/function/plus_eq.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:plus_eq"(i32) {
entry:
  %a = alloca i32
  store i32 %0, i32* %a
  %b = alloca i32
  store i32 11, i32* %b
  %tmp1 = load i32, i32* %b
  %tmp2 = load i32, i32* %a
  %tmp0 = add i32 %tmp1, %tmp2
  store i32 %tmp0, i32* %b
  %tmp3 = load i32, i32* %b
  ret i32 %tmp3
}
--------------8<------------------

and for (minus_eq):

--------------8<------------------
> cat ../backend.native/tests/codegen/function/minus_eq.kt
fun minus_eq(a: Int): Int {
  var b = 11
  b -= a
  return b
}

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

generator produces:

--------------8<------------------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/function/minus_eq.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/function/minus_eq.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:minus_eq"(i32) {
entry:
  %a = alloca i32
  store i32 %0, i32* %a
  %b = alloca i32
  store i32 11, i32* %b
  %tmp1 = load i32, i32* %b
  %tmp2 = load i32, i32* %a
  %tmp0 = sub i32 %tmp1, %tmp2
  store i32 %tmp0, i32* %b
  %tmp3 = load i32, i32* %b
  ret i32 %tmp3
}
--------------8<------------------
2016-11-07 18:00:30 +03:00
Konstantin Anisimov ea149fab4e Tests for "PLUSEQ" and "MINUSEQ" 2016-11-07 18:00:30 +03:00
Nikolay Igotti a022b7d1ab Char constants. 2016-11-07 17:42:29 +03:00
Konstantin Anisimov 3c68ee4ce5 testsuite updated to reflect recent changes in codegen: branch support 2016-11-07 17:34:01 +03:00
Vasily Levchenko 76ee79adc0 branching: branch suppport introduced
--------------8<----------------
> cat if_else.kt
fun if_else(b: Boolean): Int {
  if (b) return 42
  else   return 24
}
--------------8<----------------
we've got following bitcode:
--------------8<----------------
; ModuleID = '../backend.native/tests/codegen/branching/if_else.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:if_else"(i1) {
entry:
  %b = alloca i1
  store i1 %0, i1* %b
  %tmp0 = load i1, i1* %b
  br i1 %tmp0, label %label_0, label %label_1

label_0:                                          ; preds = %entry
  ret i32 42

label_1:                                          ; preds = %entry
  ret i32 24
}
...
--------------8<----------------
2016-11-07 17:34:01 +03:00
Vasily Levchenko 147de5d3ad added .usr/bin path to tools chain to take right variants of binutils from our system archieve 2016-11-07 17:25:08 +03:00
Nikolay Igotti f06aeef9ce Some work for string concatenation. (#40) 2016-11-07 15:58:11 +03:00
Svyatoslav Scherbina 451ac00087 backend/tests: enable hello0 2016-11-07 17:42:47 +07:00
Svyatoslav Scherbina 674713f429 backend: instantiate string literals statically
also improve other code for static instantiation
2016-11-07 17:42:47 +07:00
vvlevchenko fddaea5624 Merge pull request #34 from JetBrains/ir-processing-refactoring
Ir processing refactoring
2016-11-03 20:42:32 +03:00