diff --git a/kotstd/include/BooleanArray.kt b/kotstd/include/BooleanArray.kt index 3b2200059f1..656b2771ea1 100644 --- a/kotstd/include/BooleanArray.kt +++ b/kotstd/include/BooleanArray.kt @@ -1,3 +1,5 @@ +external fun kotlinclib_boolean_size(): Int + class BooleanArray(var size: Int) { val data: Int @@ -5,7 +7,7 @@ class BooleanArray(var size: Int) { //size: Int init { - this.data = malloc_array(this.size) + this.data = malloc_array(kotlinclib_boolean_size() * this.size) } /** Returns the array element at the given [index]. This method can be called using the index operator. */ @@ -19,8 +21,7 @@ class BooleanArray(var size: Int) { operator fun set(index: Int, value: Boolean) { if (value == true) { kotlinclib_set_byte(this.data, index, 1.toByte()) - } - else{ + } else { kotlinclib_set_byte(this.data, index, 0.toByte()) } } diff --git a/kotstd/include/ByteArray.kt b/kotstd/include/ByteArray.kt index 904ecd1f6f1..fbcac272ca6 100644 --- a/kotstd/include/ByteArray.kt +++ b/kotstd/include/ByteArray.kt @@ -1,6 +1,7 @@ external fun malloc_array(size: Int): Int external fun kotlinclib_get_byte(src: Int, index: Int): Byte external fun kotlinclib_set_byte(src: Int, index: Int, value: Byte) +external fun kotlinclib_byte_size(): Int class ByteArray(var size: Int) { @@ -10,7 +11,7 @@ class ByteArray(var size: Int) { //size: Int init { - this.data = malloc_array(this.size) + this.data = malloc_array(kotlinclib_byte_size() * this.size) } /** Returns the array element at the given [index]. This method can be called using the index operator. */ diff --git a/kotstd/include/IntArray.kt b/kotstd/include/IntArray.kt index d731c28b8cf..e2b9d616b44 100644 --- a/kotstd/include/IntArray.kt +++ b/kotstd/include/IntArray.kt @@ -1,5 +1,6 @@ external fun kotlinclib_get_int(src: Int, index: Int): Int external fun kotlinclib_set_int(src: Int, index: Int, value: Int) +external fun kotlinclib_int_size(): Int class IntArray(var size: Int) { @@ -9,7 +10,7 @@ class IntArray(var size: Int) { //size: Int init { - this.data = malloc_array(4 * this.size) + this.data = malloc_array(kotlinclib_int_size() * this.size) } /** Returns the array element at the given [index]. This method can be called using the index operator. */ diff --git a/kotstd/include/LongArray.kt b/kotstd/include/LongArray.kt new file mode 100644 index 00000000000..683ce2130a2 --- /dev/null +++ b/kotstd/include/LongArray.kt @@ -0,0 +1,92 @@ +external fun kotlinclib_get_long(src: Int, index: Int): Long +external fun kotlinclib_set_long(src: Int, index: Int, value: Long) +external fun kotlinclib_long_size(): Int + + +class LongArray(var size: Int) { + val data: Int + + /** Returns the number of elements in the array. */ + //size: Int + + init { + this.data = malloc_array(kotlinclib_long_size() * this.size) + } + + /** Returns the array element at the given [index]. This method can be called using the index operator. */ + operator fun get(index: Int): Long { + return kotlinclib_get_long(this.data, index) + } + + + /** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */ + operator fun set(index: Int, value: Long) { + kotlinclib_set_long(this.data, index, value) + } + + + fun clone(): LongArray { + val newInstance = LongArray(this.size) + var index = 0 + while (index < this.size) { + val value = this.get(index) + newInstance.set(index, value) + index = index + 1 + } + + return newInstance + } +} + +fun LongArray.copyOf(newSize: Int): LongArray { + val newInstance = LongArray(newSize) + var index = 0 + val end = if (newSize > this.size) this.size else newSize + while (index < end) { + val value = this.get(index) + newInstance.set(index, value) + index = index + 1 + } + + while (index < newSize) { + newInstance.set(index, 0) + index = index + 1 + } + + return newInstance +} + +fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): LongArray { + val newInstance = LongArray(toIndex - fromIndex) + var index = fromIndex + while (index < toIndex) { + val value = this.get(index) + newInstance.set(index - fromIndex, value) + index = index + 1 + } + + return newInstance +} + +operator fun LongArray.plus(element: Long): LongArray { + val index = size + val result = this.copyOf(index + 1) + result[index] = element + return result +} + +operator fun LongArray.plus(elements: LongArray): LongArray { + val thisSize = size + val arraySize = elements.size + val resultSize = thisSize + arraySize + val newInstance = this.copyOf(resultSize) + var index = thisSize + + while (index < resultSize) { + val value = elements.get(index - thisSize) + newInstance.set(index, value) + index = index + 1 + } + + return newInstance +} \ No newline at end of file diff --git a/kotstd/include/ShortArray.kt b/kotstd/include/ShortArray.kt index b9c6bf07070..a9c5ec0672f 100644 --- a/kotstd/include/ShortArray.kt +++ b/kotstd/include/ShortArray.kt @@ -1,5 +1,6 @@ external fun kotlinclib_get_short(src: Int, index: Int): Short external fun kotlinclib_set_short(src: Int, index: Int, value: Short) +external fun kotlinclib_short_size(): Int class ShortArray(var size: Int) { @@ -9,7 +10,7 @@ class ShortArray(var size: Int) { //size: Int init { - this.data = malloc_array(this.size) + this.data = malloc_array(kotlinclib_short_size() * this.size) } /** Returns the array element at the given [index]. This method can be called using the index operator. */ diff --git a/kotstd/lib/arm/array_c.ll b/kotstd/lib/arm/array_c.ll index a2766bc94b3..4e01dd4193a 100644 --- a/kotstd/lib/arm/array_c.ll +++ b/kotstd/lib/arm/array_c.ll @@ -2,18 +2,17 @@ target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" target triple = "thumbv7m-none--eabi" -declare i8* @malloc_static(i32) #0 - ; Function Attrs: nounwind define weak i32 @malloc_array(i32 %x) #0 { %1 = alloca i32, align 4 store i32 %x, i32* %1, align 4 %2 = load i32* %1, align 4 - %3 = call i8* @malloc_static(i32 %2) + %3 = call i8* @malloc(i32 %2) #2 %4 = ptrtoint i8* %3 to i32 ret i32 %4 } +declare i8* @malloc(i32) #1 ; Function Attrs: nounwind define weak zeroext i8 @kotlinclib_get_byte(i32 %data, i32 %index) #0 { @@ -117,4 +116,47 @@ define weak void @kotlinclib_set_short(i32 %data, i32 %index, i16 signext %value ret void } +; Function Attrs: nounwind +define weak i32 @kotlinclib_get_long(i32 %data, i32 %index) #0 { + %1 = alloca i32, align 4 + %2 = alloca i32, align 4 + store i32 %data, i32* %1, align 4 + store i32 %index, i32* %2, align 4 + %3 = load i32* %1, align 4 + %4 = inttoptr i32 %3 to i32* + %5 = load i32* %2, align 4 + %6 = getelementptr inbounds i32* %4, i32 %5 + %7 = load i32* %6, align 4 + ret i32 %7 +} + +; Function Attrs: nounwind +define weak void @kotlinclib_set_long(i32 %data, i32 %index, i32 %value) #0 { + %1 = alloca i32, align 4 + %2 = alloca i32, align 4 + %3 = alloca i32, align 4 + %ptr = alloca i32*, align 4 + store i32 %data, i32* %1, align 4 + store i32 %index, i32* %2, align 4 + store i32 %value, i32* %3, align 4 + %4 = load i32* %1, align 4 + %5 = inttoptr i32 %4 to i32* + store i32* %5, i32** %ptr, align 4 + %6 = load i32* %3, align 4 + %7 = load i32** %ptr, align 4 + %8 = load i32* %2, align 4 + %9 = getelementptr inbounds i32* %7, i32 %8 + store i32 %6, i32* %9, align 4 + ret void +} + attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { nobuiltin } + +!llvm.module.flags = !{!0, !1} +!llvm.ident = !{!2} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{i32 1, !"min_enum_size", i32 4} +!2 = !{!"Ubuntu clang version 3.6.2-3ubuntu2 (tags/RELEASE_362/final) (based on LLVM 3.6.2)"} diff --git a/kotstd/lib/arm/console_c.ll b/kotstd/lib/arm/console_c.ll index 80e601c9565..0eb3e507444 100644 --- a/kotstd/lib/arm/console_c.ll +++ b/kotstd/lib/arm/console_c.ll @@ -3,133 +3,133 @@ target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" target triple = "thumbv7m-none--eabi" ; Function Attrs: nounwind -define void @kotlinclib_print_int(i32 %message) #0 { +define weak void @kotlinclib_print_int(i32 %message) #0 { %1 = alloca i32, align 4 store i32 %message, i32* %1, align 4 ret void } ; Function Attrs: nounwind -define void @kotlinclib_print_long(i32 %message) #0 { +define weak void @kotlinclib_print_long(i32 %message) #0 { %1 = alloca i32, align 4 store i32 %message, i32* %1, align 4 ret void } ; Function Attrs: nounwind -define void @kotlinclib_print_byte(i8 zeroext %message) #0 { +define weak void @kotlinclib_print_byte(i8 zeroext %message) #0 { %1 = alloca i8, align 1 store i8 %message, i8* %1, align 1 ret void } ; Function Attrs: nounwind -define void @kotlinclib_print_short(i16 signext %message) #0 { +define weak void @kotlinclib_print_short(i16 signext %message) #0 { %1 = alloca i16, align 2 store i16 %message, i16* %1, align 2 ret void } ; Function Attrs: nounwind -define void @kotlinclib_print_char(i8 zeroext %message) #0 { +define weak void @kotlinclib_print_char(i8 zeroext %message) #0 { %1 = alloca i8, align 1 store i8 %message, i8* %1, align 1 ret void } ; Function Attrs: nounwind -define void @kotlinclib_print_boolean(i1 %message) #0 { +define weak void @kotlinclib_print_boolean(i1 %message) #0 { %1 = alloca i1, align 4 store i1 %message, i1* %1, align 4 ret void } ; Function Attrs: nounwind -define void @kotlinclib_print_float(float %message) #0 { +define weak void @kotlinclib_print_float(float %message) #0 { %1 = alloca float, align 4 store float %message, float* %1, align 4 ret void } ; Function Attrs: nounwind -define void @kotlinclib_print_double(double %message) #0 { +define weak void @kotlinclib_print_double(double %message) #0 { %1 = alloca double, align 8 store double %message, double* %1, align 8 ret void } ; Function Attrs: nounwind -define void @kotlinclib_print_string(i8* %message) #0 { +define weak void @kotlinclib_print_string(i8* %message) #0 { %1 = alloca i8*, align 4 store i8* %message, i8** %1, align 4 ret void } ; Function Attrs: nounwind -define void @kotlinclib_println_int(i32 %message) #0 { +define weak void @kotlinclib_println_int(i32 %message) #0 { %1 = alloca i32, align 4 store i32 %message, i32* %1, align 4 ret void } ; Function Attrs: nounwind -define void @kotlinclib_println_long(i32 %message) #0 { +define weak void @kotlinclib_println_long(i32 %message) #0 { %1 = alloca i32, align 4 store i32 %message, i32* %1, align 4 ret void } ; Function Attrs: nounwind -define void @kotlinclib_println_byte(i8 zeroext %message) #0 { +define weak void @kotlinclib_println_byte(i8 zeroext %message) #0 { %1 = alloca i8, align 1 store i8 %message, i8* %1, align 1 ret void } ; Function Attrs: nounwind -define void @kotlinclib_println_short(i16 signext %message) #0 { +define weak void @kotlinclib_println_short(i16 signext %message) #0 { %1 = alloca i16, align 2 store i16 %message, i16* %1, align 2 ret void } ; Function Attrs: nounwind -define void @kotlinclib_println_char(i8 zeroext %message) #0 { +define weak void @kotlinclib_println_char(i8 zeroext %message) #0 { %1 = alloca i8, align 1 store i8 %message, i8* %1, align 1 ret void } ; Function Attrs: nounwind -define void @kotlinclib_println_boolean(i1 %message) #0 { +define weak void @kotlinclib_println_boolean(i1 %message) #0 { %1 = alloca i1, align 4 store i1 %message, i1* %1, align 4 ret void } ; Function Attrs: nounwind -define void @kotlinclib_println_float(float %message) #0 { +define weak void @kotlinclib_println_float(float %message) #0 { %1 = alloca float, align 4 store float %message, float* %1, align 4 ret void } ; Function Attrs: nounwind -define void @kotlinclib_println_double(double %message) #0 { +define weak void @kotlinclib_println_double(double %message) #0 { %1 = alloca double, align 8 store double %message, double* %1, align 8 ret void } ; Function Attrs: nounwind -define void @kotlinclib_println_string(i8* %message) #0 { +define weak void @kotlinclib_println_string(i8* %message) #0 { %1 = alloca i8*, align 4 store i8* %message, i8** %1, align 4 ret void } ; Function Attrs: nounwind -define void @kotlinclib_println() #0 { +define weak void @kotlinclib_println() #0 { ret void } diff --git a/kotstd/lib/arm/primitives_c.ll b/kotstd/lib/arm/primitives_c.ll index 70bbd4386b2..632d4896f00 100644 --- a/kotstd/lib/arm/primitives_c.ll +++ b/kotstd/lib/arm/primitives_c.ll @@ -260,7 +260,7 @@ define weak float @kotlinclib_longToFloat(i32 %value) #0 { } ; Function Attrs: nounwind -define double @kotlinclib_longToDouble(i32 %value) #0 { +define weak double @kotlinclib_longToDouble(i32 %value) #0 { %1 = alloca i32, align 4 store i32 %value, i32* %1, align 4 %2 = load i32* %1, align 4 @@ -376,4 +376,46 @@ define weak float @kotlinclib_doubleToFloat(double %value) #0 { ret float %3 } +; Function Attrs: nounwind +define weak i32 @kotlinclib_int_size() #0 { + ret i32 4 +} + +; Function Attrs: nounwind +define weak i32 @kotlinclib_long_size() #0 { + ret i32 8 +} + +; Function Attrs: nounwind +define weak i32 @kotlinclib_boolean_size() #0 { + ret i32 1 +} + +; Function Attrs: nounwind +define weak i32 @kotlinclib_short_size() #0 { + ret i32 2 +} + +; Function Attrs: nounwind +define weak i32 @kotlinclib_double_size() #0 { + ret i32 8 +} + +; Function Attrs: nounwind +define weak i32 @kotlinclib_float_size() #0 { + ret i32 4 +} + +; Function Attrs: nounwind +define weak i32 @kotlinclib_char_size() #0 { + ret i32 1 +} + attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.module.flags = !{!0, !1} +!llvm.ident = !{!2} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{i32 1, !"min_enum_size", i32 4} +!2 = !{!"Ubuntu clang version 3.6.2-3ubuntu2 (tags/RELEASE_362/final) (based on LLVM 3.6.2)"} diff --git a/kotstd/lib/kotlin-reflect.jar b/kotstd/lib/kotlin-reflect.jar new file mode 100644 index 00000000000..62340e2dae4 Binary files /dev/null and b/kotstd/lib/kotlin-reflect.jar differ diff --git a/kotstd/lib/kotlin-runtime-sources.jar b/kotstd/lib/kotlin-runtime-sources.jar new file mode 100644 index 00000000000..e661b30034a Binary files /dev/null and b/kotstd/lib/kotlin-runtime-sources.jar differ diff --git a/kotstd/lib/kotlin-runtime.jar b/kotstd/lib/kotlin-runtime.jar new file mode 100644 index 00000000000..4d7a92703f8 Binary files /dev/null and b/kotstd/lib/kotlin-runtime.jar differ diff --git a/kotstd/lib/x86/array_c.ll b/kotstd/lib/x86/array_c.ll index c82227b8908..0cd31ef0e23 100644 --- a/kotstd/lib/x86/array_c.ll +++ b/kotstd/lib/x86/array_c.ll @@ -1,16 +1,21 @@ -declare i8* @malloc_static(i32) +; ModuleID = 'array.c' +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-linux-gnu" +; Function Attrs: nounwind uwtable define weak i32 @malloc_array(i32 %x) #0 { %1 = alloca i32, align 4 store i32 %x, i32* %1, align 4 %2 = load i32* %1, align 4 - %3 = call i8* @malloc_static(i32 %2) + %3 = call i8* @malloc(i32 %2) %4 = ptrtoint i8* %3 to i32 ret i32 %4 } +declare i8* @malloc(i32) #1 + ; Function Attrs: nounwind uwtable -define weak signext i8 @kotlinclib_get_byte(i32 %data, i32 %index) { +define weak signext i8 @kotlinclib_get_byte(i32 %data, i32 %index) #0 { %1 = alloca i32, align 4 %2 = alloca i32, align 4 store i32 %data, i32* %1, align 4 @@ -26,7 +31,7 @@ define weak signext i8 @kotlinclib_get_byte(i32 %data, i32 %index) { } ; Function Attrs: nounwind uwtable -define weak void @kotlinclib_set_byte(i32 %data, i32 %index, i8 signext %value) { +define weak void @kotlinclib_set_byte(i32 %data, i32 %index, i8 signext %value) #0 { %1 = alloca i32, align 4 %2 = alloca i32, align 4 %3 = alloca i8, align 1 @@ -47,9 +52,8 @@ define weak void @kotlinclib_set_byte(i32 %data, i32 %index, i8 signext %value) ret void } - ; Function Attrs: nounwind uwtable -define weak i32 @kotlinclib_get_int(i32 %data, i32 %index) { +define weak i32 @kotlinclib_get_int(i32 %data, i32 %index) #0 { %1 = alloca i32, align 4 %2 = alloca i32, align 4 store i32 %data, i32* %1, align 4 @@ -65,7 +69,7 @@ define weak i32 @kotlinclib_get_int(i32 %data, i32 %index) { } ; Function Attrs: nounwind uwtable -define weak void @kotlinclib_set_int(i32 %data, i32 %index, i32 %value) { +define weak void @kotlinclib_set_int(i32 %data, i32 %index, i32 %value) #0 { %1 = alloca i32, align 4 %2 = alloca i32, align 4 %3 = alloca i32, align 4 @@ -86,9 +90,8 @@ define weak void @kotlinclib_set_int(i32 %data, i32 %index, i32 %value) { ret void } - ; Function Attrs: nounwind uwtable -define weak signext i16 @kotlinclib_get_short(i32 %data, i32 %index) { +define weak signext i16 @kotlinclib_get_short(i32 %data, i32 %index) #0 { %1 = alloca i32, align 4 %2 = alloca i32, align 4 store i32 %data, i32* %1, align 4 @@ -104,7 +107,7 @@ define weak signext i16 @kotlinclib_get_short(i32 %data, i32 %index) { } ; Function Attrs: nounwind uwtable -define weak void @kotlinclib_set_short(i32 %data, i32 %index, i16 signext %value) { +define weak void @kotlinclib_set_short(i32 %data, i32 %index, i16 signext %value) #0 { %1 = alloca i32, align 4 %2 = alloca i32, align 4 %3 = alloca i16, align 2 @@ -124,3 +127,48 @@ define weak void @kotlinclib_set_short(i32 %data, i32 %index, i16 signext %value store i16 %7, i16* %11, align 2 ret void } + +; Function Attrs: nounwind uwtable +define weak i64 @kotlinclib_get_long(i32 %data, i32 %index) #0 { + %1 = alloca i32, align 4 + %2 = alloca i32, align 4 + store i32 %data, i32* %1, align 4 + store i32 %index, i32* %2, align 4 + %3 = load i32* %1, align 4 + %4 = sext i32 %3 to i64 + %5 = inttoptr i64 %4 to i64* + %6 = load i32* %2, align 4 + %7 = sext i32 %6 to i64 + %8 = getelementptr inbounds i64* %5, i64 %7 + %9 = load i64* %8, align 8 + ret i64 %9 +} + +; Function Attrs: nounwind uwtable +define weak void @kotlinclib_set_long(i32 %data, i32 %index, i64 %value) #0 { + %1 = alloca i32, align 4 + %2 = alloca i32, align 4 + %3 = alloca i64, align 8 + %ptr = alloca i64*, align 8 + store i32 %data, i32* %1, align 4 + store i32 %index, i32* %2, align 4 + store i64 %value, i64* %3, align 8 + %4 = load i32* %1, align 4 + %5 = sext i32 %4 to i64 + %6 = inttoptr i64 %5 to i64* + store i64* %6, i64** %ptr, align 8 + %7 = load i64* %3, align 8 + %8 = load i64** %ptr, align 8 + %9 = load i32* %2, align 4 + %10 = sext i32 %9 to i64 + %11 = getelementptr inbounds i64* %8, i64 %10 + store i64 %7, i64* %11, align 8 + ret void +} + +attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = !{!"Ubuntu clang version 3.6.2-3ubuntu2 (tags/RELEASE_362/final) (based on LLVM 3.6.2)"} diff --git a/kotstd/lib/x86/console_c.ll b/kotstd/lib/x86/console_c.ll index 0a8ad5c6f38..71277bff916 100644 --- a/kotstd/lib/x86/console_c.ll +++ b/kotstd/lib/x86/console_c.ll @@ -12,7 +12,7 @@ target triple = "x86_64-pc-linux-gnu" @.str7 = private unnamed_addr constant [3 x i8] c"%s\00", align 1 ; Function Attrs: nounwind uwtable -define void @kotlinclib_print_int(i32 %message) #0 { +define weak void @kotlinclib_print_int(i32 %message) #0 { %1 = alloca i32, align 4 store i32 %message, i32* %1, align 4 %2 = load i32* %1, align 4 @@ -23,7 +23,7 @@ define void @kotlinclib_print_int(i32 %message) #0 { declare i32 @printf(i8*, ...) #1 ; Function Attrs: nounwind uwtable -define void @kotlinclib_print_long(i64 %message) #0 { +define weak void @kotlinclib_print_long(i64 %message) #0 { %1 = alloca i64, align 8 store i64 %message, i64* %1, align 8 %2 = load i64* %1, align 8 @@ -32,7 +32,7 @@ define void @kotlinclib_print_long(i64 %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_print_byte(i8 signext %message) #0 { +define weak void @kotlinclib_print_byte(i8 signext %message) #0 { %1 = alloca i8, align 1 store i8 %message, i8* %1, align 1 %2 = load i8* %1, align 1 @@ -42,7 +42,7 @@ define void @kotlinclib_print_byte(i8 signext %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_print_short(i16 signext %message) #0 { +define weak void @kotlinclib_print_short(i16 signext %message) #0 { %1 = alloca i16, align 2 store i16 %message, i16* %1, align 2 %2 = load i16* %1, align 2 @@ -52,7 +52,7 @@ define void @kotlinclib_print_short(i16 signext %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_print_char(i8 signext %message) #0 { +define weak void @kotlinclib_print_char(i8 signext %message) #0 { %1 = alloca i8, align 1 store i8 %message, i8* %1, align 1 %2 = load i8* %1, align 1 @@ -62,7 +62,7 @@ define void @kotlinclib_print_char(i8 signext %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_print_boolean(i1 %message) #0 { +define weak void @kotlinclib_print_boolean(i1 %message) #0 { %1 = alloca i1, align 4 store i1 %message, i1* %1, align 4 %2 = load i1* %1, align 4 @@ -82,7 +82,7 @@ define void @kotlinclib_print_boolean(i1 %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_print_float(float %message) #0 { +define weak void @kotlinclib_print_float(float %message) #0 { %1 = alloca float, align 4 store float %message, float* %1, align 4 %2 = load float* %1, align 4 @@ -92,7 +92,7 @@ define void @kotlinclib_print_float(float %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_print_double(double %message) #0 { +define weak void @kotlinclib_print_double(double %message) #0 { %1 = alloca double, align 8 store double %message, double* %1, align 8 %2 = load double* %1, align 8 @@ -101,7 +101,7 @@ define void @kotlinclib_print_double(double %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_print_string(i8* %message) #0 { +define weak void @kotlinclib_print_string(i8* %message) #0 { %1 = alloca i8*, align 8 store i8* %message, i8** %1, align 8 %2 = load i8** %1, align 8 @@ -110,13 +110,13 @@ define void @kotlinclib_print_string(i8* %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_println() #0 { +define weak void @kotlinclib_println() #0 { call void @kotlinclib_print_char(i8 signext 10) ret void } ; Function Attrs: nounwind uwtable -define void @kotlinclib_println_int(i32 %message) #0 { +define weak void @kotlinclib_println_int(i32 %message) #0 { %1 = alloca i32, align 4 store i32 %message, i32* %1, align 4 %2 = load i32* %1, align 4 @@ -126,7 +126,7 @@ define void @kotlinclib_println_int(i32 %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_println_long(i64 %message) #0 { +define weak void @kotlinclib_println_long(i64 %message) #0 { %1 = alloca i64, align 8 store i64 %message, i64* %1, align 8 %2 = load i64* %1, align 8 @@ -136,7 +136,7 @@ define void @kotlinclib_println_long(i64 %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_println_byte(i8 signext %message) #0 { +define weak void @kotlinclib_println_byte(i8 signext %message) #0 { %1 = alloca i8, align 1 store i8 %message, i8* %1, align 1 %2 = load i8* %1, align 1 @@ -146,7 +146,7 @@ define void @kotlinclib_println_byte(i8 signext %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_println_short(i16 signext %message) #0 { +define weak void @kotlinclib_println_short(i16 signext %message) #0 { %1 = alloca i16, align 2 store i16 %message, i16* %1, align 2 %2 = load i16* %1, align 2 @@ -156,7 +156,7 @@ define void @kotlinclib_println_short(i16 signext %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_println_char(i8 signext %message) #0 { +define weak void @kotlinclib_println_char(i8 signext %message) #0 { %1 = alloca i8, align 1 store i8 %message, i8* %1, align 1 %2 = load i8* %1, align 1 @@ -166,7 +166,7 @@ define void @kotlinclib_println_char(i8 signext %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_println_boolean(i1 %message) #0 { +define weak void @kotlinclib_println_boolean(i1 %message) #0 { %1 = alloca i1, align 4 store i1 %message, i1* %1, align 4 %2 = load i1* %1, align 4 @@ -176,7 +176,7 @@ define void @kotlinclib_println_boolean(i1 %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_println_float(float %message) #0 { +define weak void @kotlinclib_println_float(float %message) #0 { %1 = alloca float, align 4 store float %message, float* %1, align 4 %2 = load float* %1, align 4 @@ -186,7 +186,7 @@ define void @kotlinclib_println_float(float %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_println_double(double %message) #0 { +define weak void @kotlinclib_println_double(double %message) #0 { %1 = alloca double, align 8 store double %message, double* %1, align 8 %2 = load double* %1, align 8 @@ -196,7 +196,7 @@ define void @kotlinclib_println_double(double %message) #0 { } ; Function Attrs: nounwind uwtable -define void @kotlinclib_println_string(i8* %message) #0 { +define weak void @kotlinclib_println_string(i8* %message) #0 { %1 = alloca i8*, align 8 store i8* %message, i8** %1, align 8 %2 = load i8** %1, align 8 diff --git a/kotstd/lib/x86/primitives_c.ll b/kotstd/lib/x86/primitives_c.ll index 7dbb9213163..fdfd9831b9e 100644 --- a/kotstd/lib/x86/primitives_c.ll +++ b/kotstd/lib/x86/primitives_c.ll @@ -1,10 +1,9 @@ ; ModuleID = 'primitives.c' -target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" -target triple = "x86_64-pc-linux-gnu" +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" +target triple = "thumbv7m-none--eabi" -attributes #0 = { nounwind "stack-protector-buffer-size"="8" "target-cpu"="cortex-m3" "target-features"="+hwdiv,+strict-align" } -; Function Attrs: nounwind uwtable -define weak signext i8 @kotlinclib_intToByte(i32 %value) #0 { +; Function Attrs: nounwind +define weak zeroext i8 @kotlinclib_intToByte(i32 %value) #0 { %1 = alloca i32, align 4 store i32 %value, i32* %1, align 4 %2 = load i32* %1, align 4 @@ -12,8 +11,8 @@ define weak signext i8 @kotlinclib_intToByte(i32 %value) #0 { ret i8 %3 } -; Function Attrs: nounwind uwtable -define weak signext i8 @kotlinclib_intToChar(i32 %value) #0 { +; Function Attrs: nounwind +define weak zeroext i8 @kotlinclib_intToChar(i32 %value) #0 { %1 = alloca i32, align 4 store i32 %value, i32* %1, align 4 %2 = load i32* %1, align 4 @@ -21,7 +20,7 @@ define weak signext i8 @kotlinclib_intToChar(i32 %value) #0 { ret i8 %3 } -; Function Attrs: nounwind uwtable +; Function Attrs: nounwind define weak signext i16 @kotlinclib_intToShort(i32 %value) #0 { %1 = alloca i32, align 4 store i32 %value, i32* %1, align 4 @@ -30,16 +29,15 @@ define weak signext i16 @kotlinclib_intToShort(i32 %value) #0 { ret i16 %3 } -; Function Attrs: nounwind uwtable -define weak i64 @kotlinclib_intToLong(i32 %value) #0 { +; Function Attrs: nounwind +define weak i32 @kotlinclib_intToLong(i32 %value) #0 { %1 = alloca i32, align 4 store i32 %value, i32* %1, align 4 %2 = load i32* %1, align 4 - %3 = sext i32 %2 to i64 - ret i64 %3 + ret i32 %2 } -; Function Attrs: nounwind uwtable +; Function Attrs: nounwind define weak float @kotlinclib_intToFloat(i32 %value) #0 { %1 = alloca i32, align 4 store i32 %value, i32* %1, align 4 @@ -48,7 +46,7 @@ define weak float @kotlinclib_intToFloat(i32 %value) #0 { ret float %3 } -; Function Attrs: nounwind uwtable +; Function Attrs: nounwind define weak double @kotlinclib_intToDouble(i32 %value) #0 { %1 = alloca i32, align 4 store i32 %value, i32* %1, align 4 @@ -57,114 +55,114 @@ define weak double @kotlinclib_intToDouble(i32 %value) #0 { ret double %3 } -; Function Attrs: nounwind uwtable -define weak signext i8 @kotlinclib_byteToChar(i8 signext %value) #0 { +; Function Attrs: nounwind +define weak zeroext i8 @kotlinclib_byteToChar(i8 zeroext %value) #0 { %1 = alloca i8, align 1 store i8 %value, i8* %1, align 1 %2 = load i8* %1, align 1 ret i8 %2 } -; Function Attrs: nounwind uwtable -define weak signext i16 @kotlinclib_byteToShort(i8 signext %value) #0 { +; Function Attrs: nounwind +define weak signext i16 @kotlinclib_byteToShort(i8 zeroext %value) #0 { %1 = alloca i8, align 1 store i8 %value, i8* %1, align 1 %2 = load i8* %1, align 1 - %3 = sext i8 %2 to i16 + %3 = zext i8 %2 to i16 ret i16 %3 } -; Function Attrs: nounwind uwtable -define weak i32 @kotlinclib_byteToInt(i8 signext %value) #0 { +; Function Attrs: nounwind +define weak i32 @kotlinclib_byteToInt(i8 zeroext %value) #0 { %1 = alloca i8, align 1 store i8 %value, i8* %1, align 1 %2 = load i8* %1, align 1 - %3 = sext i8 %2 to i32 + %3 = zext i8 %2 to i32 ret i32 %3 } -; Function Attrs: nounwind uwtable -define weak i64 @kotlinclib_byteToLong(i8 signext %value) #0 { +; Function Attrs: nounwind +define weak i32 @kotlinclib_byteToLong(i8 zeroext %value) #0 { %1 = alloca i8, align 1 store i8 %value, i8* %1, align 1 %2 = load i8* %1, align 1 - %3 = sext i8 %2 to i64 - ret i64 %3 + %3 = zext i8 %2 to i32 + ret i32 %3 } -; Function Attrs: nounwind uwtable -define weak float @kotlinclib_byteToFloat(i8 signext %value) #0 { +; Function Attrs: nounwind +define weak float @kotlinclib_byteToFloat(i8 zeroext %value) #0 { %1 = alloca i8, align 1 store i8 %value, i8* %1, align 1 %2 = load i8* %1, align 1 - %3 = sitofp i8 %2 to float + %3 = uitofp i8 %2 to float ret float %3 } -; Function Attrs: nounwind uwtable -define weak double @kotlinclib_byteToDouble(i8 signext %value) #0 { +; Function Attrs: nounwind +define weak double @kotlinclib_byteToDouble(i8 zeroext %value) #0 { %1 = alloca i8, align 1 store i8 %value, i8* %1, align 1 %2 = load i8* %1, align 1 - %3 = sitofp i8 %2 to double + %3 = uitofp i8 %2 to double ret double %3 } -; Function Attrs: nounwind uwtable -define weak signext i8 @kotlinclib_charToByte(i8 signext %value) #0 { +; Function Attrs: nounwind +define weak zeroext i8 @kotlinclib_charToByte(i8 zeroext %value) #0 { %1 = alloca i8, align 1 store i8 %value, i8* %1, align 1 %2 = load i8* %1, align 1 ret i8 %2 } -; Function Attrs: nounwind uwtable -define weak signext i16 @kotlinclib_charToShort(i8 signext %value) #0 { +; Function Attrs: nounwind +define weak signext i16 @kotlinclib_charToShort(i8 zeroext %value) #0 { %1 = alloca i8, align 1 store i8 %value, i8* %1, align 1 %2 = load i8* %1, align 1 - %3 = sext i8 %2 to i16 + %3 = zext i8 %2 to i16 ret i16 %3 } -; Function Attrs: nounwind uwtable -define weak i32 @kotlinclib_charToInt(i8 signext %value) #0 { +; Function Attrs: nounwind +define weak i32 @kotlinclib_charToInt(i8 zeroext %value) #0 { %1 = alloca i8, align 1 store i8 %value, i8* %1, align 1 %2 = load i8* %1, align 1 - %3 = sext i8 %2 to i32 + %3 = zext i8 %2 to i32 ret i32 %3 } -; Function Attrs: nounwind uwtable -define weak i64 @kotlinclib_charToLong(i8 signext %value) #0 { +; Function Attrs: nounwind +define weak i32 @kotlinclib_charToLong(i8 zeroext %value) #0 { %1 = alloca i8, align 1 store i8 %value, i8* %1, align 1 %2 = load i8* %1, align 1 - %3 = sext i8 %2 to i64 - ret i64 %3 + %3 = zext i8 %2 to i32 + ret i32 %3 } -; Function Attrs: nounwind uwtable -define weak float @kotlinclib_charToFloat(i8 signext %value) #0 { +; Function Attrs: nounwind +define weak float @kotlinclib_charToFloat(i8 zeroext %value) #0 { %1 = alloca i8, align 1 store i8 %value, i8* %1, align 1 %2 = load i8* %1, align 1 - %3 = sitofp i8 %2 to float + %3 = uitofp i8 %2 to float ret float %3 } -; Function Attrs: nounwind uwtable -define weak double @kotlinclib_charToDouble(i8 signext %value) #0 { +; Function Attrs: nounwind +define weak double @kotlinclib_charToDouble(i8 zeroext %value) #0 { %1 = alloca i8, align 1 store i8 %value, i8* %1, align 1 %2 = load i8* %1, align 1 - %3 = sitofp i8 %2 to double + %3 = uitofp i8 %2 to double ret double %3 } -; Function Attrs: nounwind uwtable -define weak signext i8 @kotlinclib_shortToByte(i16 signext %value) #0 { +; Function Attrs: nounwind +define weak zeroext i8 @kotlinclib_shortToByte(i16 signext %value) #0 { %1 = alloca i16, align 2 store i16 %value, i16* %1, align 2 %2 = load i16* %1, align 2 @@ -172,8 +170,8 @@ define weak signext i8 @kotlinclib_shortToByte(i16 signext %value) #0 { ret i8 %3 } -; Function Attrs: nounwind uwtable -define weak signext i8 @kotlinclib_shortToChar(i16 signext %value) #0 { +; Function Attrs: nounwind +define weak zeroext i8 @kotlinclib_shortToChar(i16 signext %value) #0 { %1 = alloca i16, align 2 store i16 %value, i16* %1, align 2 %2 = load i16* %1, align 2 @@ -181,7 +179,7 @@ define weak signext i8 @kotlinclib_shortToChar(i16 signext %value) #0 { ret i8 %3 } -; Function Attrs: nounwind uwtable +; Function Attrs: nounwind define weak i32 @kotlinclib_shortToInt(i16 signext %value) #0 { %1 = alloca i16, align 2 store i16 %value, i16* %1, align 2 @@ -190,16 +188,16 @@ define weak i32 @kotlinclib_shortToInt(i16 signext %value) #0 { ret i32 %3 } -; Function Attrs: nounwind uwtable -define weak i64 @kotlinclib_shortToLong(i16 signext %value) #0 { +; Function Attrs: nounwind +define weak i32 @kotlinclib_shortToLong(i16 signext %value) #0 { %1 = alloca i16, align 2 store i16 %value, i16* %1, align 2 %2 = load i16* %1, align 2 - %3 = sext i16 %2 to i64 - ret i64 %3 + %3 = sext i16 %2 to i32 + ret i32 %3 } -; Function Attrs: nounwind uwtable +; Function Attrs: nounwind define weak float @kotlinclib_shortToFloat(i16 signext %value) #0 { %1 = alloca i16, align 2 store i16 %value, i16* %1, align 2 @@ -208,7 +206,7 @@ define weak float @kotlinclib_shortToFloat(i16 signext %value) #0 { ret float %3 } -; Function Attrs: nounwind uwtable +; Function Attrs: nounwind define weak double @kotlinclib_shortToDouble(i16 signext %value) #0 { %1 = alloca i16, align 2 store i16 %value, i16* %1, align 2 @@ -217,79 +215,78 @@ define weak double @kotlinclib_shortToDouble(i16 signext %value) #0 { ret double %3 } -; Function Attrs: nounwind uwtable -define weak signext i8 @kotlinclib_longToByte(i64 %value) #0 { - %1 = alloca i64, align 8 - store i64 %value, i64* %1, align 8 - %2 = load i64* %1, align 8 - %3 = trunc i64 %2 to i8 +; Function Attrs: nounwind +define weak zeroext i8 @kotlinclib_longToByte(i32 %value) #0 { + %1 = alloca i32, align 4 + store i32 %value, i32* %1, align 4 + %2 = load i32* %1, align 4 + %3 = trunc i32 %2 to i8 ret i8 %3 } -; Function Attrs: nounwind uwtable -define weak signext i8 @kotlinclib_longToChar(i64 %value) #0 { - %1 = alloca i64, align 8 - store i64 %value, i64* %1, align 8 - %2 = load i64* %1, align 8 - %3 = trunc i64 %2 to i8 +; Function Attrs: nounwind +define weak zeroext i8 @kotlinclib_longToChar(i32 %value) #0 { + %1 = alloca i32, align 4 + store i32 %value, i32* %1, align 4 + %2 = load i32* %1, align 4 + %3 = trunc i32 %2 to i8 ret i8 %3 } -; Function Attrs: nounwind uwtable -define weak signext i16 @kotlinclib_longToShort(i64 %value) #0 { - %1 = alloca i64, align 8 - store i64 %value, i64* %1, align 8 - %2 = load i64* %1, align 8 - %3 = trunc i64 %2 to i16 +; Function Attrs: nounwind +define weak signext i16 @kotlinclib_longToShort(i32 %value) #0 { + %1 = alloca i32, align 4 + store i32 %value, i32* %1, align 4 + %2 = load i32* %1, align 4 + %3 = trunc i32 %2 to i16 ret i16 %3 } -; Function Attrs: nounwind uwtable -define weak i32 @kotlinclib_longToInt(i64 %value) #0 { - %1 = alloca i64, align 8 - store i64 %value, i64* %1, align 8 - %2 = load i64* %1, align 8 - %3 = trunc i64 %2 to i32 - ret i32 %3 +; Function Attrs: nounwind +define weak i32 @kotlinclib_longToInt(i32 %value) #0 { + %1 = alloca i32, align 4 + store i32 %value, i32* %1, align 4 + %2 = load i32* %1, align 4 + ret i32 %2 } -; Function Attrs: nounwind uwtable -define weak float @kotlinclib_longToFloat(i64 %value) #0 { - %1 = alloca i64, align 8 - store i64 %value, i64* %1, align 8 - %2 = load i64* %1, align 8 - %3 = sitofp i64 %2 to float +; Function Attrs: nounwind +define weak float @kotlinclib_longToFloat(i32 %value) #0 { + %1 = alloca i32, align 4 + store i32 %value, i32* %1, align 4 + %2 = load i32* %1, align 4 + %3 = sitofp i32 %2 to float ret float %3 } -; Function Attrs: nounwind uwtable -define weak double @kotlinclib_longToDouble(i64 %value) #0 { - %1 = alloca i64, align 8 - store i64 %value, i64* %1, align 8 - %2 = load i64* %1, align 8 - %3 = sitofp i64 %2 to double +; Function Attrs: nounwind +define weak double @kotlinclib_longToDouble(i32 %value) #0 { + %1 = alloca i32, align 4 + store i32 %value, i32* %1, align 4 + %2 = load i32* %1, align 4 + %3 = sitofp i32 %2 to double ret double %3 } -; Function Attrs: nounwind uwtable -define weak signext i8 @kotlinclib_floatToByte(float %value) #0 { +; Function Attrs: nounwind +define weak zeroext i8 @kotlinclib_floatToByte(float %value) #0 { %1 = alloca float, align 4 store float %value, float* %1, align 4 %2 = load float* %1, align 4 - %3 = fptosi float %2 to i8 + %3 = fptoui float %2 to i8 ret i8 %3 } -; Function Attrs: nounwind uwtable -define weak signext i8 @kotlinclib_floatToChar(float %value) #0 { +; Function Attrs: nounwind +define weak zeroext i8 @kotlinclib_floatToChar(float %value) #0 { %1 = alloca float, align 4 store float %value, float* %1, align 4 %2 = load float* %1, align 4 - %3 = fptosi float %2 to i8 + %3 = fptoui float %2 to i8 ret i8 %3 } -; Function Attrs: nounwind uwtable +; Function Attrs: nounwind define weak signext i16 @kotlinclib_floatToShort(float %value) #0 { %1 = alloca float, align 4 store float %value, float* %1, align 4 @@ -298,7 +295,7 @@ define weak signext i16 @kotlinclib_floatToShort(float %value) #0 { ret i16 %3 } -; Function Attrs: nounwind uwtable +; Function Attrs: nounwind define weak i32 @kotlinclib_floatToInt(float %value) #0 { %1 = alloca float, align 4 store float %value, float* %1, align 4 @@ -307,16 +304,16 @@ define weak i32 @kotlinclib_floatToInt(float %value) #0 { ret i32 %3 } -; Function Attrs: nounwind uwtable -define weak i64 @kotlinclib_floatToLong(float %value) #0 { +; Function Attrs: nounwind +define weak i32 @kotlinclib_floatToLong(float %value) #0 { %1 = alloca float, align 4 store float %value, float* %1, align 4 %2 = load float* %1, align 4 - %3 = fptosi float %2 to i64 - ret i64 %3 + %3 = fptosi float %2 to i32 + ret i32 %3 } -; Function Attrs: nounwind uwtable +; Function Attrs: nounwind define weak double @kotlinclib_floatToDouble(float %value) #0 { %1 = alloca float, align 4 store float %value, float* %1, align 4 @@ -325,25 +322,25 @@ define weak double @kotlinclib_floatToDouble(float %value) #0 { ret double %3 } -; Function Attrs: nounwind uwtable -define weak signext i8 @kotlinclib_doubleToByte(double %value) #0 { +; Function Attrs: nounwind +define weak zeroext i8 @kotlinclib_doubleToByte(double %value) #0 { %1 = alloca double, align 8 store double %value, double* %1, align 8 %2 = load double* %1, align 8 - %3 = fptosi double %2 to i8 + %3 = fptoui double %2 to i8 ret i8 %3 } -; Function Attrs: nounwind uwtable -define weak signext i8 @kotlinclib_doubleToChar(double %value) #0 { +; Function Attrs: nounwind +define weak zeroext i8 @kotlinclib_doubleToChar(double %value) #0 { %1 = alloca double, align 8 store double %value, double* %1, align 8 %2 = load double* %1, align 8 - %3 = fptosi double %2 to i8 + %3 = fptoui double %2 to i8 ret i8 %3 } -; Function Attrs: nounwind uwtable +; Function Attrs: nounwind define weak signext i16 @kotlinclib_doubleToShort(double %value) #0 { %1 = alloca double, align 8 store double %value, double* %1, align 8 @@ -352,7 +349,7 @@ define weak signext i16 @kotlinclib_doubleToShort(double %value) #0 { ret i16 %3 } -; Function Attrs: nounwind uwtable +; Function Attrs: nounwind define weak i32 @kotlinclib_doubleToInt(double %value) #0 { %1 = alloca double, align 8 store double %value, double* %1, align 8 @@ -361,16 +358,16 @@ define weak i32 @kotlinclib_doubleToInt(double %value) #0 { ret i32 %3 } -; Function Attrs: nounwind uwtable -define weak i64 @kotlinclib_doubleToLong(double %value) #0 { +; Function Attrs: nounwind +define weak i32 @kotlinclib_doubleToLong(double %value) #0 { %1 = alloca double, align 8 store double %value, double* %1, align 8 %2 = load double* %1, align 8 - %3 = fptosi double %2 to i64 - ret i64 %3 + %3 = fptosi double %2 to i32 + ret i32 %3 } -; Function Attrs: nounwind uwtable +; Function Attrs: nounwind define weak float @kotlinclib_doubleToFloat(double %value) #0 { %1 = alloca double, align 8 store double %value, double* %1, align 8 @@ -378,3 +375,47 @@ define weak float @kotlinclib_doubleToFloat(double %value) #0 { %3 = fptrunc double %2 to float ret float %3 } + +; Function Attrs: nounwind +define weak i32 @kotlinclib_int_size() #0 { + ret i32 4 +} + +; Function Attrs: nounwind +define weak i32 @kotlinclib_long_size() #0 { + ret i32 4 +} + +; Function Attrs: nounwind +define weak i32 @kotlinclib_boolean_size() #0 { + ret i32 1 +} + +; Function Attrs: nounwind +define weak i32 @kotlinclib_short_size() #0 { + ret i32 2 +} + +; Function Attrs: nounwind +define weak i32 @kotlinclib_double_size() #0 { + ret i32 8 +} + +; Function Attrs: nounwind +define weak i32 @kotlinclib_float_size() #0 { + ret i32 4 +} + +; Function Attrs: nounwind +define weak i32 @kotlinclib_char_size() #0 { + ret i32 1 +} + +attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.module.flags = !{!0, !1} +!llvm.ident = !{!2} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{i32 1, !"min_enum_size", i32 4} +!2 = !{!"Ubuntu clang version 3.6.2-3ubuntu2 (tags/RELEASE_362/final) (based on LLVM 3.6.2)"} diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMDoubleType.kt b/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMDoubleType.kt index c65befa9251..138f0694f31 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMDoubleType.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMDoubleType.kt @@ -18,6 +18,30 @@ class LLVMDoubleType() : LLVMType() { override fun operatorPlus(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = LLVMExpression(LLVMDoubleType(), "fadd double $firstOp, $secondOp") + override fun operatorInc(firstOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMDoubleType(), "fadd double $firstOp, 1.0") + + override fun operatorDec(firstOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMDoubleType(), "fsub double $firstOp, 1.0") + + override fun operatorLt(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMBooleanType(), "fcmp olt double $firstOp, $secondOp") + + override fun operatorGt(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMBooleanType(), "fcmp ogt double $firstOp, $secondOp") + + override fun operatorLeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMBooleanType(), "fcmp ole double i32 $firstOp, $secondOp") + + override fun operatorGeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMBooleanType(), "fcmp oge double i32 $firstOp, $secondOp") + + override fun operatorEq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMBooleanType(), "fcmp oeq double $firstOp, $secondOp") + + override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMBooleanType(), "fcmp one double $firstOp, $secondOp") + override fun equals(other: Any?): Boolean { return other is LLVMDoubleType } diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMFloatType.kt b/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMFloatType.kt index e2bd347f7d9..2756c0cf7f7 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMFloatType.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMFloatType.kt @@ -18,6 +18,30 @@ class LLVMFloatType() : LLVMType() { override fun operatorPlus(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = LLVMExpression(LLVMFloatType(), "fadd float $firstOp, $secondOp") + override fun operatorInc(firstOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMDoubleType(), "fadd float $firstOp, 1.0") + + override fun operatorDec(firstOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMDoubleType(), "fsub float $firstOp, 1.0") + + override fun operatorLt(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMBooleanType(), "fcmp olt float $firstOp, $secondOp") + + override fun operatorGt(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMBooleanType(), "fcmp ogt float $firstOp, $secondOp") + + override fun operatorLeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMBooleanType(), "fcmp ole float i32 $firstOp, $secondOp") + + override fun operatorGeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMBooleanType(), "fcmp oge float i32 $firstOp, $secondOp") + + override fun operatorEq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMBooleanType(), "fcmp oeq float $firstOp, $secondOp") + + override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMBooleanType(), "fcmp one float $firstOp, $secondOp") + override fun equals(other: Any?): Boolean { return other is LLVMFloatType } diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMReferenceType.kt b/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMReferenceType.kt index 429e832bf65..0c87c928319 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMReferenceType.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMReferenceType.kt @@ -28,4 +28,7 @@ class LLVMReferenceType(val type: String, var prefix: String = "", override val override fun operatorEq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = LLVMExpression(LLVMBooleanType(), "icmp eq ${firstOp.getType()} $firstOp, ${if (secondOp.type is LLVMNullType) "null" else "$secondOp"}") + + override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = + LLVMExpression(LLVMBooleanType(), "icmp neq ${firstOp.getType()} $firstOp, ${if (secondOp.type is LLVMNullType) "null" else "$secondOp"}") } \ No newline at end of file diff --git a/translator/src/test/kotlin/tests/input/floating_point_operators_1.txt b/translator/src/test/kotlin/tests/input/floating_point_operators_1.txt new file mode 100644 index 00000000000..af281b291ce --- /dev/null +++ b/translator/src/test/kotlin/tests/input/floating_point_operators_1.txt @@ -0,0 +1,2 @@ +floating_point_operators_1_double_leq_Double_Double(14.9301, 5.6) == 0 +floating_point_operators_1_double_leq_Double_Double(1.49301, 5.6) == 1 diff --git a/translator/src/test/kotlin/tests/kotlin/floating_point_operators_1.kt b/translator/src/test/kotlin/tests/kotlin/floating_point_operators_1.kt new file mode 100644 index 00000000000..951a1fb499b --- /dev/null +++ b/translator/src/test/kotlin/tests/kotlin/floating_point_operators_1.kt @@ -0,0 +1,12 @@ +fun floating_point_operators_1_double_leq(x: Double, y: Double): Int { + if (x < y){ + return 1 + } + else{ + return 0 + } +} + +fun floating_point_operators_1_getValue(b: Boolean): Boolean{ + return b +} \ No newline at end of file