Re: C code refactoring or optimizing ?

"Ira Baxter" <>
29 Mar 2007 23:09:08 -0400

          From comp.compilers

Related articles
C code refactoring or optimizing ? (Dennis Yurichev) (2007-03-29)
Re: C code refactoring or optimizing ? (Ira Baxter) (2007-03-29)
Re: C code refactoring or optimizing ? (Michael Beck) (2007-03-30)
Re: C code refactoring or optimizing ? (Jeff Kenton) (2007-04-01)
| List of all articles for this month |

From: "Ira Baxter" <>
Newsgroups: comp.compilers
Date: 29 Mar 2007 23:09:08 -0400
Organization: NewsGuy - Unlimited Usenet $19.95
References: 07-03-102
Keywords: C, optimize
Posted-Date: 29 Mar 2007 23:09:08 EDT

"Dennis Yurichev" <> wrote
> How can I find some ready tool or how can I find a proper way to
> develop a tool which will convert such code:
> if (a>b+2+2)
> {
> f1();
> f2(a*3*2);
> } else
> {
> f1();
> f3(a);
> }
> To something like that:
> f1();
> if (a>b+4)
> f2(a*6)
> else
> f3(a);
> In another words, this is what is done by modern compiler at
> optimization phase, right? (that's why I post here) But I need to have
> C-source at the input and C-source at the output. Could please anyone
> point me to any ideas or ready works.

The DMS Software Reengineering Tookit has the machinery to support
this, including a robust C front with preprocessor, parser to ASTs,
symbol table construction, control and dataflow analysis. You can
specify tree to tree transformations either procedurally or with
source-to-source transformations, conditioned by the circumstances
(e.g, analyses) that make the transform legal. After transformation,
you can regenerate legal C source code, including the comments.

You should understand that setting this up isn't an afternoon's task.
DMS is a big tool, necessitated by the complexity of real languages
such as GCC and MS Visual Studio dialects of C. But if you have scale
or need to do this a lot, DMS is a big win.

DMS has been used to carry out these kinds of tasks
on very large C source code bases.


Ira Baxter, CTO

Post a followup to this message

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