Re: Taking an AST back into C

Martin Ward <Martin.Ward@durham.ac.uk>
1 Dec 2004 23:02:24 -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)
[1 later articles]
| List of all articles for this month |

From: Martin Ward <Martin.Ward@durham.ac.uk>
Newsgroups: comp.compilers
Date: 1 Dec 2004 23:02:24 -0500
Organization: Compilers Central
References: 04-11-119
Keywords: disassemble, comment
Posted-Date: 01 Dec 2004 23:02:24 EST

> [There's been a lot of work on decompilers over the years, including
> one I tried that disassembled x86 object code and turned it into C.
> It worked, but the results were so low-level that they were useless.
> -John]


FermaT has been sucessfully used to translate 544,000 lines of x86
assembler (an embedded system) into efficient and maintainable C code.
The totally automated technique is to translate the assembler into
WSL, apply several thousand WSL to WSL transformations (per module),
and then translate the restructured and simplified WSL into C. See
the paper "Pigs from Sausages? Reengineering from Assembler to C via
FermaT Transformations" at
http://www.cse.dmu.ac.uk/~mward/martin/papers/


Sample assembler code:


                extrn dsaft :abs
                extrn adtn1 :word
                extrn hrfft :abs
                extrn oldgs :byte


no_pick:
                mov dx,dsaft
                mov bx,adtn1
                call far ptr tstbt
                jnz htst_irf_ret
                mov bx,adtn1
                mov dx,hrfft
                call far ptr tstbt
                jz htst_irf
                mov oldgs,0
                call far ptr hwal
                jnz htst_irf_ret
                jmp htst_irf
htst_irf_ret:
                ret




and the corresponding C code:




void
no_pick()
{
  if ((adtn1->dsaft == 0 && adtn1->hrfft == 0))
  {
                  htst_irf();
  }
  else if (adtn1->dsaft == 0)
  {
                  oldgs = 0;
                  hwal_zf = hwal();
                  if (hwal_zf != 0)
                  {
                                  htst_irf();
                  }
  }
  return;
}


--
Martin
Martin.Ward@durham.ac.uk http://www.cse.dmu.ac.uk/~mward/ Erdos number: 4
[I'd think that translating assembler into C should be a lot easier
than decompiling object code because you have the symbols and
labels. -John]


Post a followup to this message

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