[Wasm] Generate stdlib WasmOp based on WasmOp from Wasm IR
This commit is contained in:
@@ -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()
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user