Hi! I've been poking around `IrGenerationExtension...
# compiler
s
Hi! I've been poking around
IrGenerationExtension
, and am trying to add a function to annotated classes that just prints "Hello World". I got stuck figuring out how to find the
println
descriptor or symbol to build the function call through
IrCallImpl
. Does anyone know where I could find an example, or another way I could go about this? Thanks!
r
Not sure if relevant but you may find some of these functions that go from descriptors to IR useful https://github.com/47deg/arrow-meta-prototype/blob/rr-idea-improvements/compiler-plugin/src/main/kotlin/arrow/meta/ir/IrUtils.kt
That is if you can get a hold of any descriptor by name you can get the Ir with one of those function or similar way. Maybe there is a better way but this is what I came up reading the compiler sources
s
Thanks for sending that, Raul. definitely helps as a reference for getting the call. 😄 Do you know how to get a descriptor by name?
r
I think you may be able to get a hold of it via a ClassId or something like:
Copy code
module.getPackageByName("<http://kotlin.io|kotlin.io>").getContributedDescriptors(name, filter)
👍 1
or something like that if I recall, sorry not near the sources now
also you can always type it in a string use the KtPsiFactory to parse it then feed it to the analysis to get an AnalysisResult and ask it in the binding trace for the resulting descriptor
But that implies you are attempting to do half of the compilation manually and I’m sure if what you want is just get
println
as a descriptor there is some other way to do that.
There is also a slice in the Binding Context that is called FQNAME_TO_CLASS_DESCRIPTOR but I’m not sure if it holds references to external symbols or just the local ones in the module being compiled
s
That seems to do it. Thanks, @raulraja!
👍 1
d
What seems do do it? I happen to be doing the exact same thing, of trying to look up
IrFunctionSymbol
based on a some name.
Nvm, I found some other way.
a
Is there some kind of repo for this? I am trying to do this "Hello World" thing as well