[Wasm] Support packed integer class fields

This commit is contained in:
Svyatoslav Kuzmich
2020-12-08 15:53:15 +03:00
parent 28168bf230
commit 51e8d782b0
6 changed files with 37 additions and 5 deletions
@@ -77,9 +77,22 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
}
private fun generateInstanceFieldAccess(field: IrField) {
body.buildStructGet(
context.referenceGcType(field.parentAsClass.symbol),
context.getStructFieldRef(field)
val opcode = when (field.type) {
irBuiltIns.charType ->
WasmOp.STRUCT_GET_U
irBuiltIns.booleanType,
irBuiltIns.byteType,
irBuiltIns.shortType ->
WasmOp.STRUCT_GET_S
else -> WasmOp.STRUCT_GET
}
body.buildInstr(
opcode,
WasmImmediate.GcType(context.referenceGcType(field.parentAsClass.symbol)),
WasmImmediate.StructFieldIdx(context.getStructFieldRef(field))
)
}
@@ -194,7 +194,7 @@ class DeclarationGenerator(val context: WasmModuleCodegenContext) : IrElementVis
fields = declaration.allFields(irBuiltIns).map {
WasmStructFieldDeclaration(
name = it.name.toString(),
type = context.transformType(it.type),
type = context.transformFieldType(it.type),
isMutable = true
)
}
@@ -51,6 +51,19 @@ class WasmTypeTransformer(
fun IrType.toBoxedInlineClassType(): WasmType =
toWasmGcRefType()
fun IrType.toWasmFieldType(): WasmType =
when (this) {
builtIns.booleanType,
builtIns.byteType ->
WasmI8
builtIns.shortType,
builtIns.charType ->
WasmI16
else -> toWasmValueType()
}
fun IrType.toWasmValueType(): WasmType =
when (this) {
builtIns.booleanType,
@@ -34,6 +34,8 @@ interface WasmBaseCodegenContext {
fun referenceStringLiteral(string: String): WasmSymbol<Int>
fun transformType(irType: IrType): WasmType
fun transformFieldType(irType: IrType): WasmType
fun transformBoxedType(irType: IrType): WasmType
fun transformValueParameterType(irValueParameter: IrValueParameter): WasmType
fun transformResultType(irType: IrType): WasmType?
@@ -33,6 +33,10 @@ class WasmModuleCodegenContextImpl(
return with(typeTransformer) { irType.toWasmValueType() }
}
override fun transformFieldType(irType: IrType): WasmType {
return with(typeTransformer) { irType.toWasmFieldType() }
}
override fun transformBoxedType(irType: IrType): WasmType {
return with(typeTransformer) { irType.toBoxedInlineClassType() }
}
@@ -21,7 +21,7 @@ object WasmF32 : WasmType("f32", -0x3)
object WasmF64 : WasmType("f64", -0x4)
object WasmV128 : WasmType("v128", -0x5)
object WasmI8 : WasmType("i8", -0x6)
object WasmI16 : WasmType("i8", -0x7)
object WasmI16 : WasmType("i16", -0x7)
object WasmFuncRef : WasmType("funcref", -0x10)
object WasmExternRef : WasmType("externref", -0x11)
object WasmAnyRef : WasmType("anyref", -0x12)