Support plugin-defined instrinsics that can be non-typeOf operation types.

This commit is contained in:
Leonid Startsev
2022-09-13 15:08:54 +02:00
committed by Space
parent 033538161e
commit 69c00785f2
5 changed files with 89 additions and 37 deletions
@@ -181,28 +181,29 @@ class SerializationJvmIrIntrinsicSupport(val jvmBackendContext: JvmBackendContex
* 4: swap // if withModule
* 5: invokestatic(kotlinx.serialization.serializer(module?, kType)
*
* We need to remove instructions from 1 to 5
* Instructions 0, -1 -2 and -3 would be removed by inliner.
* We need to remove instructions from 0 to 5
* Instructions -1, -2 and -3 would be removed by inliner.
*/
override fun rewritePluginDefinedOperationMarker(
v: InstructionAdapter,
stubConstNull: AbstractInsnNode,
reifiedInsn: AbstractInsnNode,
instructions: InsnList,
type: IrType
): Boolean {
val operationTypeStr = (stubConstNull.next as LdcInsnNode).cst as String
val operationTypeStr = (reifiedInsn.next as LdcInsnNode).cst as String
if (!operationTypeStr.startsWith(magicMarkerStringPrefix)) return false
val operationType = if (operationTypeStr.endsWith("withModule")) {
val aload = stubConstNull.next.next.next as VarInsnNode
val aload = reifiedInsn.next.next.next as VarInsnNode
val storedVar = aload.`var`
instructions.remove(aload.next)
instructions.remove(aload)
IntrinsicType.WithModule(storedVar)
} else IntrinsicType.Simple
// Remove other instructions
instructions.remove(stubConstNull.next.next.next)
instructions.remove(stubConstNull.next.next)
instructions.remove(stubConstNull.next)
instructions.remove(reifiedInsn.next.next.next)
instructions.remove(reifiedInsn.next.next)
instructions.remove(reifiedInsn.next)
instructions.remove(reifiedInsn)
// generate serializer
generateSerializerForType(type, v, operationType)
return true