<br><br>
<div class="gmail_quote">2010/11/5 Eli Friedman <span dir="ltr"><<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>></span><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>
<div></div>
<div class="h5">On Thu, Nov 4, 2010 at 10:22 PM, Neng Chen <<a href="http://cnisme.cn/" target="_blank">cnisme.cn</a>@<a href="http://gmail.com/" target="_blank">gmail.com</a>> wrote:<br>> I wonder if there is any method to get the source code of a program with<br>
> LLVM pass in the bytecode file(*.ibc), Recently I have written an LLVM Pass<br>> to iterate through functions, basic blocks and instructions<br>><br>><br>> for (Module::iterator F = M.begin(), ME = M.end(); F != ME; ++F) {<br>
><br>>     for (Function::iterator B = F->begin(), FE = F->end(); B != FE; ++B) {<br>><br>>         for (BasicBlock::iterator I = B->begin(), BE = B->end(); I != BE;<br>> I++) {<br>><br>>              //code<br>
>              //how can I get the source code here<br>><br>>         }<br>>     }<br>> }<br>><br>><br>> if we can get the source code, and how to get ?<br><br></div></div>Debug metadata is really your only option at that point in the<br>
pipeline.  See <a href="http://llvm.org/docs/SourceLevelDebugging.html" target="_blank">http://llvm.org/docs/SourceLevelDebugging.html</a> .  For<br>access to the AST, you need to write an ASTConsumer, not an LLVM pass;<br>
look in clang/examples for some guidance for how to do that (clang<br>documentation is still relatively immature).<br><font color="#888888"><br>-Eli<br></font></blockquote></div>
<div><br>Thank you very much for your help.</div>
<div>You means I must use Clang's API, such as ASTConsumer, to get the source code from the AST, do I get your method?</div>
<div>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?</div>