[cfe-dev] LLVM- AST contents display and dependency analysis

Reid Kleckner rnk at google.com
Wed May 13 09:53:01 PDT 2015


LLVM's IR is not the same thing as Clang's AST. Do you want the AST, which
has all the tree-structure and scopes of the original source program, or do
you want LLVM IR, which is basic block soup? Alternatively, if you want to
keep source level information you can try to use the static analysis CFG,
which is layered on top of the Clang AST.

If you want the AST, you want to use libTooling or libclang to
programmatically examine the AST. The -ast-dump flag will print the AST for
debugging purposes, but it cannot be deserialized.

If you want a low-level view of the program, use 'clang -emit-llvm -S' to
get LLVM IR instead of -ast-dump. This will be usable with other LLVM tools
like opt.

On Wed, May 13, 2015 at 3:30 AM, yaduveer singh <yaduveer99 at gmail.com>
wrote:

> Hi All,
>
> I tried seeing the AST contents in by using following command:
>
> clang -Xclang -ast-dump -fsyntax-only loop.c
>
> This is giving me some AST output( I believe so) but I am having two issue:
>
> 1. I am not able to put this output in a file as Its showing following
> error:
>
> yaduveer at yaduveer-Inspiron-3542:~/RP$ clang -Xclang -ast-dump
> -fsyntax-only loop1d.c | llvm-dis -o ast.txt
> llvm-dis: Invalid bitcode signature
> clang: error: unable to execute command: Broken pipe
> clang: error: clang frontend command failed due to signal (use -v to see
> invocation)
> clang version 3.6.0 (trunk 225627) (llvm/trunk 225626)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> clang: note: diagnostic msg: PLEASE submit a bug report to
> http://llvm.org/bugs/ and include the crash backtrace, preprocessed
> source, and associated run script.
> clang: note: diagnostic msg:
> ********************
>
> PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
> Preprocessed source(s) and associated run script(s) are located at:
> clang: note: diagnostic msg: /tmp/loop1d-71cd19.c
> clang: note: diagnostic msg: /tmp/loop1d-71cd19.sh
> clang: note: diagnostic msg:
>
> ********************
>
> Could someone please advise me on following queries:
>
> a) Is there some way so that I can get dependency analysis of AST and
>  Basic Blocks.
> b) How can I modify an existing pass by writing a new Pass just like
>  "Hello" pass but the dependencies involved in that pass must not show
> error like "redeclaration".
>
> Regards,
> Yaduveer
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150513/0185fe19/attachment.html>


More information about the cfe-dev mailing list