[WASM] Initial infrastructure

- New module ":compiler:backend.wasm"
    - Initial compiler infra (driver, phaser, context)
    - Subset of Wasm AST
    - Skeleton of IR -> Wasm AST
    - Wasm AST -> WAT transformer

- Testing infra

- SpiderMonkey jsshell tool
This commit is contained in:
Svyatoslav Kuzmich
2019-08-07 14:27:18 +03:00
parent 812083ee05
commit 6e6ffa12a6
106 changed files with 6418 additions and 584 deletions
-12
View File
@@ -1,12 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin
import kotlin.annotation.AnnotationTarget.*
// Exclude declaration or file from lowerings and code generation
@Target(FILE, CLASS, FUNCTION, PROPERTY)
internal annotation class ExcludedFromCodegen
@@ -13,6 +13,9 @@
package kotlin
import kotlin.wasm.internal.WasmInstruction
import kotlin.wasm.internal.wasm_i32_compareTo
/**
* Represents a value which is either `true` or `false`. On the JVM, non-nullable values of this type are
* represented as values of the primitive type `boolean`.
@@ -21,26 +24,34 @@ public class Boolean private constructor() : Comparable<Boolean> {
/**
* Returns the inverse of this boolean.
*/
@WasmInstruction(WasmInstruction.I32_EQZ)
public operator fun not(): Boolean
/**
* Performs a logical `and` operation between this Boolean and the [other] one. Unlike the `&&` operator,
* this function does not perform short-circuit evaluation. Both `this` and [other] will always be evaluated.
*/
@WasmInstruction(WasmInstruction.I32_AND)
public infix fun and(other: Boolean): Boolean
/**
* Performs a logical `or` operation between this Boolean and the [other] one. Unlike the `||` operator,
* this function does not perform short-circuit evaluation. Both `this` and [other] will always be evaluated.
*/
@WasmInstruction(WasmInstruction.I32_OR)
public infix fun or(other: Boolean): Boolean
/**
* Performs a logical `xor` operation between this Boolean and the [other] one.
*/
@WasmInstruction(WasmInstruction.I32_XOR)
public infix fun xor(other: Boolean): Boolean
public override fun compareTo(other: Boolean): Int
public override fun compareTo(other: Boolean): Int =
wasm_i32_compareTo(this.asInt(), other.asInt())
@WasmInstruction(WasmInstruction.NOP)
internal fun asInt(): Int
@SinceKotlin("1.3")
companion object {}
@@ -3,16 +3,15 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress(
"NON_ABSTRACT_FUNCTION_WITH_NO_BODY",
"MUST_BE_INITIALIZED_OR_BE_ABSTRACT",
"EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE",
"PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED",
"WRONG_MODIFIER_TARGET"
)
@file:Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE")
package kotlin
import kotlin.wasm.internal.ExcludedFromCodegen
import kotlin.wasm.internal.WasmInstruction
import kotlin.wasm.internal.implementedAsIntrinsic
import kotlin.wasm.internal.wasm_i32_compareTo
/**
* Represents a 16-bit Unicode character.
*
@@ -25,39 +24,56 @@ public class Char private constructor() : Comparable<Char> {
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public override fun compareTo(other: Char): Int
public override inline fun compareTo(other: Char): Int =
wasm_i32_compareTo(this.toInt(), other.toInt())
/** Adds the other Int value to this value resulting a Char. */
public operator fun plus(other: Int): Char
public inline operator fun plus(other: Int): Char =
(this.toInt() + other).toChar()
/** Subtracts the other Char value from this value resulting an Int. */
public operator fun minus(other: Char): Int
public inline operator fun minus(other: Char): Int =
(this.toInt() - other.toInt())
/** Subtracts the other Int value from this value resulting a Char. */
public operator fun minus(other: Int): Char
public inline operator fun minus(other: Int): Char =
(this.toInt() - other).toChar()
/** Increments this value. */
public operator fun inc(): Char
public inline operator fun inc(): Char =
(this.toInt() + 1).toChar()
/** Decrements this value. */
public operator fun dec(): Char
public inline operator fun dec(): Char =
(this.toInt() - 1).toChar()
// /** Creates a range from this value to the specified [other] value. */
// public operator fun rangeTo(other: Char): CharRange
/** Returns the value of this character as a `Byte`. */
public fun toByte(): Byte
public inline fun toByte(): Byte =
this.toInt().toByte()
/** Returns the value of this character as a `Char`. */
public fun toChar(): Char
public inline fun toChar(): Char =
this
/** Returns the value of this character as a `Short`. */
public fun toShort(): Short
public inline fun toShort(): Short =
this.toInt().toShort()
/** Returns the value of this character as a `Int`. */
public fun toInt(): Int
@WasmInstruction(WasmInstruction.NOP)
public fun toInt(): Int =
implementedAsIntrinsic
/** Returns the value of this character as a `Long`. */
public fun toLong(): Long
public inline fun toLong(): Long =
this.toInt().toLong()
/** Returns the value of this character as a `Float`. */
public fun toFloat(): Float
public inline fun toFloat(): Float =
this.toInt().toFloat()
/** Returns the value of this character as a `Double`. */
public fun toDouble(): Double
public inline fun toDouble(): Double =
this.toInt().toDouble()
@ExcludedFromCodegen
companion object {
/**
* The minimum value of a character code unit.
@@ -6,7 +6,7 @@
"NON_MEMBER_FUNCTION_NO_BODY",
"REIFIED_TYPE_PARAMETER_NO_INLINE"
)
@file:ExcludedFromCodegen
@file:kotlin.wasm.internal.ExcludedFromCodegen
package kotlin
File diff suppressed because it is too large Load Diff
@@ -13,19 +13,25 @@
package kotlin
import kotlin.wasm.internal.ExcludedFromCodegen
import kotlin.wasm.internal.WasmImport
/**
* The `String` class represents character strings. All string literals in Kotlin programs, such as `"abc"`, are
* implemented as instances of this class.
*/
public class String : Comparable<String>, CharSequence {
@ExcludedFromCodegen
companion object {}
/**
* Returns a string obtained by concatenating this string with the string representation of the given [other] object.
*/
@WasmImport("runtime", "String_plus")
public operator fun plus(other: Any?): String
public override val length: Int
@WasmImport("runtime", "String_getLength") get
/**
* Returns the character of this string at the specified [index].
@@ -33,9 +39,20 @@ public class String : Comparable<String>, CharSequence {
* If the [index] is out of bounds of this string, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@WasmImport("runtime", "String_getChar")
public override fun get(index: Int): Char
@ExcludedFromCodegen
public override fun subSequence(startIndex: Int, endIndex: Int): CharSequence
@WasmImport("runtime", "String_compareTo")
public override fun compareTo(other: String): Int
}
@ExcludedFromCodegen
public override fun equals(other: Any?): Boolean
public override fun toString(): String = this
@ExcludedFromCodegen
public override fun hashCode(): Int
}
@@ -0,0 +1,397 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:ExcludedFromCodegen
@file:Suppress("NON_ABSTRACT_FUNCTION_WITH_NO_BODY", "unused")
package kotlin.wasm.internal
@WasmInstruction(WasmInstruction.UNREACHABLE)
external fun wasm_unreachable(): Nothing
@WasmInstruction(WasmInstruction.I32_EQZ)
external fun wasm_i32_eqz(a: Int): Int
@WasmInstruction(WasmInstruction.I32_EQ)
external fun wasm_i32_eq(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_NE)
external fun wasm_i32_ne(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_LT_S)
external fun wasm_i32_lt_s(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_LT_U)
external fun wasm_i32_lt_u(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_GT_S)
external fun wasm_i32_gt_s(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_GT_U)
external fun wasm_i32_gt_u(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_LE_S)
external fun wasm_i32_le_s(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_LE_U)
external fun wasm_i32_le_u(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_GE_S)
external fun wasm_i32_ge_s(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_GE_U)
external fun wasm_i32_ge_u(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I64_EQZ)
external fun wasm_i64_eqz(a: Long): Int
@WasmInstruction(WasmInstruction.I64_EQ)
external fun wasm_i64_eq(a: Long, b: Long): Int
@WasmInstruction(WasmInstruction.I64_NE)
external fun wasm_i64_ne(a: Long, b: Long): Int
@WasmInstruction(WasmInstruction.I64_LT_S)
external fun wasm_i64_lt_s(a: Long, b: Long): Int
@WasmInstruction(WasmInstruction.I64_LT_U)
external fun wasm_i64_lt_u(a: Long, b: Long): Int
@WasmInstruction(WasmInstruction.I64_GT_S)
external fun wasm_i64_gt_s(a: Long, b: Long): Int
@WasmInstruction(WasmInstruction.I64_GT_U)
external fun wasm_i64_gt_u(a: Long, b: Long): Int
@WasmInstruction(WasmInstruction.I64_LE_S)
external fun wasm_i64_le_s(a: Long, b: Long): Int
@WasmInstruction(WasmInstruction.I64_LE_U)
external fun wasm_i64_le_u(a: Long, b: Long): Int
@WasmInstruction(WasmInstruction.I64_GE_S)
external fun wasm_i64_ge_s(a: Long, b: Long): Int
@WasmInstruction(WasmInstruction.I64_GE_U)
external fun wasm_i64_ge_u(a: Long, b: Long): Int
@WasmInstruction(WasmInstruction.F32_EQ)
external fun wasm_f32_eq(a: Float, b: Float): Int
@WasmInstruction(WasmInstruction.F32_NE)
external fun wasm_f32_ne(a: Float, b: Float): Int
@WasmInstruction(WasmInstruction.F32_LT)
external fun wasm_f32_lt(a: Float, b: Float): Int
@WasmInstruction(WasmInstruction.F32_GT)
external fun wasm_f32_gt(a: Float, b: Float): Int
@WasmInstruction(WasmInstruction.F32_LE)
external fun wasm_f32_le(a: Float, b: Float): Int
@WasmInstruction(WasmInstruction.F32_GE)
external fun wasm_f32_ge(a: Float, b: Float): Int
@WasmInstruction(WasmInstruction.F64_EQ)
external fun wasm_f64_eq(a: Double, b: Double): Int
@WasmInstruction(WasmInstruction.F64_NE)
external fun wasm_f64_ne(a: Double, b: Double): Int
@WasmInstruction(WasmInstruction.F64_LT)
external fun wasm_f64_lt(a: Double, b: Double): Int
@WasmInstruction(WasmInstruction.F64_GT)
external fun wasm_f64_gt(a: Double, b: Double): Int
@WasmInstruction(WasmInstruction.F64_LE)
external fun wasm_f64_le(a: Double, b: Double): Int
@WasmInstruction(WasmInstruction.F64_GE)
external fun wasm_f64_ge(a: Double, b: Double): Int
@WasmInstruction(WasmInstruction.I32_CLZ)
external fun wasm_i32_clz(a: Int): Int
@WasmInstruction(WasmInstruction.I32_CTZ)
external fun wasm_i32_ctz(a: Int): Int
@WasmInstruction(WasmInstruction.I32_POPCNT)
external fun wasm_i32_popcnt(a: Int): Int
@WasmInstruction(WasmInstruction.I32_ADD)
external fun wasm_i32_add(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_SUB)
external fun wasm_i32_sub(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_MUL)
external fun wasm_i32_mul(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_DIV_S)
external fun wasm_i32_div_s(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_DIV_U)
external fun wasm_i32_div_u(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_REM_S)
external fun wasm_i32_rem_s(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_REM_U)
external fun wasm_i32_rem_u(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_AND)
external fun wasm_i32_and(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_OR)
external fun wasm_i32_or(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_XOR)
external fun wasm_i32_xor(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_SHL)
external fun wasm_i32_shl(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_SHR_S)
external fun wasm_i32_shr_s(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_SHR_U)
external fun wasm_i32_shr_u(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_ROTL)
external fun wasm_i32_rotl(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I32_ROTR)
external fun wasm_i32_rotr(a: Int, b: Int): Int
@WasmInstruction(WasmInstruction.I64_CLZ)
external fun wasm_i64_clz(a: Long): Long
@WasmInstruction(WasmInstruction.I64_CTZ)
external fun wasm_i64_ctz(a: Long): Long
@WasmInstruction(WasmInstruction.I64_POPCNT)
external fun wasm_i64_popcnt(a: Long): Long
@WasmInstruction(WasmInstruction.I64_ADD)
external fun wasm_i64_add(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.I64_SUB)
external fun wasm_i64_sub(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.I64_MUL)
external fun wasm_i64_mul(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.I64_DIV_S)
external fun wasm_i64_div_s(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.I64_DIV_U)
external fun wasm_i64_div_u(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.I64_REM_S)
external fun wasm_i64_rem_s(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.I64_REM_U)
external fun wasm_i64_rem_u(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.I64_AND)
external fun wasm_i64_and(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.I64_OR)
external fun wasm_i64_or(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.I64_XOR)
external fun wasm_i64_xor(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.I64_SHL)
external fun wasm_i64_shl(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.I64_SHR_S)
external fun wasm_i64_shr_s(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.I64_SHR_U)
external fun wasm_i64_shr_u(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.I64_ROTL)
external fun wasm_i64_rotl(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.I64_ROTR)
external fun wasm_i64_rotr(a: Long, b: Long): Long
@WasmInstruction(WasmInstruction.F32_ABS)
external fun wasm_f32_abs(a: Float): Float
@WasmInstruction(WasmInstruction.F32_NEG)
external fun wasm_f32_neg(a: Float): Float
@WasmInstruction(WasmInstruction.F32_CEIL)
external fun wasm_f32_ceil(a: Float): Float
@WasmInstruction(WasmInstruction.F32_FLOOR)
external fun wasm_f32_floor(a: Float): Float
@WasmInstruction(WasmInstruction.F32_TRUNC)
external fun wasm_f32_trunc(a: Float): Float
@WasmInstruction(WasmInstruction.F32_NEAREST)
external fun wasm_f32_nearest(a: Float): Float
@WasmInstruction(WasmInstruction.F32_SQRT)
external fun wasm_f32_sqrt(a: Float): Float
@WasmInstruction(WasmInstruction.F32_ADD)
external fun wasm_f32_add(a: Float, b: Float): Float
@WasmInstruction(WasmInstruction.F32_SUB)
external fun wasm_f32_sub(a: Float, b: Float): Float
@WasmInstruction(WasmInstruction.F32_MUL)
external fun wasm_f32_mul(a: Float, b: Float): Float
@WasmInstruction(WasmInstruction.F32_DIV)
external fun wasm_f32_div(a: Float, b: Float): Float
@WasmInstruction(WasmInstruction.F32_FMIN)
external fun wasm_f32_fmin(a: Float, b: Float): Float
@WasmInstruction(WasmInstruction.F32_FMAX)
external fun wasm_f32_fmax(a: Float, b: Float): Float
@WasmInstruction(WasmInstruction.F32_COPYSIGN)
external fun wasm_f32_copysign(a: Float, b: Float): Float
@WasmInstruction(WasmInstruction.F64_ABS)
external fun wasm_f64_abs(a: Double): Double
@WasmInstruction(WasmInstruction.F64_NEG)
external fun wasm_f64_neg(a: Double): Double
@WasmInstruction(WasmInstruction.F64_CEIL)
external fun wasm_f64_ceil(a: Double): Double
@WasmInstruction(WasmInstruction.F64_FLOOR)
external fun wasm_f64_floor(a: Double): Double
@WasmInstruction(WasmInstruction.F64_TRUNC)
external fun wasm_f64_trunc(a: Double): Double
@WasmInstruction(WasmInstruction.F64_NEAREST)
external fun wasm_f64_nearest(a: Double): Double
@WasmInstruction(WasmInstruction.F64_SQRT)
external fun wasm_f64_sqrt(a: Double): Double
@WasmInstruction(WasmInstruction.F64_ADD)
external fun wasm_f64_add(a: Double, b: Double): Double
@WasmInstruction(WasmInstruction.F64_SUB)
external fun wasm_f64_sub(a: Double, b: Double): Double
@WasmInstruction(WasmInstruction.F64_MUL)
external fun wasm_f64_mul(a: Double, b: Double): Double
@WasmInstruction(WasmInstruction.F64_DIV)
external fun wasm_f64_div(a: Double, b: Double): Double
@WasmInstruction(WasmInstruction.F64_FMIN)
external fun wasm_f64_fmin(a: Double, b: Double): Double
@WasmInstruction(WasmInstruction.F64_FMAX)
external fun wasm_f64_fmax(a: Double, b: Double): Double
@WasmInstruction(WasmInstruction.F64_COPYSIGN)
external fun wasm_f64_copysign(a: Double, b: Double): Double
@WasmInstruction(WasmInstruction.I32_WRAP_I64)
external fun wasm_i32_wrap_i64(a: Long): Int
@WasmInstruction(WasmInstruction.I32_TRUNC_F32_S)
external fun wasm_i32_trunc_f32_s(a: Float): Int
@WasmInstruction(WasmInstruction.I32_TRUNC_F32_U)
external fun wasm_i32_trunc_f32_u(a: Float): Int
@WasmInstruction(WasmInstruction.I32_TRUNC_F64_S)
external fun wasm_i32_trunc_f64_s(a: Double): Int
@WasmInstruction(WasmInstruction.I32_TRUNC_F64_U)
external fun wasm_i32_trunc_f64_u(a: Double): Int
@WasmInstruction(WasmInstruction.I64_EXTEND_I32_S)
external fun wasm_i64_extend_i32_s(a: Int): Long
@WasmInstruction(WasmInstruction.I64_EXTEND_I32_U)
external fun wasm_i64_extend_i32_u(a: Int): Long
@WasmInstruction(WasmInstruction.I64_TRUNC_F32_S)
external fun wasm_i64_trunc_f32_s(a: Float): Long
@WasmInstruction(WasmInstruction.I64_TRUNC_F32_U)
external fun wasm_i64_trunc_f32_u(a: Float): Long
@WasmInstruction(WasmInstruction.I64_TRUNC_F64_S)
external fun wasm_i64_trunc_f64_s(a: Double): Long
@WasmInstruction(WasmInstruction.I64_TRUNC_F64_U)
external fun wasm_i64_trunc_f64_u(a: Double): Long
@WasmInstruction(WasmInstruction.F32_CONVERT_I32_S)
external fun wasm_f32_convert_i32_s(a: Int): Float
@WasmInstruction(WasmInstruction.F32_CONVERT_I32_U)
external fun wasm_f32_convert_i32_u(a: Int): Float
@WasmInstruction(WasmInstruction.F32_CONVERT_I64_S)
external fun wasm_f32_convert_i64_s(a: Long): Float
@WasmInstruction(WasmInstruction.F32_CONVERT_I64_U)
external fun wasm_f32_convert_i64_u(a: Long): Float
@WasmInstruction(WasmInstruction.F32_DEMOTE_F64)
external fun wasm_f32_demote_f64(a: Double): Float
@WasmInstruction(WasmInstruction.F64_CONVERT_I32_S)
external fun wasm_f64_convert_i32_s(a: Int): Double
@WasmInstruction(WasmInstruction.F64_CONVERT_I32_U)
external fun wasm_f64_convert_i32_u(a: Int): Double
@WasmInstruction(WasmInstruction.F64_CONVERT_I64_S)
external fun wasm_f64_convert_i64_s(a: Long): Double
@WasmInstruction(WasmInstruction.F64_CONVERT_I64_U)
external fun wasm_f64_convert_i64_u(a: Long): Double
@WasmInstruction(WasmInstruction.F64_PROMOTE_F32)
external fun wasm_f64_promote_f32(a: Float): Double
@WasmInstruction(WasmInstruction.I32_REINTERPRET_F32)
external fun wasm_i32_reinterpret_f32(a: Float): Int
@WasmInstruction(WasmInstruction.I64_REINTERPRET_F64)
external fun wasm_i64_reinterpret_f64(a: Double): Long
@WasmInstruction(WasmInstruction.F32_REINTERPRET_I32)
external fun wasm_f32_reinterpret_i32(a: Int): Float
@WasmInstruction(WasmInstruction.F32_CONST_NAN)
external fun wasm_f32_const_nan(): Float
@WasmInstruction(WasmInstruction.F32_CONST_PLUS_INF)
external fun wasm_f32_const_plus_inf(): Float
@WasmInstruction(WasmInstruction.F32_CONST_MINUS_INF)
external fun wasm_f32_const_minus_inf(): Float
@WasmInstruction(WasmInstruction.F64_CONST_NAN)
external fun wasm_f64_const_nan(): Double
@WasmInstruction(WasmInstruction.F64_CONST_PLUS_INF)
external fun wasm_f64_const_plus_inf(): Float
@WasmInstruction(WasmInstruction.F64_CONST_MINUS_INF)
external fun wasm_f64_const_minus_inf(): Float
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.wasm.internal
// `compareTo(x, y)` implemented as `(x >= y) - (x <= y)`
fun wasm_i32_compareTo(x: Int, y: Int): Int =
wasm_i32_ge_s(x, y) - wasm_i32_le_s(x, y)
fun wasm_i64_compareTo(x: Long, y: Long): Int =
wasm_i64_ge_s(x, y) - wasm_i64_le_s(x, y)
fun wasm_f32_compareTo(x: Float, y: Float): Int =
wasm_f32_ge(x, y) - wasm_f32_le(x, y)
fun wasm_f64_compareTo(x: Double, y: Double): Int =
wasm_f64_ge(x, y) - wasm_f64_le(x, y)
+45
View File
@@ -0,0 +1,45 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
const runtime = {
/**
* kotlin.String#plus(other: Any?): String
* @return {string}
*/
String_plus(str1, str2) {
if (typeof str1 != "string") throw `Illegal argument str1: ${str1}`;
return str1 + String(str2);
},
/**
* @return {number}
*/
String_getLength(str) {
if (typeof str != "string") throw `Illegal argument x: ${str}`;
return str.length;
},
/**
* @return {number}
*/
String_getChar(str, index) {
if (typeof str != "string") throw `Illegal argument str: ${str}`;
if (typeof index != "number") throw `Illegal argument index: ${index}`;
return str.charCodeAt(index);
},
/**
* @return {number}
*/
String_compareTo(str1, str2) {
if (str1 > str2) return 1;
if (str1 < str2) return -1;
return 0;
},
String_getLiteral(index) {
return runtime.stringLiterals[index];
}
};
+10
View File
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.wasm.internal
@WasmImport("runtime", "String_getLiteral")
public fun stringLiteral(index: Int): String =
implementedAsIntrinsic
+1 -1
View File
@@ -1,4 +1,4 @@
@file:ExcludedFromCodegen
@file:kotlin.wasm.internal.ExcludedFromCodegen
package kotlin.ranges
+59
View File
@@ -0,0 +1,59 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin
import kotlin.wasm.internal.wasm_unreachable
fun assertEquals(x: Boolean, y: Boolean) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Byte, y: Byte) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Short, y: Short) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Char, y: Char) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Int, y: Int) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Long, y: Long) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Float, y: Float) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Double, y: Double) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Boolean, y: Boolean, s: String) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Byte, y: Byte, s: String) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Short, y: Short, s: String) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Char, y: Char, s: String) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Int, y: Int, s: String) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Long, y: Long, s: String) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Float, y: Float, s: String) {
if (x != y) wasm_unreachable()
}
fun assertEquals(x: Double, y: Double, s: String) {
if (x != y) wasm_unreachable()
}
+173
View File
@@ -0,0 +1,173 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.wasm.internal
import kotlin.annotation.AnnotationTarget.*
// Exclude declaration or file from lowerings and code generation
@Target(FILE, CLASS, FUNCTION, PROPERTY)
@Retention(AnnotationRetention.BINARY)
internal annotation class ExcludedFromCodegen
@ExcludedFromCodegen
@Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER)
@Retention(AnnotationRetention.BINARY)
internal annotation class WasmImport(val module: String, val name: String)
/**
* Replace calls to this functions with specified Wasm instruction.
*
* Operands are passed in the following order:
* 1. Dispatch receiver (if present)
* 2. Extension receiver (if present)
* 3. Value arguments
*
* @mnemonic parameter is an instruction WAT name: "i32.add", "f64.trunc", etc.
*
* Immediate arguments (label, index, offest, align, etc.) are not supported yet.
*/
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.BINARY)
@ExcludedFromCodegen
internal annotation class WasmInstruction(val mnemonic: String) {
companion object {
const val NOP = "nop"
const val UNREACHABLE = "unreachable"
const val I32_EQZ = "i32.eqz"
const val I32_EQ = "i32.eq"
const val I32_NE = "i32.ne"
const val I32_LT_S = "i32.lt_s"
const val I32_LT_U = "i32.lt_u"
const val I32_GT_S = "i32.gt_s"
const val I32_GT_U = "i32.gt_u"
const val I32_LE_S = "i32.le_s"
const val I32_LE_U = "i32.le_u"
const val I32_GE_S = "i32.ge_s"
const val I32_GE_U = "i32.ge_u"
const val I64_EQZ = "i64.eqz"
const val I64_EQ = "i64.eq"
const val I64_NE = "i64.ne"
const val I64_LT_S = "i64.lt_s"
const val I64_LT_U = "i64.lt_u"
const val I64_GT_S = "i64.gt_s"
const val I64_GT_U = "i64.gt_u"
const val I64_LE_S = "i64.le_s"
const val I64_LE_U = "i64.le_u"
const val I64_GE_S = "i64.ge_s"
const val I64_GE_U = "i64.ge_u"
const val F32_EQ = "f32.eq"
const val F32_NE = "f32.ne"
const val F32_LT = "f32.lt"
const val F32_GT = "f32.gt"
const val F32_LE = "f32.le"
const val F32_GE = "f32.ge"
const val F64_EQ = "f64.eq"
const val F64_NE = "f64.ne"
const val F64_LT = "f64.lt"
const val F64_GT = "f64.gt"
const val F64_LE = "f64.le"
const val F64_GE = "f64.ge"
const val I32_CLZ = "i32.clz"
const val I32_CTZ = "i32.ctz"
const val I32_POPCNT = "i32.popcnt"
const val I32_ADD = "i32.add"
const val I32_SUB = "i32.sub"
const val I32_MUL = "i32.mul"
const val I32_DIV_S = "i32.div_s"
const val I32_DIV_U = "i32.div_u"
const val I32_REM_S = "i32.rem_s"
const val I32_REM_U = "i32.rem_u"
const val I32_AND = "i32.and"
const val I32_OR = "i32.or"
const val I32_XOR = "i32.xor"
const val I32_SHL = "i32.shl"
const val I32_SHR_S = "i32.shr_s"
const val I32_SHR_U = "i32.shr_u"
const val I32_ROTL = "i32.rotl"
const val I32_ROTR = "i32.rotr"
const val I64_CLZ = "i64.clz"
const val I64_CTZ = "i64.ctz"
const val I64_POPCNT = "i64.popcnt"
const val I64_ADD = "i64.add"
const val I64_SUB = "i64.sub"
const val I64_MUL = "i64.mul"
const val I64_DIV_S = "i64.div_s"
const val I64_DIV_U = "i64.div_u"
const val I64_REM_S = "i64.rem_s"
const val I64_REM_U = "i64.rem_u"
const val I64_AND = "i64.and"
const val I64_OR = "i64.or"
const val I64_XOR = "i64.xor"
const val I64_SHL = "i64.shl"
const val I64_SHR_S = "i64.shr_s"
const val I64_SHR_U = "i64.shr_u"
const val I64_ROTL = "i64.rotl"
const val I64_ROTR = "i64.rotr"
const val F32_ABS = "f32.abs"
const val F32_NEG = "f32.neg"
const val F32_CEIL = "f32.ceil"
const val F32_FLOOR = "f32.floor"
const val F32_TRUNC = "f32.trunc"
const val F32_NEAREST = "f32.nearest"
const val F32_SQRT = "f32.sqrt"
const val F32_ADD = "f32.add"
const val F32_SUB = "f32.sub"
const val F32_MUL = "f32.mul"
const val F32_DIV = "f32.div"
const val F32_FMIN = "f32.fmin"
const val F32_FMAX = "f32.fmax"
const val F32_COPYSIGN = "f32.copysign"
const val F64_ABS = "f64.abs"
const val F64_NEG = "f64.neg"
const val F64_CEIL = "f64.ceil"
const val F64_FLOOR = "f64.floor"
const val F64_TRUNC = "f64.trunc"
const val F64_NEAREST = "f64.nearest"
const val F64_SQRT = "f64.sqrt"
const val F64_ADD = "f64.add"
const val F64_SUB = "f64.sub"
const val F64_MUL = "f64.mul"
const val F64_DIV = "f64.div"
const val F64_FMIN = "f64.fmin"
const val F64_FMAX = "f64.fmax"
const val F64_COPYSIGN = "f64.copysign"
const val I32_WRAP_I64 = "i32.wrap/i64"
const val I32_TRUNC_F32_S = "i32.trunc_s/f32"
const val I32_TRUNC_F32_U = "i32.trunc_u/f32"
const val I32_TRUNC_F64_S = "i32.trunc_s/f64"
const val I32_TRUNC_F64_U = "i32.trunc_u/f64"
const val I64_EXTEND_I32_S = "i64.extend_s/i32"
const val I64_EXTEND_I32_U = "i64.extend_u/i32"
const val I64_TRUNC_F32_S = "i64.trunc_s/f32"
const val I64_TRUNC_F32_U = "i64.trunc_u/f32"
const val I64_TRUNC_F64_S = "i64.trunc_s/f64"
const val I64_TRUNC_F64_U = "i64.trunc_u/f64"
const val F32_CONVERT_I32_S = "f32.convert_s/i32"
const val F32_CONVERT_I32_U = "f32.convert_u/i32"
const val F32_CONVERT_I64_S = "f32.convert_s/i64"
const val F32_CONVERT_I64_U = "f32.convert_u/i64"
const val F64_CONVERT_I32_S = "f64.convert_s/i32"
const val F64_CONVERT_I32_U = "f64.convert_u/i32"
const val F64_CONVERT_I64_S = "f64.convert_s/i64"
const val F64_CONVERT_I64_U = "f64.convert_u/i64"
const val F32_DEMOTE_F64 = "f32.demote/f64"
const val F64_PROMOTE_F32 = "f64.promote/f32"
const val I32_REINTERPRET_F32 = "i32.reinterpret/f32"
const val I64_REINTERPRET_F64 = "i64.reinterpret/f64"
const val F32_REINTERPRET_I32 = "f32.reinterpret/i32"
const val F32_CONST_NAN = "f32.const nan"
const val F64_CONST_NAN = "f64.const nan"
const val F32_CONST_PLUS_INF = "f32.const +inf"
const val F32_CONST_MINUS_INF = "f32.const -inf"
const val F64_CONST_PLUS_INF = "f64.const +inf"
const val F64_CONST_MINUS_INF = "f64.const -inf"
}
}
@ExcludedFromCodegen
internal val implementedAsIntrinsic: Nothing
get() = null!!