Hello!
This looks like a bit strange question, but still. What if I’m interested to write backend which will generate just an original .ll
program as it was read by llc?
Right now I’m thinking about extending a ModulePass. Is this direction correct?
Any comments?
PS. Some code modifications will be done when printing actually, so, I can not just read file and put it to output.
Why a backend and llc? Why not use opt instead?
I was just scrolling the docs and decided that ModulePass looks similar to what I want.
What is opt?
opt is a tool that takes LLVM-IR (.bc or .ll), runs passes on it, e.g., -O2, and then spits out LLVM-IR.
There is a documentation page and everything. Worth looking into.
found it, already looking on it, thank you!
I’m completely newbie. So, please, excuse me if I miss something.
As far as I can see, opt is a usefull optimization tool. So, I’m able to pass some options to it (i.e. -O3 ) and it will print optimized code as result. But I will not be able to change code.
I actually need analyze and change the original code. But I need keeping results as close to original source code as it is only possible. So, I think the best way is to start with printing original program as it is.
Then, just as an example, I would like to add ‘;;’ to the end of each function definition.
So, I think i’m again about to start with ModulePass.
opt can run your custom module pass if you want.
Without running a transformation, opt will spit out the original input.
You can now add things to it, modify it, analyze it, etc. as you want.
Adding comments (“;” in .ll files) is trickier. I would not rely on comments but you can even do that by providing printer hooks. Rather than comments, I would add attributes, e.g., string function attributes. Those are persistent and can be easily added, checked, removed, etc.
Yes! Thanks
! I think opt is exactly the “infrastructure” which I need. Great, I will take a look on printer hooks then.