[cfe-dev] get source code with LLVM pass

Eli Friedman eli.friedman at gmail.com
Thu Nov 4 22:57:08 PDT 2010


On Thu, Nov 4, 2010 at 10:22 PM, Neng Chen <cnisme.cn at gmail.com> wrote:
> 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++) {
>
>              //code
>              //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 http://llvm.org/docs/SourceLevelDebugging.html .  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).

-Eli




More information about the cfe-dev mailing list