[Wasm] Support packed integer array elements
This commit is contained in:
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.wasm.ir.WasmOp
|
||||
import templates.COMMON_AUTOGENERATED_WARNING
|
||||
import templates.COPYRIGHT_NOTICE
|
||||
import templates.PrimitiveType
|
||||
import templates.isUnsigned
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
|
||||
@@ -56,20 +57,41 @@ fun generateWasmArrays(targetDir: File) {
|
||||
writer.generateStandardWasmInternalHeader()
|
||||
|
||||
writer.appendLine(wasmArrayForType("Any", true))
|
||||
writer.appendLine(wasmArrayForType("Boolean", false))
|
||||
PrimitiveType.numericPrimitives.sortedBy { it.capacity }.forEach { primitive ->
|
||||
writer.appendLine(wasmArrayForType(primitive.name, false))
|
||||
PrimitiveType.descendingByDomainCapacity.reversed().forEach { primitive ->
|
||||
val isPacked = primitive in setOf(
|
||||
PrimitiveType.Byte,
|
||||
PrimitiveType.Short,
|
||||
PrimitiveType.Char,
|
||||
)
|
||||
val isUnsigned = primitive.isUnsigned() || primitive == PrimitiveType.Char
|
||||
|
||||
writer.appendLine(
|
||||
wasmArrayForType(
|
||||
primitive.name,
|
||||
false, isPacked, isUnsigned
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun wasmArrayForType(klass: String, isNullable: Boolean): String {
|
||||
fun wasmArrayForType(
|
||||
klass: String,
|
||||
isNullable: Boolean,
|
||||
isPacked: Boolean = false,
|
||||
isUnsigned: Boolean = false,
|
||||
): String {
|
||||
val type = klass + if (isNullable) "?" else ""
|
||||
val name = "Wasm${klass}Array"
|
||||
val getSuffix = when {
|
||||
isPacked && isUnsigned -> "_U"
|
||||
isPacked && !isUnsigned -> "_S"
|
||||
else -> ""
|
||||
}
|
||||
return """
|
||||
@WasmArrayOf($klass::class, isNullable = $isNullable)
|
||||
internal class $name(size: Int) {
|
||||
@WasmOp(WasmOp.ARRAY_GET)
|
||||
@WasmOp(WasmOp.ARRAY_GET${getSuffix})
|
||||
fun get(index: Int): $type =
|
||||
implementedAsIntrinsic
|
||||
|
||||
|
||||
Reference in New Issue
Block a user