[LLVMdev] [OT] Control Flow Graph(CFG) into Abstract Syntax Tree(AST)

Jianfei Hu hujianfei258 at gmail.com
Fri Oct 12 22:51:35 PDT 2012

Interesting things. I once also wanted to get structural information
from LLVM binary code. And I found it just consisted of connected
basic blocks, CFG, not ast-like tree.

What I am wondering is that, why LLVM does not include some high level
IR, before converting to RISC-like instruction. I think different work
and anlysis should be done on different level. As far as I know,
open64 compiler has several different level IR, called WHIRL.

Could anyone answer this question?

2012/9/13 James Courtier-Dutton <james.dutton at gmail.com>:
> Hi,
> I know most compilers go from AST to CFG.
> I am writing a decompiler, so I was wondering if anyone knew of any
> documents describing how best to get from CFG to AST.
> The decompiler project is open source.
> https://github.com/jcdutton/libbeauty
> The decompiler already contains a disassembler and a virtual machine
> resulting in an annotated CFG. It uses information gained from using a
> virtual machine to annotate the CFG. Another use of the VM will be to
> help analyze self modifying code.
> The decompiler can output C source code form the CFG, but it is not
> easy to understand the result due to lack of structure such as for {}
> loops.
> I wish to create an AST from the CFG in order to be able to output for
> {}, while {}  and if...then...else structure.
> The CFG to AST step seems a little complicated, so I was looking for
> some pointers to how best to do it to save me re-inventing the wheel.
> Kind Regards
> James
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Best Wishes,

Jianfei Hu

More information about the llvm-dev mailing list