[mod.compilers] P-code translation

johnl@ima.UUCP (Compilers mailing list) (07/14/86)

I want to translate stack-based pseudo-code into real code for
a register based machine.  For example, I would want to translate the 
pseudo-code:

	dupl
	add	

into the register code:

	r0 = r0 + r0;

assuming that the top-of-stack is in r0.
E.g.  Does anyone know of references on this subject?

Arch D. Robison					robison@uiucdcs
University of Illinois at Urbana-Champaign

[This is a classic problem, since reverse polish is a particularly easy
intermediate form to get from simple-minded parsing schemes.  You
translate it to register code essentially by treating the registers as a
stack.  You'd probably want to make some arrangement to spill to memory if
you run out of registers, and to optimize the output a little.  See Aho and
Ullman.  Other references are welcome.  -John]
-- 
Send compilers mail to ima!compilers or, in a pinch to Levine@YALE.EDU
Plausible paths are { ihnp4 | decvax | cbosgd | harvard | yale | bbncca}!ima

Please send responses to the originator of the message -- I cannot forward
mail accidentally sent back to compilers.  Meta-mail to ima!compilers-request

johnl@ima.UUCP (Compilers mailing list) (07/16/86)

A better way is to implement a virtual stack in the CG. Keep track of
where the stack element came from, delay generating code for stack
instructions so that you can generate the most sophisticated memory to
register/memory instructions possible.

I'm no expert on this, but that is what I have seen done in several RPN
CGs. Try looking at the original papers on P4 as well as the BCPL book
by Martin Richards.

	Ken
-- 
Send compilers mail to ima!compilers or, in a pinch to Levine@YALE.EDU
Plausible paths are { ihnp4 | decvax | cbosgd | harvard | yale | bbncca}!ima

Please send responses to the originator of the message -- I cannot forward
mail accidentally sent back to compilers.  Meta-mail to ima!compilers-request