Optimizing in my toy compiler

Nils M Holm <nmh@t3x.org>
Mon, 11 Feb 2008 06:48:52 +0100

          From comp.compilers

Related articles
Optimizing in my toy compiler boriel@gmail.com (Boriel) (2008-02-07)
Optimizing in my toy compiler nmh@t3x.org (Nils M Holm) (2008-02-11)
Re: Optimizing in my toy compiler max@gustavus.edu (Max Hailperin) (2008-02-12)
| List of all articles for this month |

From: Nils M Holm <nmh@t3x.org>
Newsgroups: comp.compilers
Date: Mon, 11 Feb 2008 06:48:52 +0100
Organization: Compilers Central
References: 08-02-029
Keywords: optimize
Posted-Date: 12 Feb 2008 20:03:29 EST

Boriel <boriel@gmail.com> wrote:
> If I'm not wrong, stack-oriented code is easy to generate, but
> difficult to optimize whilst three or quad code is much easy to
> optimize. Any ideas? Which one should you suggest? I'm with "The
> Dragon book", and it have *too* much information. :-P

You can always optimize your code while it is in tree form an then
emit RPN. Or, in case your compiler does not build a syntax tree
while parsing, you can build one from the RPN code just for the
purpose of optimization.

This is what I have done in the T3X compiler[1]. Early versions did
not have an optimizer nor did they create syntax trees. The optimizer
in later versions was a separate program that read an intermediate
code file in RPN, built a tree from it, optimized that tree and
emitted optimized RPN. Converting RPN to a tree is not really hard.

Feel free to download the sources for inspiration:

[1] http://www.t3x.org/t3x/

Nils M Holm <nmh@t3x.org> -- http://t3x.org/nmh/

Post a followup to this message

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