https://kotlinlang.org logo
#compiler
Title
# compiler
j

Justin Tullgren

10/05/2023, 6:26 PM
Hi, looking for help to perform ir manipulation that results in “around” advice, in a function body.
Copy code
fun() {
  statement()
  statement()
}

to

fun() {
  begin()
  statement()
  statement()
  end()
}
I can’t tell if I need to modify the IrBody or the IrFunction call…
j

Javier

10/05/2023, 6:48 PM
you need to modify the body based on the code you shared
j

Justin Tullgren

10/05/2023, 6:49 PM
so thats visitBody or do it at the visitSimpleFunction call? thats where I am struggling
IE return a new body in visitBody with my added statements or return the IrFunction with a modified body and don’t visit them
j

Javier

10/05/2023, 6:50 PM
I don’t know, I use a Tree with all the file children so I can filter to find any function by name for example. I haven’t used all visitor APIs
j

Justin Tullgren

10/05/2023, 6:51 PM
ok i’ll keep messing around
j

Javier

10/05/2023, 6:52 PM
if you already have the function, you can get the body and modify the statements by adding those two elements in the positions you want as
statements
is a mutable list
j

Justin Tullgren

10/05/2023, 6:53 PM
ya thats what I am doing now. okay thanks!
j

Javier

10/05/2023, 6:54 PM