get source code with LLVM pass

I wonder if there is any method to get the source code of a program with LLVM pass in the bytecode file(*.ibc), Recently I have written an LLVM Pass to iterate through functions, basic blocks and instructions

for (Module::iterator F = M.begin(), ME = M.end(); F != ME; ++F) {

for (Function::iterator B = F->begin(), FE = F->end(); B != FE; ++B) {

for (BasicBlock::iterator I = B->begin(), BE = B->end(); I != BE; I++) {

//how can I get the source code here


if we can get the source code, and how to get ?

Debug metadata is really your only option at that point in the
pipeline. See . For
access to the AST, you need to write an ASTConsumer, not an LLVM pass;
look in clang/examples for some guidance for how to do that (clang
documentation is still relatively immature).


2010/11/5 Eli Friedman <>

You can't use an LLVM pass to access that sort of information; you
need access to the proper clang AST. Again, see examples/ in the
clang source tree for how to do that.