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

Joshua Cranmer pidgeot18 at gmail.com
Sun Sep 16 15:12:48 PDT 2012


On 9/13/2012 5:58 AM, James Courtier-Dutton wrote:
> 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 general process that you are trying to do is known as "structuring 
control flow graphs." The basic algorithm, as far as I know it, amounts 
to three steps (in C terms):
1. Make switch statements
2. Make loops
3. Figure out the if/else stuff

Google finds this article: 
<http://ieeexplore.ieee.org/xpl/login.jsp?tp=&arnumber=914984> for a 
more detailed algorithm.

-- 
Joshua Cranmer
News submodule owner
DXR coauthor




More information about the llvm-dev mailing list