[Wasm] Support packed integer class fields
This commit is contained in:
+16
-3
@@ -77,9 +77,22 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun generateInstanceFieldAccess(field: IrField) {
|
private fun generateInstanceFieldAccess(field: IrField) {
|
||||||
body.buildStructGet(
|
val opcode = when (field.type) {
|
||||||
context.referenceGcType(field.parentAsClass.symbol),
|
irBuiltIns.charType ->
|
||||||
context.getStructFieldRef(field)
|
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))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -194,7 +194,7 @@ class DeclarationGenerator(val context: WasmModuleCodegenContext) : IrElementVis
|
|||||||
fields = declaration.allFields(irBuiltIns).map {
|
fields = declaration.allFields(irBuiltIns).map {
|
||||||
WasmStructFieldDeclaration(
|
WasmStructFieldDeclaration(
|
||||||
name = it.name.toString(),
|
name = it.name.toString(),
|
||||||
type = context.transformType(it.type),
|
type = context.transformFieldType(it.type),
|
||||||
isMutable = true
|
isMutable = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+13
@@ -51,6 +51,19 @@ class WasmTypeTransformer(
|
|||||||
fun IrType.toBoxedInlineClassType(): WasmType =
|
fun IrType.toBoxedInlineClassType(): WasmType =
|
||||||
toWasmGcRefType()
|
toWasmGcRefType()
|
||||||
|
|
||||||
|
fun IrType.toWasmFieldType(): WasmType =
|
||||||
|
when (this) {
|
||||||
|
builtIns.booleanType,
|
||||||
|
builtIns.byteType ->
|
||||||
|
WasmI8
|
||||||
|
|
||||||
|
builtIns.shortType,
|
||||||
|
builtIns.charType ->
|
||||||
|
WasmI16
|
||||||
|
|
||||||
|
else -> toWasmValueType()
|
||||||
|
}
|
||||||
|
|
||||||
fun IrType.toWasmValueType(): WasmType =
|
fun IrType.toWasmValueType(): WasmType =
|
||||||
when (this) {
|
when (this) {
|
||||||
builtIns.booleanType,
|
builtIns.booleanType,
|
||||||
|
|||||||
+2
@@ -34,6 +34,8 @@ interface WasmBaseCodegenContext {
|
|||||||
fun referenceStringLiteral(string: String): WasmSymbol<Int>
|
fun referenceStringLiteral(string: String): WasmSymbol<Int>
|
||||||
|
|
||||||
fun transformType(irType: IrType): WasmType
|
fun transformType(irType: IrType): WasmType
|
||||||
|
fun transformFieldType(irType: IrType): WasmType
|
||||||
|
|
||||||
fun transformBoxedType(irType: IrType): WasmType
|
fun transformBoxedType(irType: IrType): WasmType
|
||||||
fun transformValueParameterType(irValueParameter: IrValueParameter): WasmType
|
fun transformValueParameterType(irValueParameter: IrValueParameter): WasmType
|
||||||
fun transformResultType(irType: IrType): WasmType?
|
fun transformResultType(irType: IrType): WasmType?
|
||||||
|
|||||||
+4
@@ -33,6 +33,10 @@ class WasmModuleCodegenContextImpl(
|
|||||||
return with(typeTransformer) { irType.toWasmValueType() }
|
return with(typeTransformer) { irType.toWasmValueType() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun transformFieldType(irType: IrType): WasmType {
|
||||||
|
return with(typeTransformer) { irType.toWasmFieldType() }
|
||||||
|
}
|
||||||
|
|
||||||
override fun transformBoxedType(irType: IrType): WasmType {
|
override fun transformBoxedType(irType: IrType): WasmType {
|
||||||
return with(typeTransformer) { irType.toBoxedInlineClassType() }
|
return with(typeTransformer) { irType.toBoxedInlineClassType() }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ object WasmF32 : WasmType("f32", -0x3)
|
|||||||
object WasmF64 : WasmType("f64", -0x4)
|
object WasmF64 : WasmType("f64", -0x4)
|
||||||
object WasmV128 : WasmType("v128", -0x5)
|
object WasmV128 : WasmType("v128", -0x5)
|
||||||
object WasmI8 : WasmType("i8", -0x6)
|
object WasmI8 : WasmType("i8", -0x6)
|
||||||
object WasmI16 : WasmType("i8", -0x7)
|
object WasmI16 : WasmType("i16", -0x7)
|
||||||
object WasmFuncRef : WasmType("funcref", -0x10)
|
object WasmFuncRef : WasmType("funcref", -0x10)
|
||||||
object WasmExternRef : WasmType("externref", -0x11)
|
object WasmExternRef : WasmType("externref", -0x11)
|
||||||
object WasmAnyRef : WasmType("anyref", -0x12)
|
object WasmAnyRef : WasmType("anyref", -0x12)
|
||||||
|
|||||||
Reference in New Issue
Block a user