Re: Taking an AST back into C

vbdis@aol.com (VBDis)
1 Dec 2004 23:18:28 -0500

          From comp.compilers

Related articles
Taking an AST back into C nb_no_spam@synthcom.com (Neil Bradley) (2004-11-28)
Re: Taking an AST back into C Martin.Ward@durham.ac.uk (Martin Ward) (2004-12-01)
Re: Taking an AST back into C torbenm@diku.dk (2004-12-01)
Re: Taking an AST back into C vbdis@aol.com (2004-12-01)
Re: Taking an AST back into C vbdis@aol.com (2004-12-05)
Re: Taking an AST back into C vbdis@aol.com (2004-12-05)
Re: Taking an AST back into C vbdis@aol.com (2004-12-11)
Re: Taking an AST back into C Martin.Ward@durham.ac.uk (Martin Ward) (2004-12-11)
Re: Taking an AST back into C vbdis@aol.com (2004-12-13)
| List of all articles for this month |

From: vbdis@aol.com (VBDis)
Newsgroups: comp.compilers
Date: 1 Dec 2004 23:18:28 -0500
Organization: AOL Bertelsmann Online GmbH & Co. KG http://www.germany.aol.com
References: 04-11-119
Keywords: decompile
Posted-Date: 01 Dec 2004 23:18:28 EST

"Neil Bradley" <nb_no_spam@synthcom.com> schreibt:


>I'm currently working on a code recompiler that translates binary code
>back into its C equivalent. Fortunately, just about every processor
>instruction can be represented as an expression (computing carry,
>overflow for example).


That's a reasonable approach, for expressions.


>I've created an abstract syntax tree for the binary code and am
>translating it back into C, and now I'm trying to figure out when to
>emit parenthesis in my expressions (so that operator precedence will
>be honored).


Perhaps it's easier to emit parentheses by default, and to determine
when the parentheses can be omitted for sure.


>Does anyone know of a rule or approach that would let me know when
>parentheses should be emitted? As near as I can tell, it's when the
>node on the right tree of the current operator has an operator that
>is of differing precedence, but that just doesn't seem complete
>enough.


The procedures depend on your tree structure. You'll often have
operators in both arguments of an operation.


In my own decompiler I used an tree restructuring pass before trying
to produce syntactically valid C code. The resulting tree then was
arranged and annotated as appropriate for the source code
generation. More passes may be required for control flow analysis, and
for x86 or other CISC machines with their processor specific idioms.


>Any advice/help/hints would be greatly appreciated. Thanks!


Feel free to contact me by e-mail. Decompilers have been my hobby for
decades, and I know about many related problems and possible
solutions.


DoDi


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.