Hello! I am looking to make a compiler plugin to analyse Kotlin code as a control flow graph. I am aiming to analyse Android code in specific.
Since there exist a specification for constructing a CFG and analysing for smart casting, I am guessing Kotlin compiler plugin should also be able to construct a CFG and a builder for it should already be available somewhere.
Currently I have managed to get a simple compiler plugin to work with a pre-K2 guide, meaning I am using IR. I found multiple implementations of CFG available but these don't seem to work with IR and I am not sure how to even use or build these implementations.
Just so it is clear, I do not need to transform code, I only need to analyse it and throw errors and warnings.
Should I look into using FIR instead? What is the suggested way of constructing a CFG and where can I find more documentation about it?
contract (easy one)
• FirPropertyInitializationAnalyzer checks property initialization (hard one)
If you setup compiler test framework for your plugin, you will be able to generate dumps of CFG in graphviz format out of box (test and corresponding graph as an example)
kodee happy 1
dmitriy.novozhilov
02/19/2024, 6:58 AM
You can use this repository of an example of setup project for compiler plugin and compiler test framework for it
kodee happy 1
o
Oliver
02/19/2024, 8:32 AM
Thank you very much! I will check this out kodee electrified