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

Steven Bosscher stevenb.gcc@gmail.com
Sun Sep 23 15:54:00 GMT 2012


James Courtier-Dutton wrote:
> 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.

You want structural analysis.

Attached is an example implementation based on algorithms in an
unfortunately never-published book. It's not in a state where it'll
work out-of-the-box with the current GCC mainline code base, but it
gives you something to look at and see if this is what you need.

There is also http://gcc.gnu.org/ml/gcc-patches/2003-06/msg01656.html
but it's based on the early prints of Steve Muchnick's book, and the
section about structural analysis (section 7.7) was completely
rewritten for the third printing.

I've been working on a re-implementation of Honza's version with
modern GCC paradigma and using ideas from Kenny's work, but I
currently have no time table in mind for if/when to contribute it,
because there's no immediate practical use for the code at the moment.

Ciao!
Steven
-------------- next part --------------
A non-text attachment was scrubbed...
Name: zadeck_structure_analysis.diff
Type: application/octet-stream
Size: 144298 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20120923/56182045/attachment.obj>


More information about the Gcc mailing list