[Wasm] Major compiler and stdlib update
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("jps-compatible")
|
||||
kotlin("plugin.serialization") version "1.4.10"
|
||||
kotlin("plugin.serialization")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -53,7 +53,7 @@ sealed class WasmFunction(
|
||||
}
|
||||
|
||||
class WasmMemory(
|
||||
val limits: WasmLimits = WasmLimits(1u, null),
|
||||
val limits: WasmLimits,
|
||||
val importPair: WasmImportPair? = null,
|
||||
) : WasmNamedModuleField()
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ sealed class WasmType(
|
||||
override fun toString(): String = name
|
||||
}
|
||||
|
||||
// TODO: Remove this type.
|
||||
object WasmUnreachableType : WasmType("unreachable", -0x40)
|
||||
object WasmI32 : WasmType("i32", -0x1)
|
||||
object WasmI1 : WasmType("i32", -0x1)
|
||||
@@ -26,7 +27,7 @@ object WasmExternRef : WasmType("externref", -0x11)
|
||||
object WasmAnyRef : WasmType("anyref", -0x12)
|
||||
object WasmEqRef : WasmType("eqref", -0x13)
|
||||
|
||||
class WasmRefNullType(val heapType: WasmHeapType) : WasmType("optref", -0x14)
|
||||
class WasmRefNullType(val heapType: WasmHeapType) : WasmType("ref null", -0x14)
|
||||
class WasmRefType(val heapType: WasmHeapType) : WasmType("ref", -0x15)
|
||||
|
||||
@Suppress("unused")
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.wasm.ir
|
||||
|
||||
interface WasmExpressionBuilder {
|
||||
fun buildInstr(op: WasmOp, vararg immediates: WasmImmediate)
|
||||
var numberOfNestedBlocks: Int
|
||||
abstract class WasmExpressionBuilder {
|
||||
abstract fun buildInstr(op: WasmOp, vararg immediates: WasmImmediate)
|
||||
abstract var numberOfNestedBlocks: Int
|
||||
|
||||
fun buildConstI32(value: Int) {
|
||||
buildInstr(WasmOp.I32_CONST, WasmImmediate.ConstI32(value))
|
||||
@@ -118,7 +118,7 @@ interface WasmExpressionBuilder {
|
||||
}
|
||||
|
||||
|
||||
fun buildStructNarrow(fromType: WasmType, toType: WasmType) {
|
||||
fun buildRefCast(fromType: WasmType, toType: WasmType) {
|
||||
buildInstr(
|
||||
WasmOp.REF_CAST,
|
||||
WasmImmediate.HeapType(fromType.getHeapType()),
|
||||
|
||||
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.wasm.ir
|
||||
|
||||
class WasmIrExpressionBuilder(
|
||||
val expression: MutableList<WasmInstr>
|
||||
) : WasmExpressionBuilder {
|
||||
) : WasmExpressionBuilder() {
|
||||
|
||||
override fun buildInstr(op: WasmOp, vararg immediates: WasmImmediate) {
|
||||
expression.add(WasmInstr(op, immediates.toList()))
|
||||
|
||||
+3
-1
@@ -328,7 +328,9 @@ class WasmBinaryToIR(val b: MyByteReader) {
|
||||
elements = elements,
|
||||
data = data,
|
||||
dataCount = dataCount
|
||||
)
|
||||
).also {
|
||||
it.calculateIds()
|
||||
}
|
||||
}
|
||||
|
||||
private fun readLimits(): WasmLimits {
|
||||
+1
-1
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.wasm.ir.*
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
class WasmBinaryBuilder(outputStream: OutputStream, val module: WasmModule) {
|
||||
class WasmIrToBinary(outputStream: OutputStream, val module: WasmModule) {
|
||||
var b: ByteWriter = ByteWriter.OutputStream(outputStream)
|
||||
|
||||
fun appendWasmModule() {
|
||||
+1
-1
@@ -45,7 +45,7 @@ open class SExpressionBuilder {
|
||||
}
|
||||
|
||||
|
||||
class WatBuilder : SExpressionBuilder() {
|
||||
class WasmIrToText : SExpressionBuilder() {
|
||||
fun appendOffset(value: UInt) {
|
||||
if (value != 0u)
|
||||
appendElement("offset=$value")
|
||||
@@ -11,9 +11,9 @@ import kotlinx.serialization.json.Json
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils.assertEqualsToFile
|
||||
import org.jetbrains.kotlin.utils.fileUtils.withReplacedExtensionOrNull
|
||||
import org.jetbrains.kotlin.wasm.ir.convertors.MyByteReader
|
||||
import org.jetbrains.kotlin.wasm.ir.convertors.WasmBinaryBuilder
|
||||
import org.jetbrains.kotlin.wasm.ir.convertors.WasmIrToBinary
|
||||
import org.jetbrains.kotlin.wasm.ir.convertors.WasmBinaryToIR
|
||||
import org.jetbrains.kotlin.wasm.ir.convertors.WatBuilder
|
||||
import org.jetbrains.kotlin.wasm.ir.convertors.WasmIrToText
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
|
||||
@@ -135,24 +135,6 @@ private fun runSpecTest(specTest: SpecTest, testDir: File, wastFile: File, wabtO
|
||||
val wasmFile = File(testDir, command.filename)
|
||||
testWasmFile(wasmFile, testDir.name)
|
||||
}
|
||||
is SpecTest.Command.Register -> {
|
||||
}
|
||||
is SpecTest.Command.AssertReturn -> {
|
||||
}
|
||||
is SpecTest.Command.AssertTrap -> {
|
||||
}
|
||||
is SpecTest.Command.AssertExhaustion -> {
|
||||
}
|
||||
is SpecTest.Command.AssertMalformed -> {
|
||||
}
|
||||
is SpecTest.Command.AssertInvalid -> {
|
||||
}
|
||||
is SpecTest.Command.AssertUnlinkable -> {
|
||||
}
|
||||
is SpecTest.Command.AssertUninstantiable -> {
|
||||
}
|
||||
is SpecTest.Command.ActionCommand -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,7 +203,6 @@ fun testWasmFile(wasmFile: File, dirName: String) {
|
||||
|
||||
println("Testing wasm file : ${wasmFile.absolutePath} ... ")
|
||||
val module = fileToWasmModule(wasmFile)
|
||||
module.calculateIds()
|
||||
val kotlinTextFormat = module.toTextFormat()
|
||||
val kotlinBinaryFormat = module.toBinaryFormat()
|
||||
|
||||
@@ -248,12 +229,12 @@ fun testWasmFile(wasmFile: File, dirName: String) {
|
||||
|
||||
fun WasmModule.toBinaryFormat(): ByteArray {
|
||||
val os = ByteArrayOutputStream()
|
||||
WasmBinaryBuilder(os, this).appendWasmModule()
|
||||
WasmIrToBinary(os, this).appendWasmModule()
|
||||
return os.toByteArray()
|
||||
}
|
||||
|
||||
fun WasmModule.toTextFormat(): String {
|
||||
val builder = WatBuilder()
|
||||
val builder = WasmIrToText()
|
||||
builder.appendWasmModule(this)
|
||||
return builder.toString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user