[WASM] Renew to Milestone 6 instructions set

This commit is contained in:
Igor Yakovlev
2022-08-18 14:55:26 +02:00
committed by teamcity
parent 780fdd44b3
commit c94a051c19
11 changed files with 22 additions and 45 deletions
@@ -414,7 +414,7 @@ class BodyGenerator(
body.buildBlock("isInterface", WasmRefNullType(WasmHeapType.Simple.Data)) { innerLabel ->
body.buildGetLocal(parameterLocal)
body.buildStructGet(context.referenceGcType(irBuiltIns.anyClass), WasmSymbol(1))
body.buildBrInstr(WasmOp.BR_ON_CAST_STATIC_FAIL, innerLabel, classITable)
body.buildBrInstr(WasmOp.BR_ON_CAST_FAIL, innerLabel, classITable)
body.buildStructGet(classITable, context.referenceClassITableInterfaceSlot(irInterface.symbol))
body.buildInstr(WasmOp.REF_IS_NULL)
body.buildInstr(WasmOp.I32_EQZ)
@@ -96,7 +96,7 @@ class WasmTypeTransformer(
val ic = context.backendContext.inlineClassesUtils.getInlinedClass(this)
if (klass.isExternal) {
WasmAnyRef
WasmExternRef
} else if (isBuiltInWasmRefType(this)) {
when (val name = klass.name.identifier) {
"anyref" -> WasmAnyRef
@@ -92,17 +92,15 @@ private external fun setExternrefBox(ref: ExternalInterfaceType, box: JsExternal
@WasmNoOpCast
@Suppress("unused")
internal fun Any?.asWasmAnyref(): anyref =
private fun Any?.asWasmAnyref(): anyref =
implementedAsIntrinsic
@WasmNoOpCast
@Suppress("unused")
internal fun ExternalInterfaceType.externAsWasmAnyref(): anyref =
@WasmOp(WasmOp.EXTERN_INTERNALIZE)
private fun ExternalInterfaceType.externAsWasmAnyref(): anyref =
implementedAsIntrinsic
@WasmNoOpCast
@Suppress("unused")
internal fun Any?.asWasmExternRef(): ExternalInterfaceType =
@WasmOp(WasmOp.EXTERN_EXTERNALIZE)
private fun Any?.asWasmExternRef(): ExternalInterfaceType =
implementedAsIntrinsic
@JsFun("(ref) => ref == null")
@@ -374,18 +374,12 @@ public external fun wasm_i64_ctz(a: Long): Long
// Reference type operators
@WasmOp(WasmOp.REF_IS_FUNC)
internal external fun wasm_ref_is_func(x: anyref): Boolean
@WasmOp(WasmOp.REF_IS_DATA)
internal external fun wasm_ref_is_data(x: anyref): Boolean
@WasmOp(WasmOp.REF_IS_I31)
internal external fun wasm_ref_is_i31(x: anyref): Boolean
@WasmOp(WasmOp.REF_AS_FUNC)
internal external fun wasm_ref_as_func(x: anyref): funcref
@WasmOp(WasmOp.REF_AS_DATA)
internal external fun wasm_ref_as_data(x: anyref): dataref
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -256,21 +256,19 @@ internal annotation class WasmOp(val name: String) {
const val I31_NEW = "I31_NEW"
const val I31_GET_S = "I31_GET_S"
const val I31_GET_U = "I31_GET_U"
const val REF_TEST_STATIC = "REF_TEST_STATIC"
const val REF_CAST_STATIC = "REF_CAST_STATIC"
const val BR_ON_CAST_STATIC_FAIL = "BR_ON_CAST_STATIC_FAIL"
const val REF_IS_FUNC = "REF_IS_FUNC"
const val REF_TEST = "REF_TEST"
const val REF_CAST = "REF_CAST"
const val BR_ON_CAST_FAIL = "BR_ON_CAST_FAIL"
const val REF_IS_DATA = "REF_IS_DATA"
const val REF_IS_I31 = "REF_IS_I31"
const val REF_AS_FUNC = "REF_AS_FUNC"
const val REF_AS_DATA = "REF_AS_DATA"
const val REF_AS_I31 = "REF_AS_I31"
const val BR_ON_FUNC = "BR_ON_FUNC"
const val BR_ON_DATA = "BR_ON_DATA"
const val BR_ON_I31 = "BR_ON_I31"
const val BR_ON_NON_FUNC = "BR_ON_NON_FUNC"
const val BR_ON_NON_DATA = "BR_ON_NON_DATA"
const val BR_ON_NON_I31 = "BR_ON_NON_I31"
const val EXTERN_INTERNALIZE = "EXTERN_INTERNALIZE"
const val EXTERN_EXTERNALIZE = "EXTERN_EXTERNALIZE"
const val GET_UNIT = "GET_UNIT"
}
}
@@ -360,26 +360,25 @@ enum class WasmOp(
I31_GET_S("i31.get_s", 0xFB_21),
I31_GET_U("i31.get_u", 0xFB_22),
REF_TEST_STATIC("ref.test_static", 0xFB_44, STRUCT_TYPE_IDX),
REF_CAST_STATIC("ref.cast_static", 0xFB_45, STRUCT_TYPE_IDX),
REF_TEST("ref.test", 0xFB_44, STRUCT_TYPE_IDX),
REF_CAST("ref.cast", 0xFB_45, STRUCT_TYPE_IDX),
BR_ON_CAST_STATIC_FAIL("br_on_cast_static_fail", 0xfb47, listOf(LABEL_IDX, STRUCT_TYPE_IDX)),
BR_ON_CAST_FAIL("br_on_cast_fail", 0xfb47, listOf(LABEL_IDX, STRUCT_TYPE_IDX)),
REF_IS_FUNC("ref.is_func", 0xfb50),
REF_IS_DATA("ref.is_data", 0xfb51),
REF_IS_I31("ref.is_i31", 0xfb52),
REF_AS_FUNC("ref.as_func", 0xfb58),
REF_AS_DATA("ref.as_data", 0xfb59),
REF_AS_I31("ref.as_i31", 0xfb5a),
BR_ON_FUNC("br_on_func", 0xfb60, listOf(LABEL_IDX)),
BR_ON_DATA("br_on_data", 0xfb61, listOf(LABEL_IDX)),
BR_ON_I31("br_on_i31", 0xfb62, listOf(LABEL_IDX)),
BR_ON_NON_FUNC("br_on_non_func", 0xfb63, listOf(LABEL_IDX)),
BR_ON_NON_DATA("br_on_non_data", 0xfb64, listOf(LABEL_IDX)),
BR_ON_NON_I31("br_on_non_i31", 0xfb65, listOf(LABEL_IDX)),
EXTERN_INTERNALIZE("extern.internalize", 0xfb70), // externref -> anyref
EXTERN_EXTERNALIZE("extern.externalize", 0xfb71), // anyref -> externref
// Pseudo-instruction, just alias for a normal call. It's used to easily spot get_unit on the wasm level.
GET_UNIT("call", 0x10, FUNC_IDX)
;
@@ -31,7 +31,6 @@ data class WasmRefType(val heapType: WasmHeapType) : WasmType("ref", -0x15)
@Suppress("unused")
object WasmI31Ref : WasmType("i31ref", -0x16)
data class WasmRtt(val type: WasmSymbolReadOnly<WasmTypeDeclaration>) : WasmType("rtt", -0x18)
@Suppress("unused")
object WasmDataRef : WasmType("dataref", -0x19)
@@ -49,9 +48,6 @@ sealed class WasmHeapType {
object Any : Simple("any", -0x12)
object Eq : Simple("eq", -0x13)
@Suppress("unused")
object ExnH : Simple("exn", -0x18)
object Data : Simple("data", -0x19)
override fun toString(): String {
@@ -157,11 +157,11 @@ abstract class WasmExpressionBuilder {
}
fun buildRefCastStatic(toType: WasmSymbolReadOnly<WasmTypeDeclaration>) {
buildInstr(WasmOp.REF_CAST_STATIC, WasmImmediate.TypeIdx(toType))
buildInstr(WasmOp.REF_CAST, WasmImmediate.TypeIdx(toType))
}
fun buildRefTestStatic(toType: WasmSymbolReadOnly<WasmTypeDeclaration>) {
buildInstr(WasmOp.REF_TEST_STATIC, WasmImmediate.TypeIdx(toType))
buildInstr(WasmOp.REF_TEST, WasmImmediate.TypeIdx(toType))
}
fun buildRefNull(type: WasmHeapType) {
@@ -491,9 +491,6 @@ class WasmIrToBinary(outputStream: OutputStream, val module: WasmModule, val mod
if (type is WasmRefNullType) {
appendHeapType(type.heapType)
}
if (type is WasmRtt) {
appendModuleFieldReference(type.type.owner)
}
}
fun appendLocalReference(local: WasmLocal) {
@@ -470,11 +470,6 @@ class WasmIrToText : SExpressionBuilder() {
appendHeapType(type.heapType)
}
is WasmRtt ->
sameLineList("rtt") {
appendModuleFieldReference(type.type.owner)
}
WasmUnreachableType -> {
}