https://kotlinlang.org logo
d

Drew Hamilton

03/08/2020, 11:48 AM
I’m trying to brute force my way through writing a compiler plugin (JVM only for now), but I’m stuck now because I can’t find an
InstructionAdapter.ireturn()
function. How do I write the JVM
IRETURN
(integer return) bytecode into my generated code?
r

raulraja

03/08/2020, 11:59 AM
As you are using the
transform
api to mutate the IR tree you may intercept any expression and replace it with another such as an IrReturnImpl org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
d

Drew Hamilton

03/08/2020, 1:22 PM
I’m looking for the JVM
IRETURN
bytecode—not IrReturn or anything else with the IR tree! Editing original comment to clarify.
r

raulraja

03/08/2020, 1:36 PM
sorry, thought you meant IR
IR is coming to Kotlin and I’m not sure what the compiler plans is for those JVM only codegen apis.
d

Drew Hamilton

03/08/2020, 1:41 PM
no problem, appreciate you trying to help. i may refer back to these links if i’m forced to redo this for IR in 6 months 😂
👍 1
To anyone stopping by, the solution was to call
instructionAdapter.areturn(Type.INT_TYPE)
s

shikasd

03/09/2020, 11:53 AM
Yeah, most of us plugin writers are forced to write both "old" bytecode codegen and "new" IR for now. A good example of such a plugin is
kotlinx-serialization
, I highly recommend you to take a look if you haven't already 🙂
2 Views