[cfe-dev] get source code with LLVM pass

Neng Chen cnisme.cn at gmail.com
Thu Nov 4 23:19:41 PDT 2010


2010/11/5 Eli Friedman <eli.friedman at gmail.com>

>  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
>

Thank you very much for your help.
You means I must use Clang's API, such as ASTConsumer, to get the source
code from the AST, do I get your method?
But, I hope just use LLVM Pass to get some source code, no means all source
code. For example, I just want to get how many and where "while"
expressions appear in the program. and maybe I also like to get some
variables' values. I use llvm-gcc and llvm on Ubuntu 9.10,  have not
installed clang. so, does LLVM Pass work?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101105/95b0d23a/attachment.html>


More information about the cfe-dev mailing list