[LLVMdev] "Function" file name
t.p.northover at gmail.com
Thu Jan 30 00:06:57 PST 2014
> I am writing a simple pass that inherits from ModulePass. I override the
> runOnModule method. In the method, i am attempting to print all the function
> in the module and the source-file they appear in. I could print the name of
> the function using the Module::iterator. I am, however, not able to
> figure-out the way to identify the source-file for a given "Function".
That information is generally only present if the file was compiled
with debug info ("clang -g"), and even then I believe it's only
attached to the instructions in a function rather than the function
itself. Inlining can complicate things further, so you need to pick
the *right* instruction (some may come from a different file
Some grubbing around the class hierarchy suggests this procedure:
1. Find a "ret" instruction in the function (actually, a function can
rarely exist with "unreachable" instead of "ret" so be careful).
2. Call Instruction::getDebugLoc on it
3. Call DebugLoc::getAsMDNode to convert it into an MDNode
4. Create a DILocation from that MDNode and query it for your info.
There may be a simpler way, but hopefully that will do the job.
More information about the llvm-dev