[Wasm] Generate stdlib WasmOp based on WasmOp from Wasm IR

This commit is contained in:
Svyatoslav Kuzmich
2020-12-05 16:45:02 +03:00
parent 1cfb81455c
commit 6063353b64
5 changed files with 340 additions and 295 deletions
@@ -71,6 +71,8 @@ fun main(args: Array<String>) {
}
targetDir.resolve("_${source.name.capitalize()}$platformSuffix.kt")
}
targetBaseDirs[KotlinTarget.WASM]?.let { generateWasmOps(it) }
}
fun File.resolveExistingDir(subpath: String) = resolve(subpath).also { it.requireExistingDir() }
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2020 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 generators
import org.jetbrains.kotlin.wasm.ir.WasmOp
import templates.COMMON_AUTOGENERATED_WARNING
import templates.COPYRIGHT_NOTICE
import java.io.File
import java.io.FileWriter
fun generateWasmOps(targetDir: File) {
FileWriter(targetDir.resolve("_WasmOp.kt")).use { writer ->
writer.appendLine(COPYRIGHT_NOTICE)
writer.appendLine("package kotlin.wasm.internal")
writer.appendLine()
writer.appendLine(COMMON_AUTOGENERATED_WARNING)
writer.appendLine()
writer.appendLine(
"""
@ExcludedFromCodegen
@Suppress("unused")
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.BINARY)
internal annotation class WasmOp(val name: String) {
companion object {
""".trimIndent()
)
WasmOp.values().forEach { op ->
writer.appendLine(" const val $op = \"$op\"")
}
writer.appendLine(
"""
}
}
""".trimIndent()
)
}
}