|HLL expression -> ASM email@example.com (Alexei A. Frounze) (2001-03-26)|
|Re: HLL expression -> ASM firstname.lastname@example.org (Dan Bishop) (2001-03-27)|
|Re: HLL expression -> ASM email@example.com (Alexei A. Frounze) (2001-03-31)|
|Re: HLL expression -> ASM firstname.lastname@example.org (Ben L. Titzer) (2001-03-31)|
|Re: HLL expression -> ASM email@example.com (Randall Hyde) (2001-03-31)|
|Re: HLL expression -> ASM firstname.lastname@example.org (Marco van de Voort) (2001-04-04)|
|Re: HLL expression -> ASM email@example.com (Alexei A. Frounze) (2001-04-10)|
|[2 later articles]|
|From:||"Alexei A. Frounze" <firstname.lastname@example.org>|
|Date:||26 Mar 2001 13:55:46 -0500|
|Organization:||Global Crossing Telecommunications|
|Posted-Date:||26 Mar 2001 13:55:46 EST|
I've got a question...
I know how to parse the source, how to evaluate expressions several
similar ways: recursively or using stack(s). OK, that works perfectly,
no problems. And I can create a tree for the expression as well.
Now, how do I transform the tree/whatever (let's say only integer
values/vars involved in the expression) into an ASM piece of code w/o
consuming extra memory for partial results, just using CPU registers?
Is there any basic idea/algorithm which I'm missing? It must be
simple, I guess...
Alexei A. Frounze
alexfru [AT] chat [DOT] ru
[A simple approach is to walk the tree depth first, passing up the
register at each stage that has the result, and tracking which
registers are available. If you have three or four free registers,
this works in a remarkably large number of cases. Beyond that you
have to preprocess the tree to look for subtrees that won't fit in the
available registers and either reorganize or spill results to memory.
Most compiler texts should cover this. -John]
Return to the
Search the comp.compilers archives again.